/* =============================================================
   Malina — App Shell Layout
   App grid, sidebar, globalbar, topbar, mini-calendar
   ============================================================= */

/* ============================================================
   APP GRID
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  /* dvh + interactive-widget=overlays-content: the soft keyboard overlays the
     UI instead of resizing the shell, so the grid no longer jumps while typing. */
  height: 100dvh;
  /* Floor as well as a ceiling: on the browsers that still shrink the visual
     viewport for the keyboard, `height` alone lets the shell collapse and the
     grid rows reflow mid-typing. `height` (not min-height alone) has to stay —
     .main/.content scroll internally off a definite height, and dropping it
     would push the scroll onto the page and break the schedule grid. */
  min-height: 100dvh;
  overflow: hidden;
}
.app:has(.sidebar.collapsed) { grid-template-columns: 52px 1fr; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
/* `overflow: auto` (not `scroll`) plus a hard `overflow-x: hidden`: the content
   column scrolls VERTICALLY only. Anything too wide has to scroll inside its own
   container (.table-wrap, .emp-table, …) rather than dragging the whole column
   sideways — a sideways-scrolled column leaves its background behind, which shows
   up as a stray strip down the right edge of the screen. `min-width: 0` stops a
   wide grid/table child from inflating the column past its grid track. */
.content { flex: 1; overflow: auto; overflow-x: hidden; min-height: 0; min-width: 0; }
/* Sections are flex/grid parents of dense tables — without min-width:0 an
   intrinsically wide child stretches the section instead of scrolling inside it. */
.crm-section { min-width: 0; max-width: 100%; }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  background: var(--bg-elev-1);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  position: relative;
  transition: width 0.25s cubic-bezier(0.4,0,0.2,1);
}

.sidebar.collapsed { width: 52px; }
.sidebar.collapsed .sb-workspace .ws-info { display: none; }
.sidebar.collapsed .sb-workspace .ws-disc { display: none; }
.sidebar.collapsed .sb-workspace .ws-menu {
  display: flex; /* keep hamburger visible so user can re-expand */
}
.sidebar.collapsed .sb-workspace {
  justify-content: center;
  padding: 14px 10px;
}
.sidebar.collapsed .sb-cal { display: none; }
.sidebar.collapsed .nav-item .label,
.sidebar.collapsed .nav-item .badge,
.sidebar.collapsed .nav-item .caret,
.sidebar.collapsed .nav-sub { display: none; }
.sidebar.collapsed .sb-footer .label { display: none; }

.sb-workspace {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.sb-workspace .ws-disc {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--gold-200), var(--gold-400));
  color: var(--accent-ink);
  font-family: var(--font-display);
  font-weight: 600; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: 0;
  flex-shrink: 0;
}
.sb-workspace .ws-info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.sb-workspace .ws-name {
  font-family: var(--font-display);
  font-weight: 600; font-size: 17px;
  letter-spacing: -0.005em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--fg);
}
.sb-workspace .ws-branch {
  font-size: 11px; color: var(--fg-muted);
  display: flex; align-items: center; gap: 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sb-workspace .ws-branch .lucide { width: 11px; height: 11px; flex-shrink: 0; }
.sb-workspace .ws-menu {
  width: 30px; height: 30px;
  border-radius: var(--radius-md);
  color: var(--fg-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--dur-fast) var(--ease-out);
}
.sb-workspace .ws-menu:hover { background: var(--bg-elev-2); color: var(--fg); }

.sb-cal {
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}

.sb-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 6px;
  display: flex; flex-direction: column;
  gap: 2px;
  min-height: 0;
}

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--fg-muted);
  font-weight: 500; font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
  user-select: none;
}
.nav-item:hover { background: var(--bg-elev-2); color: var(--fg); }
.nav-item.active {
  background: var(--accent-tint);
  border-color: var(--accent-border);
  color: var(--accent);
}
.nav-item .lucide { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item .label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item .badge {
  background: var(--accent-tint-2); color: var(--accent);
  border-radius: var(--radius-pill);
  padding: 1px 8px;
  font-size: 11px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
}
.nav-item .caret { width: 14px; height: 14px; color: var(--fg-dim); transition: transform var(--dur-fast) var(--ease-out); }
.nav-item[aria-expanded="true"] .caret { transform: rotate(90deg); }

.nav-sub {
  display: none;
  flex-direction: column; gap: 1px;
  margin: 2px 0 6px 16px;
  padding-left: 14px;
  border-left: 1px solid var(--border-soft);
  /* `.sb-nav` is a flex column; without flex-shrink:0 the sub-list gets squashed
     to 0px when the sidebar runs out of vertical space, hiding the items inside. */
  flex-shrink: 0;
}
.nav-sub.open {
  display: flex;
}
.nav-item { flex-shrink: 0; }
.nav-sub-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px; color: var(--fg-muted);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.nav-sub-item:hover { background: var(--bg-elev-2); color: var(--fg); }
.nav-sub-item.active { color: var(--accent); background: var(--accent-dim, rgba(201,168,76,0.10)); font-weight: 600; }
.nav-sub-item .dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.nav-sub-item .name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-sub-item .meta { font-size: 11px; color: var(--fg-dim); letter-spacing: 0.04em; }
.nav-sub-item.active .meta { color: var(--gold-200); }
.nav-sub-item .lucide { width: 13px; height: 13px; opacity: 0.7; }

.sb-footer {
  border-top: 1px solid var(--border-soft);
  padding: 8px 10px;
  flex-shrink: 0;
}
.sb-footer .nav-item { color: var(--fg-muted); }

/* ============================================================
   GLOBAL BAR (top, above topbar)
   ============================================================ */
.globalbar {
  display: flex;
  align-items: center;
  height: 56px;
  padding: 0 22px;
  gap: 10px;
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
  position: relative;
  z-index: var(--z-sticky);
}
.globalbar-spacer { flex: 1; }

/* Global back button (#globalBackBtn). Icon + parent-section label; the label is
   dropped on narrow screens where the arrow alone has to carry it. `display` is
   owned by syncBackNav() in app.js, so only sizing/typography lives here. */
#globalBackBtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;              /* .icon-btn is a fixed square — this one has a label */
  padding: 0 10px;
  flex-shrink: 0;
  max-width: 45vw;
}
#globalBackBtn .back-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 560px) {
  #globalBackBtn .back-label { display: none; }
  #globalBackBtn { padding: 0; }
}

