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

:root {
  --black: #0f0f0f;
  --white: #fafaf8;
  --accent: #c8392b;
  --mid: #6b6b6b;
  --border: #d4d4d0;
  --surface: #ffffff;
  --section-bg: #f4f4f2;
  --sidebar-w: 72px;
  --sidebar-bg: #1a1a2e;
  --sidebar-hover: #252542;
  --sidebar-active: #3b82f6;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--white);
  min-height: 100vh;
  color: var(--black);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
body.has-sidebar {
  display: flex;
}

.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: fixed;
  top: 0; left: 0;
  z-index: 200;
  overflow-y: auto;
}

.sidebar-top, .sidebar-bottom {
  display: flex;
  flex-direction: column;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 56px;
  font-family: 'DM Serif Display', serif;
  font-size: 24px;
  color: #fff;
  text-decoration: none;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.sidebar-logo span { color: var(--sidebar-active); }

.sidebar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px 0;
  text-decoration: none;
  color: rgba(255,255,255,0.45);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: background 0.12s, color 0.12s;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.sidebar-item:hover {
  background: var(--sidebar-hover);
  color: rgba(255,255,255,0.8);
}
.sidebar-item.active {
  color: #fff;
  background: var(--sidebar-hover);
  border-left-color: var(--sidebar-active);
}

.si-icon { font-size: 20px; line-height: 1; }
.si-label { white-space: nowrap; text-transform: uppercase; letter-spacing: 0.06em; }

.sidebar-user {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 14px 4px 8px;
  color: rgba(255,255,255,0.35);
  font-size: 9px;
  font-weight: 500;
  border-top: 1px solid rgba(255,255,255,0.06);
  overflow: hidden;
}
.sidebar-user .si-icon { font-size: 16px; }
.sidebar-user .si-label {
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.sidebar-bottom .sidebar-item {
  padding: 12px 0 16px;
}

/* ── Main content ────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
}

/* ── Top bar (search) ────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 40px;
  height: 48px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar-search {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--section-bg);
  border: 1px solid var(--border);
  padding: 0 12px;
  max-width: 280px;
  width: 100%;
  transition: border-color 0.12s;
}
.topbar-search:focus-within { border-color: var(--black); background: #fff; }
.topbar-search-icon { font-size: 13px; flex-shrink: 0; }
.topbar-search input {
  flex: 1; border: none; background: transparent; padding: 7px 0;
  font-family: inherit; font-size: 13px; color: var(--black); outline: none;
}
.topbar-search input::placeholder { color: var(--mid); }

/* ── Old top nav (for standalone pages like login, preview) ──────────────── */
nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 40px;
  height: 58px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-logo {
  font-family: 'DM Serif Display', serif;
  font-size: 18px;
  color: var(--black);
  text-decoration: none;
}
.nav-logo span { color: var(--accent); }

.nav-right {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 13px;
  color: var(--mid);
}

.nav-right a {
  color: var(--mid);
  text-decoration: none;
  font-weight: 500;
}
.nav-right a:hover { color: var(--accent); }

/* ── Container & page header ─────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 44px 40px 80px;
}

.container.narrow {
  max-width: 820px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 32px;
}

.page-header h1 {
  font-family: 'DM Serif Display', serif;
  font-size: 28px;
  font-weight: 400;
}

.page-header p {
  font-size: 13px;
  color: var(--mid);
  margin-top: 4px;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 10px 22px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
  letter-spacing: 0.03em;
  transition: background 0.15s, color 0.15s;
}

.btn-primary { background: var(--black); color: #fff; }
.btn-primary:hover { background: var(--accent); }

.btn-ghost {
  background: transparent;
  color: var(--mid);
  border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--black); color: var(--black); }

.btn-danger { background: var(--accent); color: #fff; }
.btn-danger:hover { background: #a52d21; }

/* ── Flash ───────────────────────────────────────────────────────────────── */
.flash {
  background: #fdf0ef;
  border-left: 3px solid var(--accent);
  color: var(--accent);
  font-size: 13px;
  padding: 10px 14px;
  margin-bottom: 20px;
}

/* ── Mobile menu button (hidden on desktop) ─────────────────────────────── */
.mobile-menu-btn {
  display: none;
  background: none; border: none; font-size: 22px; cursor: pointer;
  color: var(--black); padding: 4px 8px; line-height: 1;
}

/* ── Mobile bottom nav (hidden on desktop) ───────────────────────────────── */
.mobile-bottom-nav {
  display: none;
}

/* ── Print ───────────────────────────────────────────────────────────────── */
@media print {
  .sidebar { display: none; }
  .main-content { margin-left: 0; }
  .topbar { display: none; }
  .mobile-bottom-nav { display: none; }
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  /* Hide desktop sidebar, show as slide-out overlay */
  .sidebar {
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 500;
    position: fixed;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 30px rgba(0,0,0,0.3);
  }
  .sidebar .si-label { display: inline; }
  .sidebar-item {
    flex-direction: row;
    gap: 12px;
    padding: 14px 24px;
    font-size: 13px;
    justify-content: flex-start;
  }
  .sidebar-user {
    flex-direction: row;
    gap: 10px;
    padding: 14px 24px;
    font-size: 12px;
  }
  .sidebar-user .si-label { max-width: none; }
  .sidebar-bottom .sidebar-item { padding: 14px 24px; }

  /* Main content full width */
  .main-content { margin-left: 0; }

  /* Show hamburger */
  .mobile-menu-btn { display: block; }

  /* Topbar */
  .topbar { padding: 0 16px; justify-content: space-between; }
  .topbar-search { max-width: 200px; }

  /* Bottom nav */
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 300;
    justify-content: space-around;
    padding: 6px 0 env(safe-area-inset-bottom, 8px);
  }
  .mobile-bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 10px;
    font-weight: 600;
    color: var(--mid);
    text-decoration: none;
    padding: 4px 8px;
  }
  .mobile-bottom-nav a span { font-size: 18px; }
  .mobile-bottom-nav a.active { color: var(--sidebar-active); }

  /* Container */
  .container { padding: 24px 16px 100px; }
  .container.narrow { max-width: 100%; }

  /* Page header stack */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .page-header h1 { font-size: 22px; }

  /* Tables scroll horizontally */
  .w-table, .r-table, .c-table, .loc-table, .fu-table, .dt-table, .eq-table { overflow-x: auto; display: block; }
  .w-header, .w-row { min-width: 700px; }
  .r-header, .r-row { min-width: 600px; }
  .c-header, .c-row { min-width: 650px; }
  .eq-header, .eq-row { min-width: 750px; }
  .loc-header, .loc-row { min-width: 500px; }

  /* Home page list rows stack on mobile */
  .list-row { flex-direction: column; align-items: flex-start; gap: 10px; }
  .row-actions { width: 100%; }

  /* Monitor rows — horizontal scroll on mobile */
  .date-rows { overflow-x: auto; }
  .sub-row { min-width: 700px; font-size: 12px; }

  /* Settings layout single column */
  .settings-layout { grid-template-columns: 1fr !important; }
  .settings-nav {
    border-right: none; border-bottom: 1px solid var(--border);
    padding: 16px 0;
    display: flex; flex-wrap: wrap; gap: 0;
  }
  .settings-nav-title { width: 100%; padding: 4px 16px; margin-bottom: 4px; }
  .settings-nav-item { padding: 8px 16px; font-size: 12px; }
  .settings-nav-sep { margin: 8px 16px; width: calc(100% - 32px); }
  .settings-body { padding: 24px 16px 100px; }

  /* Builder single column */
  .builder-layout { grid-template-columns: 1fr !important; }
  .builder-side { position: static; }

  /* Fill form */
  .field-row { grid-template-columns: 1fr !important; }
  .field-label { border-right: none; border-bottom: 1px solid var(--border); }

  /* List manager */
  .lm-layout { grid-template-columns: 1fr !important; min-height: auto; }
  .lm-left { border-right: none; border-bottom: 1px solid var(--border); max-height: 200px; }

  /* Follow-up builder */
  .fb-layout { grid-template-columns: 1fr !important; }
  .fb-sidebar { position: static; }

  /* Resource library */
  .rl-section-header { flex-wrap: wrap; gap: 8px; }

  /* Modals */
  .sched-box, .lm-modal, .fu-modal, .dt-modal, .c-modal, .rl-modal,
  .loc-box, .workers-box { max-width: 95%; width: 95%; }

  /* Bottom padding for bottom nav */
  main.main-content { padding-bottom: 70px; }
}
