:root {
  --brand-900: #0f172a;
  --brand-800: #1e3a5f;
  --brand-700: #1d4ed8;
  --brand-600: #2563eb;
  --brand-500: #3b82f6;
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --header-h: 64px;
  --sidebar-w: 260px;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--slate-100);
  color: var(--slate-800);
}
body.sidebar-drawer-open { overflow: hidden; }

.loading-msg { text-align: center; padding: 2rem; color: var(--slate-500); }

.demo-banner {
  background: #f59e0b;
  color: #78350f;
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  font-weight: 600;
  flex-shrink: 0;
}

.app-root { display: flex; flex-direction: column; min-height: 100vh; }
.app-shell {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ——— Sidebar ——— */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--brand-900) 0%, var(--brand-800) 100%);
  color: #fff;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  z-index: 200;
}
.sidebar-head {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  color: var(--brand-500);
  flex-shrink: 0;
}
.sidebar-logo svg { width: 1.5rem; height: 1.5rem; }
.sidebar-head h1 { margin: 0; font-size: 1rem; font-weight: 700; line-height: 1.3; }
.sidebar-head p { margin: 0.2rem 0 0; font-size: 0.7rem; opacity: 0.65; color: #93c5fd; }

.sidebar nav { flex: 1; padding: 0.75rem 0.625rem; overflow-y: auto; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  border-radius: 0.5rem;
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-size: 0.875rem;
  margin-bottom: 2px;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link.active {
  background: var(--brand-600);
  color: #fff;
  font-weight: 600;
}
.nav-icon { display: flex; width: 1.125rem; height: 1.125rem; flex-shrink: 0; opacity: 0.85; }
.nav-icon svg { width: 100%; height: 100%; }
.nav-label { flex: 1; }

.sidebar-foot {
  padding: 0.75rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-user-card {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.5rem;
  border: none;
  border-radius: 0.5rem;
  background: rgba(255,255,255,0.06);
  color: #fff;
  cursor: pointer;
  text-align: left;
  font: inherit;
}
.sidebar-user-text { flex: 1; min-width: 0; }
.sidebar-user-text strong { display: block; font-size: 0.8125rem; }
.sidebar-user-text span { display: block; font-size: 0.7rem; opacity: 0.65; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-chevron { opacity: 0.5; }
.sidebar-user-chevron svg { width: 1rem; height: 1rem; }

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: var(--brand-600);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}
.user-avatar.sm { width: 2rem; height: 2rem; font-size: 0.6875rem; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.5);
  z-index: 150;
}

/* ——— Main + Header ——— */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--slate-100);
  overflow: hidden;
}

.app-header {
  flex-shrink: 0;
  background: #fff;
  border-bottom: 1px solid var(--slate-200);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header-top {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  height: var(--header-h);
  min-height: var(--header-h);
}

.header-left { display: flex; align-items: center; flex-shrink: 0; }
#sidebar-toggle { display: none; }

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
  max-width: 36rem;
  margin: 0 auto;
}

.header-search-wrap {
  display: flex;
  align-items: center;
  width: 100%;
  background: var(--slate-100);
  border: 1px solid var(--slate-200);
  border-radius: 999px;
  padding: 0 0.875rem;
  height: 2.5rem;
  gap: 0.5rem;
}
.search-icon {
  display: flex;
  color: var(--slate-400);
  flex-shrink: 0;
}
.header-search {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0;
  font-size: 0.875rem;
  outline: none;
  min-width: 0;
}
.header-search::placeholder { color: var(--slate-400); }
.header-kbd {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  font-size: 0.6875rem;
  font-family: inherit;
  color: var(--slate-500);
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: 0.375rem;
  flex-shrink: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
  margin-left: auto;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--slate-600);
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--slate-100); }

