/* ============================================================
   SafePlate Design System
   ============================================================ */

:root {
  --bg: #F7F5F0;
  --surface: #FFFFFF;
  --surface-alt: #F0EDE6;
  --primary: #1B6B5A;
  --primary-hover: #155A4B;
  --primary-light: #E8F4F0;
  --primary-lighter: #F2FAF7;
  --accent: #D4853A;
  --accent-light: #FEF3E8;
  --success: #2D8A54;
  --success-light: #E8F5ED;
  --danger: #C44B4B;
  --danger-light: #FDE8E8;
  --warning: #B8860B;
  --warning-light: #FEF9E8;
  --bio: #2E6DB4;
  --bio-light: #E8F0FA;
  --text: #1A1A1A;
  --text-secondary: #5A5550;
  --text-muted: #9B9590;
  --border: #E5E0D8;
  --border-light: #F0EBE3;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.07);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --sidebar-w: 272px;
  --topbar-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
h1, h2, h3 { font-family: 'DM Serif Display', serif; font-weight: 400; line-height: 1.25; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ── App Layout ─────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

/* ── Sidebar ────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 20;
  transition: transform 0.3s ease;
}
.sidebar-brand {
  padding: 24px 24px 20px;
  border-bottom: 1px solid var(--border-light);
}
.sidebar-brand .logo {
  font-family: 'DM Serif Display', serif;
  font-size: 1.35rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.nav-group-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 12px 12px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.2s ease;
  text-decoration: none;
}
.nav-item:hover { background: var(--surface-alt); color: var(--text-secondary); text-decoration: none; }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-item .nav-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  background: var(--surface-alt);
  transition: all 0.2s ease;
}
.nav-item.active .nav-icon { background: var(--primary); color: #fff; }
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-light);
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.save-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }

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

/* ── Topbar ─────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 40px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.mobile-menu-btn { display: none; color: var(--text-muted); padding: 4px; }

.user-menu { position: relative; }
.user-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
  font-size: 0.85rem;
  color: var(--text);
}
.user-trigger:hover { background: var(--surface-alt); }
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem;
  font-weight: 600;
}
.user-name { font-weight: 500; }
.user-dropdown {
  position: absolute;
  top: 100%; right: 0;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  min-width: 180px;
  z-index: 30;
  overflow: hidden;
}
.dropdown-item {
  display: block;
  padding: 10px 16px;
  font-size: 0.85rem;
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s;
  width: 100%;
  text-align: left;
}
.dropdown-item:hover { background: var(--surface-alt); text-decoration: none; }
.dropdown-divider { border: none; border-top: 1px solid var(--border-light); margin: 0; }
.dropdown-form { margin: 0; }

/* ── Content Area ───────────────────────────────── */
.content { flex: 1; padding: 32px 40px 40px; }
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
}
.page-header h1 { font-size: 1.75rem; margin-bottom: 4px; }
.page-header .ph-sub { font-size: 0.9rem; color: var(--text-muted); }

/* ── Module Grid (Dashboard) ────────────────────── */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.module-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 24px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.25s ease;
}
.module-card:hover {
  border-color: var(--primary);
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}
.module-card .mc-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 16px;
}
.module-card h3 {
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.module-card p { font-size: 0.82rem; color: var(--text-muted); line-height: 1.5; }

/* ── Buttons ────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.2s ease;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); text-decoration: none; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn-block { display: flex; width: 100%; justify-content: center; }

/* ── Forms ──────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s;
  outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group input.field-error { border-color: var(--danger); }
.form-error { font-size: 0.78rem; color: var(--danger); margin-top: 4px; display: block; }

/* ── Alerts ─────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 20px;
  border: 1px solid;
}
.alert-danger { background: var(--danger-light); border-color: #f0b8b8; color: var(--danger); }
.alert-success { background: var(--success-light); border-color: #b8ddc8; color: var(--success); }
.alert-info { background: var(--bio-light); border-color: #b8d0e8; color: var(--bio); }

/* ── Auth Pages ─────────────────────────────────── */
.auth-body {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.auth-wrapper { width: 100%; max-width: 420px; }
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
}
.auth-logo { text-align: center; margin-bottom: 28px; color: var(--primary); }
.auth-logo h1 { font-size: 1.5rem; margin: 8px 0 4px; }
.auth-logo p { font-size: 0.85rem; color: var(--text-muted); }
.auth-switch { text-align: center; margin-top: 20px; font-size: 0.85rem; color: var(--text-muted); }
.auth-switch a { font-weight: 600; }
.auth-footer { text-align: center; font-size: 0.78rem; color: var(--text-muted); margin-top: 20px; }

/* ── Data Table ─────────────────────────────────── */
.table-card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 24px;
}
.tc-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-light);
}
.tc-header h3 {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.95rem; font-weight: 600; margin: 0;
}
.tc-count { font-size: 0.78rem; color: var(--text-muted); }

