/* ── Theme tokens ──────────────────────────────────────────────────── */
:root {
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  --sidebar-w: 216px;
  --header-h: 46px;

  --transition: 140ms ease;
}

/* ── Density ───────────────────────────────────────────────────────── */
[data-density="comfortable"] {
  --sp-1: 4px; --sp-2: 10px; --sp-3: 14px; --sp-4: 18px;
  --sp-5: 24px; --sp-6: 28px; --sp-8: 36px;
  --td-pad: 9px 14px;
  --th-pad: 8px 14px;
  --card-pad: 18px;
  font-size: 13.5px;
}
[data-density="default"] {
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;
  --td-pad: 6px 12px;
  --th-pad: 6px 12px;
  --card-pad: 16px;
  font-size: 13px;
}
[data-density="compact"] {
  --sp-1: 2px; --sp-2: 6px; --sp-3: 8px; --sp-4: 12px;
  --sp-5: 16px; --sp-6: 18px; --sp-8: 24px;
  --td-pad: 3px 10px;
  --th-pad: 4px 10px;
  --card-pad: 12px;
  font-size: 12px;
}

/* ── Light theme ───────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:        #f4f3f8;
  --surface:   #ffffff;
  --surface-2: #f0eef8;
  --border:    #e2dff0;
  --border-2:  #ccc8e0;

  --text:      #18161f;
  --text-2:    #5a5570;
  --text-3:    #9590aa;
  --text-inv:  #ffffff;

  --accent:    #7c3aed;
  --accent-h:  #6d28d9;
  --accent-bg: #f5f3ff;

  --danger:    #dc2626;
  --danger-h:  #b91c1c;
  --danger-bg: #fef2f2;

  --success:   #16a34a;
  --success-bg:#f0fdf4;

  --warn:      #d97706;
  --warn-bg:   #fffbeb;

  --sidebar-bg:    #1a1535;
  --sidebar-text:  #b0a8cc;
  --sidebar-hover: #251e45;
  --sidebar-active:#c4b5fd;
  --sidebar-active-bg: rgba(167,139,250,.18);
}

/* ── Dark theme ────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:        #0e0c15;
  --surface:   #17152a;
  --surface-2: #1f1c35;
  --border:    #2a2545;
  --border-2:  #3a3558;

  --text:      #e8e4f8;
  --text-2:    #9089b8;
  --text-3:    #5c5580;
  --text-inv:  #0e0c15;

  --accent:    #a78bfa;
  --accent-h:  #c4b5fd;
  --accent-bg: #2e1065;

  --danger:    #f87171;
  --danger-h:  #fca5a5;
  --danger-bg: #2d1515;

  --success:   #4ade80;
  --success-bg:#142414;

  --warn:      #fbbf24;
  --warn-bg:   #2a1e08;

  --sidebar-bg:    #110e20;
  --sidebar-text:  #8880aa;
  --sidebar-hover: #1c1832;
  --sidebar-active:#c4b5fd;
  --sidebar-active-bg: rgba(167,139,250,.15);
}

/* ── Reset & base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 13px; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ── Layout ────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar — collapsed by default, opens via .sidebar-open */
.sidebar {
  width: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 180ms ease;
}
.sidebar.sidebar-open {
  width: var(--sidebar-w);
  overflow-y: auto;
}

.sidebar-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-4);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  flex-shrink: 0;
}

.sidebar-logo {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.3px;
}
.sidebar-logo span { color: var(--sidebar-active); }

.sidebar-nav { flex: 1; padding: var(--sp-3) 0; }

.sidebar-section {
  padding: var(--sp-3) var(--sp-4) var(--sp-1);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-3);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px var(--sp-4);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 12.5px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.sidebar-link:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active); font-weight: 500; }
.sidebar-link svg { flex-shrink: 0; opacity: .7; }
.sidebar-link.active svg { opacity: 1; }

/* Main content */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-3) 0 var(--sp-2);
  flex-shrink: 0;
  gap: var(--sp-2);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  flex: 1;
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  color: var(--text-2);
  min-width: 0;
}
.topbar-breadcrumb .crumb-active { color: var(--text); font-weight: 500; }
.topbar-breadcrumb .sep { color: var(--text-3); font-size: 11px; padding: 0 1px; }
.crumb-link {
  background: none; border: none; cursor: pointer; padding: 2px 4px; border-radius: 3px;
  color: var(--accent); font-size: 12.5px; font-family: inherit;
  transition: background var(--transition);
}
.crumb-link:hover { background: var(--accent-bg); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}

/* ── User avatar button ─────────────────────────────────────────────── */
.user-avatar-btn {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  flex-shrink: 0;
  transition: opacity var(--transition), box-shadow var(--transition);
}
.user-avatar-btn:hover { opacity: .85; box-shadow: 0 0 0 3px var(--accent-bg); }

/* ── User dropdown ──────────────────────────────────────────────────── */
.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 28px rgba(0,0,0,.18);
  min-width: 210px;
  z-index: 500;
}
.user-dropdown-header {
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.user-dropdown-name  { font-weight: 600; font-size: 13px; color: var(--text); }
.user-dropdown-email { font-size: 11.5px; color: var(--text-2); margin-top: 1px; }
.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  font-size: 12.5px;
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  transition: background var(--transition);
}
.user-dropdown-item:hover { background: var(--surface-2); }

.content { flex: 1; overflow-y: auto; padding: var(--sp-5); }

