/* components.css — reusable UI pieces */

/* ---------- App shell ---------- */

.app-shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  align-self: start;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: var(--space-4) var(--space-3) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  scrollbar-width: none;       /* Firefox */
  -ms-overflow-style: none;    /* old Edge/IE */
}
.sidebar::-webkit-scrollbar { display: none; } /* Chrome/Safari/new Edge */

.content-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Org switcher — bordered box at the very top of the sidebar */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-3);
}
.sidebar-brand .brand-meta { flex: 1; min-width: 0; }
.sidebar-brand .brand-plan { font-size: 11px; color: var(--color-ink-faint); }
.sidebar-brand .brand-chevron { color: var(--color-ink-faint); flex-shrink: 0; }
.sidebar-brand .brand-chevron svg { width: 14px; height: 14px; }

/* Sidebar search */
.sidebar-search {
  display: flex; align-items: center; gap: var(--space-2);
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  height: 58px; padding: 0 var(--space-3); margin-bottom: var(--space-4);
  color: var(--color-ink-faint);
}
.sidebar-search svg { width: 14px; height: 14px; flex-shrink: 0; }
.sidebar-search input {
  border: none !important; outline: none; background: transparent !important; font-size: 13px;
  border-radius: 0 !important; padding: 0 !important;
  width: 100%; color: var(--color-ink);
}
.sidebar-search input::placeholder { color: var(--color-ink-faint); }

.sidebar-brand-mark {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.sidebar-brand-mark svg { width: 18px; height: 18px; }

.sidebar-brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-lg);
  letter-spacing: -0.01em;
}

.nav-group { display: flex; flex-direction: column; gap: 2px; }

.nav-section + .nav-section {
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
}

.nav-group-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-ink-faint);
  padding: var(--space-1) var(--space-3) var(--space-2);
  font-weight: 700;
}
.nav-group-label svg { width: 13px; height: 13px; stroke-width: 2; }

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 7px var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-ink-muted);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}

.nav-link .nav-badge {
  margin-left: auto;
  font-size: 11px; font-weight: 700; color: var(--color-ink-faint);
  background: var(--color-surface-sunken); border-radius: 999px;
  padding: 1px 7px;
}

.nav-link svg { width: 16px; height: 16px; flex-shrink: 0; stroke-width: 1.8; }

.nav-link:hover { background: var(--color-surface-sunken); text-decoration: none; color: var(--color-ink); }

.nav-link.active {
  background: var(--color-primary-tint);
  color: var(--color-primary);
  font-weight: 600;
}

.nav-link.active::before {
  content: '';
  position: absolute;
  left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 18px;
  border-radius: 0 3px 3px 0;
  background: var(--color-primary);
}

.nav-sub { padding-left: var(--space-3); display: flex; flex-direction: column; gap: 2px; }

.main {
  padding: var(--space-4);
  max-width: 1400px;
}

/* ---------- Top bar ---------- */
/* This is now the full-width bar itself (rendered directly into a <header id="topbar-root">
   that sits outside .main's padding), touching the sidebar on the left and the viewport's
   right edge -- not an inner wrapper anymore. */

.topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  height: 80px;
  padding: 0 var(--space-5);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.topbar-left { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.topbar-left .topbar-greeting { font-size: var(--text-sm); font-weight: 600; color: var(--color-ink); }
.topbar-left .topbar-date { font-size: 12px; color: var(--color-ink-faint); }

.topbar-right { display: flex; align-items: center; gap: var(--space-2); }

.topbar-search {
  display: flex; align-items: center; gap: var(--space-2);
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  height: 34px; padding: 0 var(--space-3); color: var(--color-ink-faint); width: 190px;
  flex-shrink: 0;
}
.topbar-search svg { width: 14px; height: 14px; flex-shrink: 0; }
.topbar-search input {
  border: none !important; outline: none; background: transparent !important;
  border-radius: 0 !important; padding: 0 !important;
  font-size: 13px; line-height: 1; width: 100%; color: var(--color-ink);
}
.topbar-search input::placeholder { color: var(--color-ink-faint); }

.topbar .topbar-icon-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-ink-muted);
  position: relative;
}
.topbar .topbar-icon-btn:hover { background: var(--color-surface-sunken); text-decoration: none; }
.topbar .topbar-icon-btn svg { width: 16px; height: 16px; stroke-width: 1.8; }

.topbar .topbar-badge {
  position: absolute; top: -3px; right: -3px;
  min-width: 16px; height: 16px; padding: 0 3px; border-radius: 8px;
  background: var(--color-danger); border: 1.5px solid var(--color-surface);
  color: #fff; font-size: 10px; font-weight: 700; line-height: 13px; text-align: center;
  display: none;
}
.topbar .topbar-badge.show { display: block; }

.notif-popup-stack {
  position: fixed; top: 70px; right: var(--space-5); z-index: 1100;
  display: flex; flex-direction: column; gap: var(--space-2); max-width: 320px;
}
.notif-popup {
  background: var(--color-surface); border: 1px solid var(--color-border); border-left: 3px solid var(--color-primary);
  border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); box-shadow: var(--shadow-raised);
  animation: notif-in var(--duration-base) var(--ease); cursor: pointer;
}
.notif-popup strong { display: block; font-size: var(--text-sm); margin-bottom: 2px; }
.notif-popup p { font-size: var(--text-xs); color: var(--color-ink-muted); margin: 0; }
@keyframes notif-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