.lang-toggle {
  display: inline-flex;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 3px;
}
.lang-toggle button {
  border: none; background: transparent;
  color: var(--fg-muted);
  font: inherit; font-weight: 600; font-size: 12px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: all var(--dur-fast) var(--ease-out);
}
.lang-toggle button:hover { color: var(--fg); }
.lang-toggle button.active { background: var(--accent-tint-2); color: var(--accent); }

.user-av {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--gold-200), var(--gold-400));
  color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  cursor: pointer;
  letter-spacing: 0;
  user-select: none;
  transition: transform var(--dur-fast) var(--ease-out);
}
.user-av:hover { transform: scale(1.04); }

.icon-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--fg-muted); cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  transition: all var(--dur-fast) var(--ease-out);
  position: relative;
}
.icon-btn:hover { background: var(--bg-elev-2); color: var(--fg); }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn .lucide { width: 17px; height: 17px; }

.notif-dot {
  position: absolute; top: 6px; right: 6px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--danger);
  border: 1.5px solid var(--bg-base);
}

/* ============================================================
   NOTIFICATIONS PANEL
   ============================================================ */
.notif-panel {
  position: absolute; top: 56px; right: 16px;
  width: 340px; max-height: calc(100vh - 80px);
  max-height: calc(100dvh - 80px);
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  display: flex; flex-direction: column;
  overflow: hidden;
  opacity: 0; pointer-events: none;
  /* visibility keeps the closed panel out of hit-testing and the a11y tree;
     the 0s/delayed toggle preserves the opacity/transform transitions. */
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out),
              visibility 0s linear var(--dur-base);
}
.notif-panel.open { opacity: 1; pointer-events: all; visibility: visible; transform: translateY(0); transition-delay: 0s; }
.notif-panel-header {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.notif-panel-title { font-weight: 600; font-size: 14px; color: var(--fg); }
.notif-mark-all {
  background: none; border: none; cursor: pointer;
  color: var(--accent); font-size: 11px; font-weight: 600;
  padding: 4px 8px; border-radius: 4px;
  transition: background var(--dur-fast) var(--ease-out);
}
.notif-mark-all:hover { background: var(--accent-tint); }

/* ============================================================
   TOPBAR (per-screen)
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  height: var(--topbar-h);
  padding: 0 22px;
  gap: 8px;
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.topbar-spacer { flex: 1; }

/* ============================================================
   MINI CALENDAR
   ============================================================ */
.mini { font-family: var(--font-body); }
.mini-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.mini-month {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 20px;
  letter-spacing: -0.005em;
  color: var(--fg);
}
.mini-nav { display: flex; gap: 4px; }
.mini-nav button {
  width: 24px; height: 24px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--dur-fast) var(--ease-out);
}
.mini-nav button:hover { background: var(--bg-elev-2); color: var(--fg); border-color: var(--border-strong); }
.mini-nav .lucide { width: 12px; height: 12px; }