/* ── Page header ───────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
  gap: var(--sp-3);
}
.page-title { font-size: 17px; font-weight: 600; }
.page-subtitle { font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* ── Card ──────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--card-pad);
  border-bottom: 1px solid var(--border);
  gap: var(--sp-3);
}
.card-title { font-size: 12.5px; font-weight: 600; }
.card-body { padding: var(--card-pad); }

/* ── Active license highlight ──────────────────────────────────────── */
.license-active-card {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.license-active-header {
  background: var(--accent-bg);
  border-bottom: 1px solid var(--accent);
  padding: var(--sp-2) var(--card-pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.license-active-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* ── Table ─────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  padding: var(--th-pad);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
td { padding: var(--td-pad); vertical-align: middle; color: var(--text); }
.td-mono { font-family: var(--font-mono); font-size: 11.5px; }
.td-dim { color: var(--text-2); }
.td-actions { text-align: right; white-space: nowrap; }

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px var(--sp-3);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), opacity var(--transition);
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-h); border-color: var(--accent-h); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border-2); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); }
.btn-ghost { background: transparent; color: var(--text-2); border-color: transparent; padding: 4px var(--sp-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 3px var(--sp-2); font-size: 11.5px; }
.btn-lg { padding: 7px var(--sp-4); font-size: 13.5px; }

/* ── Icon button ───────────────────────────────────────────────────── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  font-size: 13px;
  line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ── Form ──────────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3) var(--sp-4); }
.form-group { display: flex; flex-direction: column; gap: var(--sp-1); }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 11.5px; font-weight: 500; color: var(--text-2); }
input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 12.5px;
  padding: 5px var(--sp-2);
  outline: none;
  width: 100%;
  transition: border-color var(--transition);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}
input[type="checkbox"] { width: auto; accent-color: var(--accent); cursor: pointer; }
textarea { min-height: 70px; resize: vertical; font-family: var(--font-mono); font-size: 11.5px; }
.form-hint { font-size: 11px; color: var(--text-3); }
.form-row { display: flex; align-items: center; gap: var(--sp-2); }
.form-actions { display: flex; gap: var(--sp-2); justify-content: flex-end; padding-top: var(--sp-3); margin-top: var(--sp-3); border-top: 1px solid var(--border); }

/* ── Badge ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.4;
}
.badge-active   { background: var(--success-bg); color: var(--success); }
.badge-inactive { background: var(--surface-2);  color: var(--text-3);  }
.badge-revoked  { background: var(--danger-bg);  color: var(--danger);  }
.badge-canceled { background: var(--surface-2);  color: var(--text-3);  }
.badge-superseded{ background: var(--surface-2); color: var(--text-3);  }
.badge-expired  { background: var(--warn-bg);    color: var(--warn);    }
.badge-decommission,
.badge-decommissioned { background: var(--danger-bg); color: var(--danger); }
.badge-trial    { background: var(--warn-bg);    color: var(--warn);    }
.badge-admin    { background: var(--accent-bg);  color: var(--accent);  }

/* ── Modal ─────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--sp-4);
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.modal-lg { max-width: 700px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--card-pad);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title { font-size: 13.5px; font-weight: 600; }
.modal-body { padding: var(--card-pad); flex: 1; overflow-y: auto; }
.modal-footer {
  padding: var(--sp-3) var(--card-pad);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  flex-shrink: 0;
}

/* ── Detail grid ───────────────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--sp-3) var(--sp-4); }
.detail-item { display: flex; flex-direction: column; gap: 2px; }
.detail-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.detail-value { font-size: 12.5px; color: var(--text); word-break: break-all; }
.detail-value.mono { font-family: var(--font-mono); font-size: 11.5px; }

/* ── Token display ─────────────────────────────────────────────────── */
.token-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--sp-3);
  font-family: var(--font-mono);
  font-size: 10.5px;
  word-break: break-all;
  color: var(--text-2);
}

/* ── Danger icon button ─────────────────────────────────────────────── */
.btn-icon-danger { color: var(--danger) !important; opacity: .75; }
.btn-icon-danger:hover { opacity: 1; background: var(--danger-bg) !important; }

/* ── Remove/close buttons in rows ──────────────────────────────────── */
.remove-btn { color: var(--text-3) !important; padding: 3px 5px !important; }
.remove-btn:hover { color: var(--danger) !important; background: var(--danger-bg) !important; }

/* ── Entitlement column header ──────────────────────────────────────── */
.entitlement-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-3);
  padding-bottom: 4px;
}

/* ── Form sections (issue modal) ───────────────────────────────────── */
.form-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  margin-bottom: 10px;
}
.form-section-sublabel {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}
.entitlement-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.kv-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

/* ── Alert ─────────────────────────────────────────────────────────── */
.alert {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border-radius: var(--radius-md);
  font-size: 12.5px;
  border: 1px solid;
}
.alert-error   { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.alert-success { background: var(--success-bg); border-color: var(--success); color: var(--success); }

/* ── Login page ────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: var(--sp-4);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 340px;
}
.login-logo {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: var(--sp-6);
  letter-spacing: -.3px;
}
.login-logo span { color: var(--accent); }
.login-form { display: flex; flex-direction: column; gap: var(--sp-3); }

/* ── Empty state ───────────────────────────────────────────────────── */
.empty { text-align: center; padding: 40px var(--sp-4); color: var(--text-3); }
.empty-text { font-size: 12.5px; margin-bottom: var(--sp-3); }

/* ── Utility ───────────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-dim { color: var(--text-2); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-accent { color: var(--accent); }
.mono { font-family: var(--font-mono); }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { border: none; border-top: 1px solid var(--border); margin: var(--sp-4) 0; }
.w-full { width: 100%; }

/* ── Spinner ───────────────────────────────────────────────────────── */
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { text-align: center; padding: 32px; color: var(--text-3); font-size: 12px; }

/* ── Density label ─────────────────────────────────────────────────── */
.density-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-3);
  line-height: 1;
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .form-grid { grid-template-columns: 1fr; }
}
