/* ─────────────────────────────────────────────────────────────────────
   Africa Coffee Park · Management OS · Shell layout
   Topbar · Sidebar (desktop + mobile drawer) · Workspace
   ───────────────────────────────────────────────────────────────────── */

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "top top"
    "side main";
}

/* ── Skip link (a11y) ─────────────────────────────────────────────── */
.skip-link {
  position: absolute; top: -100px; left: 50%; transform: translateX(-50%);
  background: var(--primary); color: #001828;
  padding: 10px 18px; border-radius: var(--radius-sm);
  font-weight: 700; font-size: 13px; z-index: 999;
  transition: top .15s ease;
}
.skip-link:focus { top: 8px; }

/* ── Focus rings — global (a11y) ──────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ── Topbar ───────────────────────────────────────────────────────── */
.topbar {
  grid-area: top;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center;
  padding: 0 var(--space-5);
  gap: var(--space-3);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: var(--space-3); flex-shrink: 0; }
.brand-mark-img { height: 28px; width: auto; display: block; }
.brand-title { font-weight: 700; letter-spacing: -.01em; }
.brand-sub { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .08em; }
.topbar-spacer { flex: 1; }
.topbar-right { display: flex; align-items: center; gap: var(--space-2); }

/* Hamburger — hidden on wide, visible on mobile */
#menu-btn { display: none; }

/* ── Icon buttons ─────────────────────────────────────────────────── */
.icon-btn {
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  display: grid; place-items: center;
  background: transparent; color: var(--text-muted);
  border: 1px solid transparent; cursor: pointer;
  position: relative;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.icon-btn .dot {
  position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--err);
  box-shadow: 0 0 0 2px var(--surface);
}

/* Bell shake animation on new SSE event */
@keyframes bell-shake {
  0%  { transform: rotate(0deg);   }
  15% { transform: rotate(14deg);  }
  30% { transform: rotate(-10deg); }
  45% { transform: rotate(8deg);   }
  60% { transform: rotate(-5deg);  }
  75% { transform: rotate(3deg);   }
  90% { transform: rotate(-1deg);  }
  100%{ transform: rotate(0deg);   }
}
.bell-ring {
  animation: bell-shake .55s ease forwards;
}
@media (prefers-reduced-motion: reduce) {
  .bell-ring { animation: none; }
}

/* ── User chip + dropdown ─────────────────────────────────────────── */
.user-chip {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer; user-select: none;
}
.user-chip:hover { border-color: var(--primary); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; overflow: hidden;
  background: linear-gradient(135deg, var(--primary), var(--accent-2));
  color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 12px; flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.who .name { font-weight: 600; font-size: 13px; }
.who .role { font-size: 11px; color: var(--text-muted); }

/* User dropdown */
.user-dropdown {
  position: fixed; top: calc(var(--topbar-h) + 6px); right: var(--space-5);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-3);
  min-width: 200px; z-index: 30; padding: var(--space-1) 0;
  animation: dropdown-in .12s ease;
}
@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-6px); }
}
.user-menu-item {
  display: flex; align-items: center; gap: var(--space-2);
  width: 100%; padding: 10px var(--space-4);
  background: none; border: none; color: var(--text);
  font: inherit; font-size: 13px; cursor: pointer; text-align: left;
}
.user-menu-item:hover { background: var(--surface-3); color: var(--primary); }
.user-menu-item--danger { color: var(--err); }
.user-menu-item--danger:hover { background: color-mix(in oklab, var(--err) 12%, transparent); color: var(--err); }
.user-menu-divider { height: 1px; background: var(--line); margin: var(--space-1) 0; }

/* ── Sidebar ──────────────────────────────────────────────────────── */
.sidebar {
  grid-area: side;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto; overflow-x: hidden;
  padding: var(--space-3) var(--space-2);
  /* smooth scroll on sidebar itself */
  scroll-behavior: smooth;
}
.nav-group { margin-bottom: var(--space-4); }
.nav-group-title {
  font-size: 10px; text-transform: uppercase;
  color: var(--text-muted);
  padding: var(--space-2) var(--space-3);
  letter-spacing: .1em; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 9px var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  font-weight: 500;
  /* gradient hover — module themed */
  background: transparent;
  transition: background .2s ease, color .2s ease, box-shadow .2s ease;
  position: relative;
}
.nav-item:hover {
  background: linear-gradient(90deg,
    color-mix(in oklab, var(--primary) 12%, transparent),
    transparent 80%);
  color: var(--text);
}
.nav-item.active {
  background: linear-gradient(90deg,
    color-mix(in oklab, var(--primary) 18%, transparent),
    transparent 80%);
  color: var(--primary);
  box-shadow: inset 3px 0 0 var(--primary),
              0 0 24px -10px var(--primary);
}
.nav-item .icon { color: inherit; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--err); color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 999px;
  display: grid; place-items: center; padding: 0 4px;
}
.nav-children { margin-left: var(--space-5); display: none; padding-top: var(--space-1); }
.nav-item.expanded + .nav-children { display: block; }
.nav-child {
  display: block; padding: 6px var(--space-3);
  font-size: 13px; color: var(--text-muted);
  border-radius: var(--radius-sm); cursor: pointer;
}
.nav-child:hover { color: var(--text); background: var(--surface-2); }
.nav-child.active { color: var(--primary); background: var(--surface-2); }

/* Mobile sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 24;
}
.sidebar-overlay.visible { display: block; }

/* ── Workspace ────────────────────────────────────────────────────── */
.workspace {
  grid-area: main;
  overflow: auto;
  padding: var(--space-5);
}
.workspace:focus { outline: none; }

