/* ─────────────────────────────────────────────────
   app.css  —  Ratebook · shared theme + shell
   ───────────────────────────────────────────────── */

/* ── Theme tokens ──────────────────────────────────────────── */
:root {
  /* Surfaces */
  --bg:           #0B1322;
  --surface:      #111C31;
  --surface2:     #182642;
  --border:       #223050;

  /* Accent: Ratebook rust */
  --accent:       #C8702E;
  --accent-hover: #D67F3C;

  /* Brand reference tokens */
  --brand-navy:   #192D52;
  --brand-rust:   #C8702E;

  /* Semantic colours */
  --green:        #22c55e;
  --yellow:       #facc15;
  --danger:       #ef4444;
  --red:          #ef4444;   /* alias used in some pages */

  /* Type */
  --text:         #e2e8f0;
  --muted:        #7b82a0;

  /* Theme-switchable tokens (light mode overrides these below) */
  --on-accent:     #0B1322;              /* dark navy text on rust buttons (≈5.5:1, passes AA) */
  --nav-hover-bg:  rgba(255, 255, 255, 0.04);
  --accent-subtle: rgba(200, 112, 46, 0.12);
  --blue-text:     #7eb4ff;

  /* Layout */
  --sidebar-w:    220px;
}

/* ── Light theme ────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:            #f0f2f7;
  --surface:       #ffffff;
  --surface2:      #eef1f8;
  --border:        #cdd3e4;

  --accent:        #A85A24;      /* darkened rust — ≈5.4:1 contrast on white */
  --accent-hover:  #8F4C1E;      /* deeper rust */

  --green:         #16a34a;      /* green-600 */
  --yellow:        #b45309;      /* amber-700 — dark enough to read on light bg */
  --danger:        #dc2626;      /* red-600 */
  --red:           #dc2626;

  --text:          #111827;      /* gray-900 */
  --muted:         #6b7280;      /* gray-500 */

  --on-accent:     #ffffff;      /* white text on darkened-rust accent (≈5.4:1) */
  --nav-hover-bg:  rgba(0, 0, 0, 0.05);
  --accent-subtle: rgba(168, 90, 36, 0.10);
  --blue-text:     #2563eb;      /* blue-600 — AA contrast on light bg */
}

/* ── Reset / base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ── App shell ─────────────────────────────────────────────── */
/* Wraps sidebar + main-content. All pages get this. */
.app-shell {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow-y: auto;
}

/* Logo slot at top of sidebar */
.sidebar-logo {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-logo a {
  display: block;
  line-height: 1;
  text-decoration: none;
}
.sidebar-logo img {
  height: 30px;
  width: auto;
  display: block;
}

/* Ratebook wordmark (three-bar mark + styled text, theme-aware) */
.brand-link {
  display: flex; align-items: center; gap: 8px;
  color: #E8ECF4; text-decoration: none;
}
[data-theme="light"] .brand-link { color: var(--brand-navy); }
.brand-word { font-size: 19px; letter-spacing: -0.4px; font-weight: 300; line-height: 30px; }
.brand-word b { font-weight: 600; }

/* Nav list */
.sidebar-nav {
  padding: 10px 0 20px;
  flex: 1;
}

.nav-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--muted);
  padding: 14px 20px 5px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.nav-item:hover {
  color: var(--text);
  background: var(--nav-hover-bg);
}
.nav-item.active {
  color: var(--accent);
  background: var(--accent-subtle);
  border-left-color: var(--accent);
}

.nav-icon {
  font-size: 15px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  opacity: 0.8;
}
.nav-item.active .nav-icon,
.nav-item:hover  .nav-icon { opacity: 1; }

/* ── Main content area ─────────────────────────────────────── */
/* Takes all space to the right of the fixed sidebar.
   Acts as the scroll container so the sidebar stays pinned. */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ── Role-based visibility (set by auth.js on body[data-role]) ── */
/* view  : read-only — hide all mutating controls                   */
/* standard : hide admin-only controls                              */
body[data-role="view"] [data-requires="standard"],
body[data-role="view"] [data-requires="admin"],
body[data-role="standard"] [data-requires="admin"] {
  display: none !important;
}

/* ── Sidebar user widget (injected by auth.js) ─────────────── */
.sidebar-user {
  margin-top: auto;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.user-role-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 2px 5px;
  border-radius: 4px;
  flex-shrink: 0;
}
.user-role-badge.role-admin    { background: rgba(200,112,46,.20); color: var(--accent); }
.user-role-badge.role-standard { background: rgba(79,142,247,.18); color: var(--blue-text); }
.user-role-badge.role-view     { background: rgba(123,130,160,.15); color: var(--muted); }

.btn-logout {
  width: 100%;
  padding: 7px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
  text-align: left;
}
.btn-logout:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ── "My account" button (sidebar user widget) ──────────────── */
.btn-account {
  padding: 7px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
  text-align: left;
}
.btn-account:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* ── Theme toggle button (sidebar + login page) ─────────────── */
.btn-theme-toggle {
  padding: 6px 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color .15s;
}
.btn-theme-toggle:hover { border-color: var(--accent); }

/* Floating variant used on login page (no sidebar) */
.btn-theme-float {
  position: fixed;
  top: 14px;
  right: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  z-index: 10;
  transition: border-color .15s;
}
.btn-theme-float:hover { border-color: var(--accent); }