.header-notify .notify-badge {
  position: absolute;
  top: 0.375rem;
  right: 0.375rem;
  min-width: 1.125rem;
  height: 1.125rem;
  padding: 0 0.25rem;
  font-size: 0.625rem;
  font-weight: 700;
  line-height: 1.125rem;
  text-align: center;
  background: #ef4444;
  color: #fff;
  border-radius: 999px;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem 0.25rem 0.25rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: var(--slate-800);
  transition: background 0.15s;
}
.header-user:hover { background: var(--slate-100); }
.user-meta { display: flex; align-items: center; gap: 0.25rem; }
.user-name { font-size: 0.875rem; font-weight: 600; white-space: nowrap; }
.user-chevron { display: flex; color: var(--slate-400); }

/* Page chrome (title row below top bar) */
.page-chrome {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem 1rem;
  flex-wrap: wrap;
  background: #fff;
  border-bottom: 1px solid var(--slate-200);
}
.page-chrome-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--slate-900);
  letter-spacing: -0.02em;
}
.page-chrome-subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.875rem;
  color: var(--slate-500);
  max-width: 36rem;
}
.page-chrome-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}
.date-range-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius);
  background: #fff;
  font-size: 0.8125rem;
  color: var(--slate-700);
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.date-range-btn:hover { background: var(--slate-50); }
.date-icon, .date-chevron { display: flex; color: var(--slate-500); }

.header-quick-action {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  white-space: nowrap;
}
.header-quick-action .qa-chevron,
.qa-chevron { display: inline-flex; align-items: center; }

.main-inner {
  flex: 1;
  overflow: auto;
  padding: 1.5rem;
  max-width: none;
}

.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap; }
.page-header h2 { margin: 0; font-size: 1.5rem; color: var(--slate-800); }
.page-header p { margin: 0.25rem 0 0; font-size: 0.875rem; color: var(--slate-500); }

.card {
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.card-pad { padding: 1rem; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card .label { font-size: 0.875rem; color: var(--slate-500); }
.stat-card .value { font-size: 1.5rem; font-weight: 700; margin-top: 0.25rem; color: var(--slate-900); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--slate-200);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  gap: 0.35rem;
}
.btn-primary { background: var(--brand-600); color: #fff; }
.btn-primary:hover { background: var(--brand-700); }
.btn-green { background: #16a34a; color: #fff; }
.btn-dark { background: #334155; color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.header-quick-action:disabled { opacity: 0.6; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; background: #fff; border: 1px solid var(--slate-200); border-radius: var(--radius); }
th, td { padding: 0.625rem 0.875rem; text-align: left; border-top: 1px solid var(--slate-200); }
thead th { background: var(--slate-50); font-weight: 600; font-size: 0.8125rem; color: var(--slate-600); }
.text-right { text-align: right; }
.empty-row td { text-align: center; color: var(--slate-500); padding: 1.5rem; }

.notice {
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}
.notice-warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.notice-ok { color: #15803d; font-weight: 600; }

.toast {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  color: #fff;
  z-index: 9999;
  max-width: 320px;
  font-size: 0.875rem;
}
.toast-error { background: #dc2626; }
.toast-success { background: #16a34a; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }

/* Desktop: sidebar always visible, hide hamburger */
@media (min-width: 769px) {
  #sidebar-toggle { display: none !important; }
  .sidebar-backdrop { display: none !important; }
}

/* Mobile: drawer sidebar */
@media (max-width: 768px) {
  #sidebar-toggle { display: inline-flex !important; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
  }
  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }
  .app-shell.sidebar-open .sidebar-backdrop {
    display: block;
  }

  .header-center { max-width: none; }
  .header-kbd { display: none; }
  .user-name { display: none; }
  .user-chevron { display: none; }

  .page-chrome {
    flex-direction: column;
    align-items: stretch;
  }
  .page-chrome-right {
    flex-wrap: wrap;
  }
  .page-chrome-title { font-size: 1.375rem; }

  .grid-2 { grid-template-columns: 1fr; }
}