/* ── Breadcrumb (injected by moduleHead) ──────────────────────────── */
.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted);
  margin-bottom: var(--space-2);
}
.breadcrumb a, .breadcrumb span { color: inherit; }
.breadcrumb .crumb-active { color: var(--text); font-weight: 600; }
.breadcrumb .icon-sm { color: var(--text-muted); opacity: .6; }

/* ── Icon helpers ─────────────────────────────────────────────────── */
.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon-lg  { width: 28px; height: 28px; }
.icon-sm  { width: 14px; height: 14px; }
.icon-xl  { width: 40px; height: 40px; }

/* ── Loader + Skeleton ────────────────────────────────────────────── */
.loader {
  display: grid; place-items: center; gap: var(--space-3);
  padding: var(--space-8); color: var(--text-muted);
}
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid var(--surface-2);
  border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Skeleton shimmer — replaces spinner on first mount */
.skeleton {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  position: relative; overflow: hidden;
}
.skeleton::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(90deg,
    transparent 0%,
    color-mix(in oklab, var(--text) 6%, transparent) 40%,
    color-mix(in oklab, var(--text) 10%, transparent) 50%,
    color-mix(in oklab, var(--text) 6%, transparent) 60%,
    transparent 100%);
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton::after { animation: none; }
}
.skeleton-row { height: 44px; margin-bottom: 6px; }

/* ── Toast notifications ──────────────────────────────────────────── */
.toast-root {
  position: fixed; right: var(--space-5); bottom: var(--space-5);
  display: grid; gap: var(--space-2); z-index: 100;
  pointer-events: none;
}
.toast {
  background: var(--surface-2); border: 1px solid var(--line);
  border-left: 3px solid var(--primary);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  min-width: 280px; max-width: 420px;
  animation: toast-in .18s ease;
  pointer-events: auto;
}
.toast.ok  { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
.toast.warn{ border-left-color: var(--warn); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ── Command palette (Cmd+K) ──────────────────────────────────────── */
.palette-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  z-index: 90; display: grid; place-items: start center;
  padding-top: 15vh;
}
/* Browser default `[hidden] { display: none }` loses to .palette-backdrop;
   restore it explicitly so closePalette() actually closes. */
.palette-backdrop[hidden] { display: none; }
.user-dropdown[hidden]    { display: none; }
.palette-box {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); width: 100%; max-width: 580px;
  box-shadow: var(--shadow-3);
  overflow: hidden;
  animation: palette-in .16s ease;
}
@keyframes palette-in {
  from { opacity: 0; transform: scale(.97) translateY(-8px); }
}
.palette-search-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--line);
}
.palette-input {
  flex: 1; background: none; border: none;
  color: var(--text); font: inherit; font-size: 15px;
  outline: none;
}
.palette-input::placeholder { color: var(--text-muted); }
.palette-esc {
  font-size: 11px; color: var(--text-muted);
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 2px 6px; border-radius: 4px;
  font-family: var(--font-mono);
  flex-shrink: 0;
}
.palette-results { max-height: 400px; overflow-y: auto; padding: var(--space-2) 0; }
.palette-section-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--text-muted); padding: 8px var(--space-4) 4px;
  font-weight: 600;
}
.palette-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 9px var(--space-4);
  cursor: pointer; font-size: 13px; color: var(--text);
  border-radius: 0;
}
.palette-item:hover, .palette-item[aria-selected="true"] {
  background: color-mix(in oklab, var(--primary) 12%, transparent);
  color: var(--primary);
}
.palette-item-sub { font-size: 11px; color: var(--text-muted); margin-left: auto; }
.palette-empty {
  padding: var(--space-6); text-align: center;
  color: var(--text-muted); font-size: 13px;
}

/* ── Responsive breakpoints ───────────────────────────────────────── */
/* Rail mode — 1100px */
@media (max-width: 1100px) {
  body { grid-template-columns: var(--sidebar-rail) 1fr; }
  .sidebar .nav-item .label,
  .sidebar .nav-badge,
  .sidebar .nav-group-title,
  .sidebar .nav-children { display: none; }
  .sidebar .nav-item { justify-content: center; padding: 9px 0; }
  .brand-title, .brand-sub, .who { display: none; }
}

/* Mobile — drawer behavior ≤720px */
@media (max-width: 720px) {
  body {
    grid-template-columns: 1fr;
    grid-template-areas: "top" "main";
  }
  .sidebar {
    /* Off-screen by default; slides in when .open */
    position: fixed; inset: 0 auto 0 0;
    width: min(var(--sidebar-w), 82vw);
    z-index: 25; transform: translateX(-110%);
    transition: transform .25s cubic-bezier(.25,.46,.45,.94);
    padding-top: var(--topbar-h);
    /* Restore full labels in mobile drawer */
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar .nav-item .label,
  .sidebar .nav-badge,
  .sidebar .nav-group-title { display: block !important; }
  .sidebar .nav-children    { display: none; }
  .sidebar .nav-item.expanded + .nav-children { display: block; }
  .sidebar .nav-item { justify-content: flex-start; padding: 9px var(--space-3); }
  #menu-btn { display: grid; }
  .brand-title, .brand-sub { display: block !important; }
  .who { display: none; }
  .workspace { padding: var(--space-4) var(--space-3); }
  /* Palette fits small screens */
  .palette-box { margin: 0 var(--space-3); }
}
