:root {
  --sidebar-width: 260px;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #eef2ff;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --sidebar-from: #1e1b4b;
  --sidebar-to: #312e81;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

body.app-guest { background: linear-gradient(135deg, #1e1b4b 0%, #4338ca 50%, #6366f1 100%); }

.admin-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--sidebar-from) 0%, var(--sidebar-to) 100%);
  color: #e0e7ff;
  padding: 1.25rem 1rem;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  box-shadow: 4px 0 24px rgba(0,0,0,.15);
}

.sidebar-brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff !important;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .25rem;
}

.sidebar-sub { font-size: .72rem; color: #a5b4fc; margin-bottom: 1.25rem; padding-left: .25rem; }

.sidebar-nav { list-style: none; padding: 0; margin: 0; flex: 1; }
.sidebar-nav li { margin-bottom: .2rem; }
.sidebar-nav a {
  display: flex; align-items: center; gap: .65rem;
  padding: .7rem .9rem;
  border-radius: 10px;
  color: #c7d2fe !important;
  text-decoration: none;
  font-size: .9rem;
  font-weight: 500;
  transition: all .15s ease;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.1); color: #fff !important; transform: translateX(2px); }
.sidebar-nav a.active { background: rgba(255,255,255,.18); color: #fff !important; box-shadow: inset 3px 0 0 #fff; }
.sidebar-nav .sidebar-section {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #818cf8;
  padding: .85rem .9rem .35rem;
  font-weight: 700;
}

.sidebar-footer { margin-top: auto; padding-top: 1rem; border-top: 1px solid rgba(255,255,255,.12); }
.user-chip { font-size: .8rem; color: #c7d2fe; display: flex; align-items: center; gap: .4rem; }

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 1.75rem 2rem;
  width: calc(100% - var(--sidebar-width));
  min-height: 100vh;
}

.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.65rem; font-weight: 700; margin: 0 0 .4rem; letter-spacing: -.02em; }
.page-header p { color: var(--muted); margin: 0; font-size: .92rem; max-width: 640px; }

.card-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.35rem;
  margin-bottom: 1.25rem;
}

