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

/* ── Design Tokens ────────────────────────────────────────────────── */
:root {
  /* Surfaces */
  --bg-page:     #F5F6F8;
  --bg-card:     #FFFFFF;
  --bg-hover:    #F1F3F6;
  --bg-input:    #F5F6F8;

  /* Sidebar */
  --sidebar-bg:       #1C1F2E;
  --sidebar-hover:    rgba(255,255,255,0.06);
  --sidebar-active:   rgba(0,133,255,0.14);
  --sidebar-text:     #8B90A9;
  --sidebar-text-active: #FFFFFF;
  --sidebar-accent:   #0085FF;

  /* Borders */
  --border:       #E6E9EF;
  --border-hover: #C8CDD8;
  --border-focus: #0085FF;

  /* Text */
  --text-primary:   #1F2937;
  --text-secondary: #6B7280;
  --text-light:     #9CA3AF;

  /* Brand */
  --accent:      #0085FF;
  --accent-dim:  rgba(0,133,255,0.10);
  --accent-hover:#0070D8;

  /* Status / semantic */
  --green:       #00C875;
  --green-dim:   rgba(0,200,117,0.10);
  --green-text:  #007A4D;
  --yellow:      #E08D00;
  --yellow-bg:   rgba(253,171,61,0.10);
  --red:         #D93025;
  --red-dim:     rgba(217,48,37,0.10);
  --purple:      #7B61FF;
  --purple-dim:  rgba(123,97,255,0.10);

  /* Sizing */
  --sidebar-w:   220px;
  --topbar-h:    56px;
  --radius:      8px;
  --radius-lg:   12px;

  /* Fonts */
  --font-head: 'Syne', sans-serif;
  --font-body: 'Instrument Sans', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Shadows */
  --shadow-card:  0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-raised: 0 4px 12px rgba(0,0,0,0.10), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-modal:  0 20px 60px rgba(0,0,0,0.18), 0 8px 20px rgba(0,0,0,0.10);
}

/* ── Base ─────────────────────────────────────────────────────────── */
html { font-size: 14px; }

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

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

/* ── Sidebar ──────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 10;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 22px 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 6px;
}

.logo-mark {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}

.logo-name {
  display: block;
  font-family: var(--font-head);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #FFFFFF;
  line-height: 1.1;
}

.logo-tagline {
  display: block;
  font-size: 9.5px;
  font-family: var(--font-mono);
  color: var(--sidebar-text);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 2px;
}

/* ── Nav ──────────────────────────────────────────────────────────── */
#sidebar-nav {
  flex: 1;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  cursor: pointer;
  position: relative;
  user-select: none;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #FFFFFF;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: var(--sidebar-text-active);
}

.nav-item.active .nav-icon {
  color: var(--sidebar-accent);
}

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 20px;
}

.nav-label {
  font-family: var(--font-body);
  white-space: nowrap;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.version-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--sidebar-text);
  letter-spacing: 0.05em;
  opacity: 0.6;
}

/* ── Main Area ────────────────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-page);
}

#top-bar {
  height: var(--topbar-h);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 5;
}

#page-title {
  font-family: var(--font-head);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

#top-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#section-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#section-content::-webkit-scrollbar { width: 5px; }
#section-content::-webkit-scrollbar-track { background: transparent; }
#section-content::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }

/* ── Typography helpers ───────────────────────────────────────────── */
.text-muted    { color: var(--text-secondary); }
.text-light    { color: var(--text-light); }
.text-green    { color: var(--green-text, var(--green)); }
.text-blue     { color: var(--accent); }
.text-yellow   { color: var(--yellow); }
.text-alert    { color: var(--red); }
.text-mono     { font-family: var(--font-mono); }

.hidden { display: none !important; }

/* ── Login Page ───────────────────────────────────────────────────── */
#login-page {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-page);
}

.login-bg {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 70% 50% at 20% 80%, rgba(0,133,255,0.06) 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 80% 20%, rgba(0,133,255,0.04) 0%, transparent 50%);
  padding: 20px;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 44px;
  width: 420px;
  max-width: 100%;
  box-shadow: var(--shadow-raised);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-logo-mark {
  width: 44px;
  height: 44px;
  background: var(--accent);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  flex-shrink: 0;
}

.login-logo-name {
  font-family: var(--font-head);
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: 0.01em;
  line-height: 1;
}

.login-logo-sub {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-light);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 4px;
}

.login-heading h1 {
  font-family: var(--font-head);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}

.login-heading p {
  font-size: 14px;
  color: var(--text-secondary);
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-submit {
  width: 100%;
  padding: 10px;
  font-size: 14.5px;
  margin-top: 4px;
}

.remember-row {
  display: flex;
  align-items: center;
}
.remember-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}
.remember-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.login-error {
  background: var(--red-dim);
  border: 1px solid rgba(217,48,37,0.2);
  color: var(--red);
  border-radius: var(--radius);
  padding: 9px 13px;
  font-size: 13px;
  font-weight: 500;
}

.login-footer {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-light);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

/* Password toggle */
.pw-wrap {
  position: relative;
}
.pw-wrap .form-input {
  padding-right: 40px;
}
.pw-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  display: flex;
  align-items: center;
  padding: 2px;
  transition: color 0.12s;
}
.pw-toggle:hover { color: var(--text-secondary); }

/* ── Sidebar User Profile ─────────────────────────────────────────── */
#sidebar-user {
  padding: 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.sidebar-user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: default;
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-head);
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: 12.5px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 10px;
  color: var(--sidebar-text);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 1px;
}

.sidebar-logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}
.sidebar-logout-btn:hover {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.8);
}

/* ── Mobile hamburger button ──────────────────────────────────────── */
#mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}
#mobile-menu-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ── Sidebar backdrop ─────────────────────────────────────────────── */
#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 98;
  backdrop-filter: blur(1px);
}
#sidebar-backdrop.active { display: block; }

/* ── Mobile breakpoint ────────────────────────────────────────────── */
@media (max-width: 768px) {
  #mobile-menu-btn { display: flex; }

  /* Sidebar hides off-screen, slides in as overlay */
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 99;
    transform: translateX(-100%);
    transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
  }
  #sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.35);
  }

  /* Main takes full width */
  #app { display: block; overflow: auto; height: 100vh; }
  #main { height: 100vh; display: flex; flex-direction: column; }

  #top-bar {
    padding: 0 14px;
    gap: 10px;
  }

  #page-title { font-size: 15px; }

  #section-content { padding: 12px; overflow-y: auto; }

  /* Login card */
  .login-card {
    padding: 28px 20px;
    border-radius: 12px;
  }
  .login-logo-name { font-size: 18px; }

  /* Body can scroll */
  body { overflow: auto; }
}