.mini-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.mini-dow {
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-dim);
  padding: 4px 0;
}
.mini-day {
  font-size: 12px; color: var(--fg);
  padding: 5px 0;
  cursor: pointer;
  position: relative;
  border-radius: var(--radius-sm);
  transition: background var(--dur-fast) var(--ease-out);
}
.mini-day:hover { background: var(--bg-elev-2); }
.mini-day.muted { color: var(--fg-dim); }
.mini-day .pill-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
}
.mini-day.today .pill-num {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.mini-day.selected .pill-num {
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--accent-border);
}
.mini-day .has-evt::after {
  content: ""; position: absolute;
  bottom: 1px; left: 50%; transform: translateX(-50%);
  width: 3px; height: 3px; border-radius: 50%;
  background: var(--danger);
}

/* ── cal-day (JS-generated mini-calendar class names) ── */
.cal-day {
  font-size: 12px; color: var(--fg);
  padding: 5px 0;
  cursor: pointer;
  position: relative;
  border-radius: var(--radius-sm);
  transition: background var(--dur-fast) var(--ease-out);
  text-align: center;
  display: flex; align-items: center; justify-content: center;
}
.cal-day:hover { background: var(--bg-elev-2); }
.cal-day.today {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  border-radius: 50%;
}
.cal-day.selected {
  color: var(--accent);
  font-weight: 700;
  box-shadow: inset 0 0 0 1.5px var(--accent-border);
  border-radius: 50%;
}
.cal-day.today.selected {
  color: var(--accent-ink);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.4);
}
.cal-day.has-appt::after {
  content: "";
  position: absolute;
  bottom: 2px; left: 50%; transform: translateX(-50%);
  width: 3px; height: 3px; border-radius: 50%;
  background: var(--accent);
}
.cal-day.empty { visibility: hidden; pointer-events: none; }

/* ============================================================
   CONTENT SECTIONS (SPA routing)
   ============================================================ */
.crm-section { display: none; flex-direction: column; height: 100%; overflow-y: auto; padding: 24px 28px; gap: 20px; }
.crm-section.active { display: flex; }
#sec-timetable { padding: 0; gap: 0; overflow: hidden; }
#sec-timetable.active { display: flex; flex-direction: column; height: 100%; }

.sec-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-shrink: 0; }
.sec-title {
  font-family: var(--font-display);
  font-size: 26px; font-weight: 700;
  color: var(--fg); line-height: 1.15; letter-spacing: -0.015em;
}
.sec-subtitle { font-size: 13px; color: var(--fg-muted); margin-top: 4px; line-height: 1.5; }
.sec-header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; flex-wrap: wrap; }

.crm-section::-webkit-scrollbar { width: 5px; }
.crm-section::-webkit-scrollbar-track { background: transparent; }
.crm-section::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Back button */
.sec-back-btn {
  display: flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 6px 12px;
  color: var(--fg-muted); font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
  flex-shrink: 0; margin-right: 8px;
}
.sec-back-btn:hover { border-color: var(--accent-border); color: var(--accent); background: var(--accent-tint); }

/* Skip link */
.skip-link {
  position: absolute; top: -40px; left: 0;
  background: var(--accent); color: var(--accent-ink);
  padding: 6px 14px; font-size: 13px; font-weight: 600;
  border-radius: 0 0 var(--radius-md) 0;
  text-decoration: none;
  transition: top 0.2s;
  z-index: 9999;
}
.skip-link:focus { top: 0; }

/* Toast */
.toast-msg {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev-3); color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); padding: 12px 22px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none;
  transition: all var(--dur-base) var(--ease-out);
  z-index: 9999; white-space: nowrap;
}
.toast-msg.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast-msg.success { border-color: var(--success); color: var(--success); }
.toast-msg.error   { border-color: var(--danger);  color: var(--danger);  }
.toast-msg.warning { border-color: var(--warning); color: var(--warning); }

/* Segmented control (.seg) used in topbar */
.seg {
  display: inline-flex;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2px;
  gap: 2px;
}
.seg button {
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600;
  color: var(--fg-dim);
  background: transparent; border: none;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
}
.seg button:hover { color: var(--fg); }
.seg button.active {
  background: var(--accent);
  color: var(--accent-ink);
}

/* Date pill in topbar */
.date-pill {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--bg-elev-1); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 5px 12px;
  font-size: 13px; font-weight: 600; color: var(--fg);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
}
.date-pill:hover { border-color: var(--border-strong); }
.date-pill .lucide { width: 14px; height: 14px; color: var(--fg-muted); }

/* Zoom pill */
.zoom-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg-elev-1); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 5px 12px;
  font-size: 11px; font-weight: 600; color: var(--fg-muted);
}
.zoom-pill input[type=range] {
  width: 70px; height: 3px;
  -webkit-appearance: none; appearance: none;
  background: var(--bg-elev-3); border-radius: 2px;
  outline: none; cursor: pointer;
}
.zoom-pill input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px;
  border-radius: 50%; background: var(--accent); cursor: pointer;
}