.wizard-steps {
  display: flex;
  gap: .5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.wizard-step {
  flex: 1;
  min-width: 140px;
  padding: .85rem 1rem;
  border-radius: 10px;
  background: #fff;
  border: 2px solid var(--border);
  text-align: center;
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
  transition: all .2s;
}
.wizard-step.active { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.wizard-step.done { border-color: var(--success); color: #047857; background: #ecfdf5; }
.wizard-step i { display: block; font-size: 1.25rem; margin-bottom: .35rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
  box-shadow: var(--shadow);
}
.stat-card .label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.stat-card .value { font-size: 1.65rem; font-weight: 700; margin-top: .2rem; }

.badge-status {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .25rem .65rem; border-radius: 999px; font-size: .72rem; font-weight: 600;
}
.badge-ok { background: #d1fae5; color: #065f46; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-cf { background: #fef3c7; color: #92400e; }
.badge-warn { background: #fef3c7; color: #92400e; }
.audit-json { white-space: pre-wrap; word-break: break-word; max-height: 200px; overflow: auto; }

.integration-pills { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.integration-pill {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .4rem .85rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: #fff;
}

.domain-search-box { display: flex; gap: .75rem; }
.domain-search-box input {
  flex: 1;
  font-size: 1.05rem;
  padding: .8rem 1rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  transition: border-color .15s, box-shadow .15s;
}
.domain-search-box input:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, .15);
}

.domain-cart-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}
.domain-cart-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .35rem .55rem .35rem .75rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
  background: #ede9fe;
  color: #5b21b6;
  border: 1px solid #ddd6fe;
}
.domain-cart-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(91, 33, 182, .12);
  color: #5b21b6;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.domain-cart-remove:hover { background: rgba(91, 33, 182, .22); }

.balance-bar {
  display: flex; gap: 2rem; flex-wrap: wrap; align-items: center;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, #eef2ff, #e0e7ff);
  border-radius: 10px;
  margin: 1rem 0;
  border: 1px solid #c7d2fe;
}
.balance-bar strong { color: var(--primary-dark); font-size: 1.1rem; }

.results-table { width: 100%; border-collapse: collapse; }
.results-table th {
  padding: .75rem 1rem;
  text-align: left;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  background: #f8fafc;
}
.results-table td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
.results-table tr.available { background: #f0fdf4; }
.results-table tr.available:hover { background: #dcfce7; }
.results-table tr.owned { background: #eff6ff; }
.results-table tr.owned:hover { background: #dbeafe; }
.results-table tr.in-cf { background: #fffbeb; }
.results-table tr.in-cf:hover { background: #fef3c7; }
.results-table tr.unavailable { opacity: .5; }

.domain-results-scroll {
    max-height: 420px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: .5rem;
}
.load-more-row {
    text-align: center;
    padding: .75rem;
    color: var(--text-muted);
    font-size: .875rem;
}

.btn-primary-custom {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border: none; color: #fff !important;
  padding: .7rem 1.35rem; border-radius: 10px; font-weight: 600;
  box-shadow: 0 4px 14px rgba(99, 102, 241, .35);
  transition: transform .15s, box-shadow .15s;
}
.btn-primary-custom:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, .45);
  color: #fff !important;
}
.btn-primary-custom:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.login-card {
  width: 100%; max-width: 420px;
  background: #fff; border-radius: 16px;
  padding: 2.25rem;
  box-shadow: 0 25px 60px rgba(0,0,0,.25);
}

.integration-card { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem; overflow: hidden; background: #fff; box-shadow: var(--shadow); }
.integration-card-header {
  padding: 1rem 1.25rem;
  background: linear-gradient(180deg, #f8fafc, #fff);
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.integration-card-header h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.integration-card-body { padding: 1.25rem; }
.integration-hint { font-size: .85rem; color: var(--muted); margin-bottom: 1rem; line-height: 1.55; }

.permission-group { margin-bottom: 1.25rem; }
.permission-group-title {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: .5rem;
  padding-bottom: .35rem;
  border-bottom: 1px solid var(--border);
}
.permission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: .5rem;
}
.permission-item {
  display: flex;
  gap: .6rem;
  align-items: flex-start;
  padding: .65rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafbfc;
  cursor: pointer;
  margin: 0;
  font-size: .85rem;
}
.permission-item input { margin-top: .2rem; flex-shrink: 0; }
.permission-item:hover { border-color: #c7d2fe; background: #f5f7ff; }

.role-columns { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.role-col-title { font-size: .7rem; font-weight: 700; text-transform: uppercase; color: var(--muted); margin-bottom: .35rem; }
.role-drop-zone {
  min-height: 180px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: .5rem;
  background: #fafbfc;
}
.role-drop-zone-active { border-color: #a5b4fc; background: #f5f7ff; }
.role-chip {
  padding: .45rem .65rem;
  margin-bottom: .35rem;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
  font-size: .85rem;
  font-weight: 600;
  cursor: grab;
}
.role-chip-ghost { opacity: .5; background: #e0e7ff; }
.permission-scroll { max-height: 420px; overflow-y: auto; padding-right: .25rem; }
.role-perm-summary {
  border-top: 1px solid var(--border);
  padding-top: .75rem;
}
.role-perm-matrix { max-height: 220px; }
.role-perm-role-line { font-size: .8rem; margin-bottom: .2rem; }
.role-perm-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.role-perm-chip {
  font-size: .72rem;
  font-weight: 600;
  padding: .2rem .45rem;
  border-radius: 999px;
  background: #e0e7ff;
  color: #3730a3;
}
.role-perm-chip-more { background: #f1f5f9; color: var(--muted); }
.permission-item.perm-from-role { border-color: #c7d2fe; background: #f8faff; }
.permission-item.perm-excluded { opacity: .65; background: #fff7ed; border-color: #fdba74; }

.summary-box {
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
}

@media (max-width: 768px) {
  .sidebar { position: relative; width: 100%; }
  .main-content { margin-left: 0; width: 100%; padding: 1rem; }
  .admin-shell { flex-direction: column; }
}