.data-table {
    width: 100%; border-collapse: collapse;
}
.data-table th {
    text-align: left; font-size: 0.68rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-muted); padding: 12px 16px;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: 10px 16px; font-size: 0.85rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface-alt); }

/* ── Responsive ─────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; }
  .content { padding: 20px; }
  .topbar { padding: 0 20px; }
  .mobile-menu-btn { display: flex; }
  .module-grid { grid-template-columns: 1fr; }
  .user-name { display: none; }
}

/* ── Notification Bell ───────────────────────────── */
[x-cloak] { display: none !important; }
.notif-bell-wrap { position: relative; }
.notif-bell-btn {
    position: relative;
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    transition: background 0.15s, color 0.15s;
}
.notif-bell-btn:hover { background: var(--surface-alt); color: var(--text); }
.notif-bell-badge {
    position: absolute; top: 3px; right: 3px;
    min-width: 16px; height: 16px; padding: 0 4px;
    border-radius: 9px;
    background: var(--danger); color: #fff;
    font-size: 10px; font-weight: 700;
    line-height: 16px; text-align: center;
}
.notif-bell-dropdown {
    position: absolute; top: calc(100% + 8px); right: 0;
    width: 360px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg); z-index: 100; overflow: hidden;
}
.nbd-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; border-bottom: 1px solid var(--border-light);
}
.nbd-title { font-size: 0.85rem; font-weight: 600; }
.nbd-action {
    font-size: 0.75rem; font-weight: 600; color: var(--primary);
    background: none; border: none; cursor: pointer;
}
.nbd-action:hover { text-decoration: underline; }
.nbd-body { max-height: 340px; overflow-y: auto; }
.nbd-body::-webkit-scrollbar { width: 4px; }
.nbd-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.nbd-empty { padding: 28px 16px; text-align: center; font-size: 0.82rem; color: var(--text-muted); }
.nbd-item {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 16px; border-bottom: 1px solid var(--border-light);
    text-decoration: none; color: var(--text); transition: background 0.12s;
}
.nbd-item:last-child { border-bottom: none; }
.nbd-item:hover { background: var(--surface-alt); text-decoration: none; }
.nbd-unread { background: #f8fffe; }
.nbdi-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); flex-shrink: 0; margin-top: 5px; }
.nbdi-content { flex: 1; min-width: 0; }
.nbdi-title { font-size: 0.82rem; font-weight: 600; line-height: 1.3; margin-bottom: 2px; }
.nbdi-message { font-size: 0.78rem; color: var(--text-muted); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.nbdi-meta { display: flex; gap: 8px; margin-top: 4px; font-size: 0.7rem; color: var(--text-muted); }
.nbdi-source { text-transform: capitalize; font-weight: 600; color: var(--primary); }
.nbd-footer { padding: 10px 16px; text-align: center; border-top: 1px solid var(--border-light); }
.nbd-view-all { font-size: 0.78rem; font-weight: 600; color: var(--primary); }
.nbd-view-all:hover { text-decoration: underline; }

/* ── Plan Badge ──────────────────────────────────── */
.plan-badge {
    display: inline-block; padding: 2px 8px; border-radius: 4px;
    background: var(--primary-light); color: var(--primary);
    font-size: 0.68rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.05em; margin-right: 6px;
}

/* ── Subscription Page ───────────────────────────── */
.sub-current-card {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--surface); border: 1px solid var(--border-light);
    border-radius: var(--radius-md); padding: 28px 32px;
    margin-bottom: 36px; box-shadow: var(--shadow-sm);
}
.scc-plan { font-family: 'DM Serif Display', serif; font-size: 1.5rem; color: var(--text); margin-bottom: 4px; }
.scc-status { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 8px; }
.scc-status-dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-trial { background: var(--bio); }
.dot-active { background: var(--success); }
.dot-past_due { background: var(--warning); }
.dot-cancelled { background: var(--text-muted); }
.dot-expired { background: var(--danger); }
.scc-details { font-size: 0.82rem; color: var(--text-muted); }
.scc-right { text-align: right; }
.scc-price { font-family: 'DM Serif Display', serif; font-size: 1.5rem; color: var(--primary); margin-bottom: 8px; }
.btn-cancel { font-size: 0.78rem; color: var(--text-muted); text-decoration: underline; cursor: pointer; background: none; border: none; }
.btn-cancel:hover { color: var(--danger); }
.sub-section-title { font-size: 1.25rem; margin-bottom: 20px; }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; margin-bottom: 40px; }
.plan-card {
    background: var(--surface); border: 2px solid var(--border-light);
    border-radius: var(--radius-md); padding: 28px 24px;
    display: flex; flex-direction: column;
    transition: border-color 0.2s, transform 0.2s;
}
.plan-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.plan-current { border-color: var(--primary); }
.plan-premium { border-color: var(--accent); }
.plan-header { margin-bottom: 20px; }
.plan-name { font-family: 'DM Serif Display', serif; font-size: 1.25rem; margin-bottom: 4px; }
.plan-price { font-size: 1.75rem; font-weight: 700; margin-bottom: 2px; }
.plan-annual { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 10px; }
.plan-desc { font-size: 0.82rem; color: var(--text-secondary); line-height: 1.5; }
.plan-features { flex: 1; margin-bottom: 20px; }
.plan-feature { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 0.82rem; color: var(--text-secondary); }
.pf-check { color: var(--success); font-weight: 700; }
.plan-action { margin-top: auto; }
.plan-current-label { display: block; text-align: center; font-size: 0.82rem; font-weight: 600; color: var(--primary); padding: 10px; }
.btn-premium { background: var(--accent); }
.btn-premium:hover { background: #b87030; }

/* ── Upgrade Required ────────────────────────────── */
.upgrade-card {
    background: var(--surface); border: 1px solid var(--border-light);
    border-radius: var(--radius-lg); padding: 48px 36px;
    text-align: center; max-width: 520px; box-shadow: var(--shadow-md);
}
.uc-icon {
    width: 80px; height: 80px; border-radius: 50%;
    background: var(--accent-light); color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 20px;
}
.uc-title { font-size: 1.25rem; margin-bottom: 10px; }
.uc-desc { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 28px; line-height: 1.5; }
.uc-actions { display: flex; gap: 10px; justify-content: center; }

@media (max-width: 900px) {
    .sub-current-card { flex-direction: column; text-align: center; gap: 16px; }
    .scc-right { text-align: center; }
    .plan-grid { grid-template-columns: 1fr; }
    .notif-bell-dropdown { width: 300px; right: -40px; }
    .uc-actions { flex-direction: column; }
}

/* ── Trial Banner ─────────────────────────────────── */
.trial-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 20px;
    background: var(--accent-light);
    border: 1px solid #f0d0b0;
    border-radius: var(--radius-sm);
    margin-bottom: 24px;
}
.tb-info { font-size: 0.85rem; color: var(--text); }
.tb-info strong { color: var(--accent); }

