/* ---------- Design tokens ---------- */
:root {
  --brand: #4f46e5;
  --brand-fg: #ffffff;
  --brand-soft: color-mix(in srgb, var(--brand) 12%, transparent);
  --brand-ring: color-mix(in srgb, var(--brand) 40%, transparent);

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f2f5;
  --text: #1a1d23;
  --text-muted: #5b6470;
  --border: #e3e6eb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --warning: #d97706;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 10px 30px -10px rgba(15, 23, 42, 0.25);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --text: #e8eaed;
    --text-muted: #9aa3b2;
    --border: #2a2f3a;
    --danger: #f87171;
    --danger-soft: #2a1414;
    --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14.5px;
  line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
img { max-width: 100%; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550;
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, transform .04s, box-shadow .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-fg); }
.btn-primary:hover { background: color-mix(in srgb, var(--brand) 88%, black); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.94); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 550; font-size: 13px; color: var(--text-muted); }
.field .hint { font-size: 12px; color: var(--text-muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px; width: 100%;
}
textarea { resize: vertical; min-height: 72px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring);
}
input[type="color"] { padding: 4px; height: 40px; cursor: pointer; }
input[type="file"] { padding: 7px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

/* ---------- Layout ---------- */
.app-shell { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px; gap: 6px; position: sticky; top: 0; height: 100vh;
}
.brand-block { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 9px; object-fit: cover; background: var(--brand-soft);
  display: grid; place-items: center; flex: none;
}
.brand-logo.placeholder { color: var(--brand); font-weight: 800; }
.brand-name { font-weight: 680; font-size: 15px; line-height: 1.15; }
.brand-name small { display: block; font-weight: 500; color: var(--text-muted); font-size: 11.5px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 550; cursor: pointer;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--brand-soft); color: var(--brand); }
.nav-link .ico { width: 18px; height: 18px; flex: none; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 6px 8px; font-size: 13px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: var(--brand-fg);
  display: grid; place-items: center; font-weight: 650; font-size: 12px; flex: none;
}
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; border-bottom: 1px solid var(--border); background: var(--surface);
  display: flex; align-items: center; justify-content: space-between; padding: 0 26px; position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 17px; }
.content { padding: 26px; max-width: 1140px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--text-muted); }

/* ---------- Cards / tables ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

.stat { padding: 18px 20px; }
.stat .n { font-size: 26px; font-weight: 720; letter-spacing: -0.02em; }
.stat .l { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table.table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 14px; }
.table th, .table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover, .table tr:hover td { background: var(--surface-2); }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-muted);
}
.badge.green { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.badge.red { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }

.resource-card { overflow: hidden; display: flex; flex-direction: column; }
.resource-card .thumb {
  aspect-ratio: 16 / 9; background: var(--surface-2) center/cover no-repeat; display: grid; place-items: center;
  color: var(--text-muted);
}
.resource-card .body { padding: 15px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.resource-card .body h3 { font-size: 15.5px; }
.resource-card .body .desc { color: var(--text-muted); font-size: 13px; flex: 1; }
.resource-card .foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }

.empty { text-align: center; padding: 54px 20px; color: var(--text-muted); }
.empty svg { opacity: .5; margin-bottom: 10px; }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 50% -10%, var(--brand-soft), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 390px; }
.auth-card .logo-lg { width: 46px; height: 46px; border-radius: 12px; background: var(--brand); color: var(--brand-fg); display: grid; place-items: center; font-weight: 800; margin-bottom: 16px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 12, 18, 0.5); backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 20px; z-index: 50; animation: fade .12s ease;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; animation: pop .14s ease;
}
.modal.lg { max-width: 620px; }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; }
.modal-foot { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- Toast ---------- */
#toast-stack { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--brand);
  box-shadow: var(--shadow-lg); border-radius: var(--radius-sm); padding: 12px 15px; max-width: 340px;
  font-size: 13.5px; animation: pop .14s ease;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

/* ---------- Misc ---------- */
.spinner {
  width: 22px; height: 22px; border: 3px solid var(--brand-soft); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .7s linear infinite;
}
.center-fill { min-height: 100vh; display: grid; place-items: center; }
@keyframes spin { to { transform: rotate(360deg); } }
.muted { color: var(--text-muted); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tenant-note {
  font-size: 12.5px; color: var(--text-muted); background: var(--brand-soft); border-radius: var(--radius-sm);
  padding: 8px 12px; display: inline-flex; gap: 8px; align-items: center;
}
.org-switch-wrap {
  display: flex; align-items: center; gap: 7px; margin: 2px 6px 10px;
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-muted); background: var(--surface-2);
}
.org-switch {
  flex: 1; border: 0; background: transparent; padding: 0; font: inherit; font-weight: 600;
  color: var(--text); cursor: pointer;
}
.org-switch:focus { outline: none; box-shadow: none; }
.org-choice {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  cursor: pointer; border: 1px solid var(--border); transition: border-color .12s, background .12s;
}
.org-choice:hover { border-color: var(--brand); background: var(--brand-soft); }
.slot-list { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; max-height: 190px; overflow-y: auto; }
.slot { display: flex; justify-content: space-between; padding: 8px 10px; background: var(--surface-2); border-radius: var(--radius-sm); font-size: 13px; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 244px; z-index: 40; transform: translateX(-100%);
    transition: transform .18s ease;
  }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; }
  .menu-btn { display: inline-flex; }
}
.menu-btn { display: none; }