.topbar-divider { width: 1px; height: 24px; background: var(--color-border); margin: 0 var(--space-1); }

.topbar .topbar-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--color-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; font-family: var(--font-display);
  flex-shrink: 0;
}


.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
}

.page-header .eyebrow {
  font-size: var(--text-sm);
  color: var(--color-ink-faint);
  margin-bottom: var(--space-1);
}

/* ---------- Cards ---------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  box-shadow: var(--shadow-card);
}

.stat-card .stat-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: var(--color-primary-tint);
  color: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: var(--space-4);
}
.stat-card .stat-icon svg { width: 18px; height: 18px; stroke-width: 2; }

.stat-card .stat-label {
  font-size: var(--text-sm);
  color: var(--color-ink-muted);
  margin-bottom: var(--space-1);
}

.stat-card .stat-value {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.stat-card .stat-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--text-xs);
  font-weight: 700;
  margin-top: var(--space-3);
  padding: 2px var(--space-2);
  border-radius: 999px;
}
.stat-delta.up { color: var(--color-success); background: var(--color-success-tint); }
.stat-delta.down { color: var(--color-danger); background: var(--color-danger-tint); }
.stat-delta-label { color: var(--color-ink-faint); font-size: var(--text-xs); margin-left: var(--space-1); }

/* ---------- Icon buttons / toolbar ---------- */

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-ink-muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--color-surface-sunken); color: var(--color-ink); }
.icon-btn svg { width: 16px; height: 16px; stroke-width: 1.8; }

.btn svg { width: 15px; height: 15px; stroke-width: 2; flex-shrink: 0; }

/* ---------- Buttons ---------- */

.btn {

  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
}

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); text-decoration: none; }

.btn-secondary { background: var(--color-surface); border-color: var(--color-border); color: var(--color-ink); }
.btn-secondary:hover { background: var(--color-surface-sunken); text-decoration: none; }

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

.btn-ghost { background: transparent; color: var(--color-ink-muted); }
.btn-ghost:hover { background: var(--color-surface-sunken); text-decoration: none; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-4); }
.field label { font-size: var(--text-sm); font-weight: 600; color: var(--color-ink); }
.field .hint { font-size: var(--text-xs); color: var(--color-ink-faint); }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="number"], input[type="tel"], select, textarea {
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-ink);
  transition: border-color var(--duration-fast) var(--ease);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--color-primary);
}

/* ---------- Tables ---------- */

.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table th {
  text-align: left;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-ink-faint);
  padding: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}
.data-table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.data-table tr:hover td { background: var(--color-surface-sunken); }

@media (max-width: 720px) {
  .data-table thead { display: none; }
  .data-table tr { display: block; border-bottom: 1px solid var(--color-border); padding: var(--space-3) 0; }
  .data-table td { display: flex; justify-content: space-between; border: none; padding: var(--space-1) 0; }
  .data-table td::before { content: attr(data-label); font-weight: 600; color: var(--color-ink-muted); margin-right: var(--space-3); }
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
}
.badge-success { background: var(--color-success-tint); color: var(--color-success); }
.badge-warning { background: var(--color-warning-tint); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-tint); color: var(--color-danger); }
.badge-neutral { background: var(--color-surface-sunken); color: var(--color-ink-muted); }
.badge-gold { background: var(--color-gold-tint); color: var(--color-gold); }

/* ---------- Empty / loading states ---------- */

.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-5);
  color: var(--color-ink-muted);
}
.empty-state .arch-mark { margin: 0 auto var(--space-4); display: block; }
.empty-state h3 { margin-bottom: var(--space-2); }

.skeleton {
  background: linear-gradient(90deg, var(--color-surface-sunken) 25%, #eceae3 37%, var(--color-surface-sunken) 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-loading {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ---------- Toasts ---------- */

.toast-stack {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 1000;
}
.toast {
  background: var(--color-ink);
  color: #fff;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-raised);
  animation: toast-in var(--duration-base) var(--ease);
}
.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Mobile nav (hamburger + slide-in sidebar drawer) ---------- */
/* Centralized here instead of duplicated per-page -- every page's old inline
   "@media (max-width:900px){.sidebar{display:none}}" rule has been removed and replaced by
   this, since simply hiding the sidebar left mobile users with no way to navigate at all. */

.mobile-menu-btn { display: none; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .main { padding: var(--space-4); }

  .mobile-menu-btn { display: flex; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    width: 280px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform var(--duration-base) var(--ease);
    box-shadow: var(--shadow-raised);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 190;
  }
  .sidebar-backdrop.open { display: block; }

  /* The greeting text and search box are what were overlapping and causing the broken layout
     -- both drop off entirely on narrow screens, leaving just the icon row. */
  .topbar-left { display: none; }
  .topbar-search { display: none; }
  .topbar { padding: 0 var(--space-4); }
}