/* ── Demo Banner ─────────────────────────────────── */
.demo-banner {
    position: fixed;
    top: 0; left: 0; right: 0;
    background: #DC2626;
    color: #fff;
    padding: 8px 20px;
    font-size: 0.82rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    z-index: 9998;
}

/* ── Outlet Switcher ─────────────────────────────── */
.outlet-switcher {
    position: relative;
    margin-right: 6px;
}
.outlet-switcher-trigger {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 10px; border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: var(--surface-alt);
    cursor: pointer; font-family: inherit;
    font-size: 0.78rem; font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.15s;
}
.outlet-switcher-trigger:hover {
    border-color: var(--primary);
    color: var(--primary);
}
.outlet-switcher-name {
    max-width: 140px; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.outlet-switcher-chevron {
    transition: transform 0.2s;
}
.outlet-switcher-chevron.open {
    transform: rotate(180deg);
}
.outlet-switcher-dropdown {
    position: absolute; top: calc(100% + 6px); right: 0;
    min-width: 260px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1000; overflow: hidden;
}
.osd-header {
    padding: 10px 16px; font-size: 0.7rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--text-muted); border-bottom: 1px solid var(--border-light);
}
.osd-list { padding: 4px; max-height: 280px; overflow-y: auto; }
.osd-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 10px 12px; border-radius: 6px;
    border: none; background: none; cursor: pointer;
    font-family: inherit; font-size: 0.82rem; font-weight: 500;
    color: var(--text); transition: background 0.1s;
    text-align: left;
}
.osd-item:hover:not(:disabled) { background: var(--surface-alt); }
.osd-item:disabled { cursor: default; }
.osd-item.osd-current {
    background: var(--primary-light); color: var(--primary); font-weight: 600;
}
.osd-check { margin-left: auto; color: var(--primary); }

/* ── Topbar Static Outlet ────────────────────────── */
.topbar-outlet-static {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.8rem; color: var(--text-muted); margin-right: 8px;
}
.topbar-outlet-name { font-weight: 600; }

/* ── Topbar Role Badge ───────────────────────────── */
.topbar-role-badge {
    font-size: 0.7rem; font-weight: 600;
    padding: 2px 8px; border-radius: 4px;
    background: var(--primary-light); color: var(--primary);
    margin-right: 4px;
}

/* ── Outlet Switcher Empty State ─────────────────── */
.osd-empty {
    padding: 16px;
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-muted);
}
