/* ── Teloring Design System — CSS Variables & Global Styles ── */

:root {
  /* Brand Colors */
  --color-coral: #E8523A;
  --color-coral-dark: #D4422C;
  --color-coral-light: #EF7A66;
  --color-coral-pale: #FDE8E4;

  --color-teal: #4BBFB0;
  --color-teal-dark: #2A9090;
  --color-teal-light: #74CFC4;
  --color-teal-pale: #E0F5F3;

  /* Neutrals */
  --color-dark: #0F1A1A;
  --color-dark-2: #1C2E2E;
  --color-text: #1a1a1a;
  --color-text-muted: #6B8080;
  --color-border: #E8EEEE;
  --color-bg: #F8F8F6;
  --color-white: #FFFFFF;

  /* Code & terminal surfaces — deliberately dark in BOTH themes.
     `--color-dark` is a *chrome* token: under [data-theme="dark"] it flips to a
     near-white tint so that dark-on-light chrome becomes light-on-dark. A code
     block that painted itself with --color-dark plus a hard-coded light text
     colour therefore turned white-on-white the moment an agent enabled dark
     mode. These tokens do not flip — a terminal reads as a terminal in either
     theme — so anything with light text on a dark ground must use them. */
  --color-code-bg: #0F1A1A;
  --color-code-text: #E6EFEF;
  --color-code-accent: #74CFC4;
  --color-code-border: rgba(75, 191, 176, 0.16);

  /* Status Colors */
  --color-success: #4BBFB0;
  --color-warning: #f5c842;
  --color-error: #E8523A;
  --color-info: #4BBFB0;

  /* Typography */
  --font-display: "Arial Black", "Arial Bold", Arial, sans-serif;
  --font-body: Arial, "Helvetica Neue", Helvetica, sans-serif;
  --font-mono: "Courier New", Courier, monospace;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-icon: 20px;
  --radius-pill: 999px;

  /* Shadows */
  --shadow-sm: 0 1px 4px rgba(15, 26, 26, 0.08);
  --shadow-md: 0 4px 16px rgba(15, 26, 26, 0.12);
  --shadow-lg: 0 8px 32px rgba(15, 26, 26, 0.16);

  /* Animation */
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.0, 0.0, 0.2, 1);

  /* Sidebar */
  --sidebar-width: 282px;
  --sidebar-collapsed-width: 72px;
  --header-height: 56px;

  /* Sidebar Colors — Cream & Teal (light mode default) */
  --sidebar-bg: #FBFAF6;
  --sidebar-bg-darker: #F0EFEB;
  --sidebar-border: rgba(15, 26, 26, 0.08);
  --sidebar-link-color: #3C4B4B;
  --sidebar-link-hover-bg: rgba(75, 191, 176, 0.12);
  --sidebar-link-hover-color: #1C2E2E;
  --sidebar-link-active-bg: rgba(75, 191, 176, 0.16);
  --sidebar-link-active-color: #0F1A1A;
  --sidebar-section-label: #6B8080;
  --sidebar-accent-line: #4BBFB0;

  /* Sidebar structural backgrounds */
  --sidebar-logo-bg: rgba(255, 255, 255, 0.72);
  --sidebar-footer-bg: rgba(255, 255, 255, 0.62);
  --sidebar-wordmark-color: var(--color-dark);
}

/* ── Dark Mode — Deep Ocean ── */
[data-theme="dark"] {
  --sidebar-bg: #0F1A1A;
  --sidebar-bg-darker: #0A1212;
  --sidebar-border: rgba(75, 191, 176, 0.15);
  --sidebar-link-color: #A3DED8;
  --sidebar-link-hover-bg: rgba(75, 191, 176, 0.15);
  --sidebar-link-hover-color: #E0F5F3;
  --sidebar-link-active-bg: rgba(232, 82, 58, 0.2);
  --sidebar-link-active-color: #EF7A66;
  --sidebar-section-label: #6B8080;
  --sidebar-accent-line: #E8523A;
  --sidebar-logo-bg: rgba(75, 191, 176, 0.08);
  --sidebar-footer-bg: rgba(75, 191, 176, 0.08);
  --sidebar-wordmark-color: #FFFFFF;

  /* Page-level dark overrides */
  --color-bg: #0F1A1A;
  --color-white: #1C2E2E;
  --color-text: #E0F5F3;
  --color-text-muted: #6B8080;
  --color-border: rgba(75, 191, 176, 0.12);
  --color-dark: #E0F5F3;
  /* Code surfaces stay dark, but the page ground is now dark too — sink them
     a step deeper and lift the border so the block still reads as a block. */
  --color-code-bg: #060E0E;
  --color-code-border: rgba(75, 191, 176, 0.24);
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .sidebar {
  background:
    radial-gradient(circle at 16% 8%, rgba(75, 191, 176, 0.18), transparent 30%),
    radial-gradient(circle at 92% 18%, rgba(232, 82, 58, 0.16), transparent 26%),
    linear-gradient(180deg, #0F1A1A 0%, #0A1212 100%);
  box-shadow: 10px 0 34px rgba(0, 0, 0, 0.28);
}

[data-theme="dark"] .sidebar-logo svg,
[data-theme="dark"] .sidebar-footer .sidebar-user-link {
  background: rgba(28, 46, 46, 0.78);
  border-color: rgba(75, 191, 176, 0.14);
}

[data-theme="dark"] .sidebar-nav a.active {
  background: linear-gradient(135deg, rgba(75, 191, 176, 0.12), rgba(232, 82, 58, 0.14));
  border-color: rgba(232, 82, 58, 0.22);
}

[data-theme="dark"] .sidebar-nav a:hover .nav-icon {
  background: rgba(75, 191, 176, 0.14);
}

[data-theme="dark"] .top-header {
  background: rgba(15, 26, 26, 0.82);
  border-bottom-color: rgba(75, 191, 176, 0.12);
}

/* ── RTL Support ── */
[dir="rtl"] {
  direction: rtl;
  text-align: right;
}

/* Directional-icon mirroring.
 *
 * Only icons that POINT somewhere may flip: chevrons, arrows, "reply", "send",
 * back/forward, progress carets. Icons that carry their own orientation must
 * NOT — a clock, a checkmark, a magnifier, a logo or a play button reads as
 * broken when mirrored, and a mirrored ✓ is a different glyph entirely. So this
 * is opt-in per icon rather than a blanket `[dir="rtl"] svg { … }`.
 *
 * Usage:  <svg class="rtl-flip" …>   or   <span class="rtl-flip">→</span>
 * `display:inline-block` is needed because `transform` does nothing on a
 * non-replaced inline element such as a bare <span>.
 */
[dir="rtl"] .rtl-flip {
  display: inline-block;
  transform: scaleX(-1);
}
/* An element already carrying a transform (rotating caret, animated spinner)
   would have it clobbered by the rule above, so give it its own hook. */
[dir="rtl"] .rtl-flip-none { transform: none; }

/* ── Reset & Base ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
}

a {
  color: var(--color-teal);
  text-decoration: none;
  transition: color 0.2s var(--ease-smooth);
}

a:hover {
  color: var(--color-teal-dark);
}

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 900;
  line-height: 1.3;
  color: var(--color-text);
}

h1 { font-size: 2rem; letter-spacing: -1px; }
h2 { font-size: 1.5rem; letter-spacing: -0.5px; }
h3 { font-size: 1.2rem; }

.label {
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: all 0.2s var(--ease-smooth);
  text-decoration: none;
  line-height: 1.4;
}

.btn-primary {
  background: var(--color-coral);
  color: var(--color-white);
}
.btn-primary:hover {
  background: var(--color-coral-dark);
  color: var(--color-white);
}

.btn-secondary {
  background: transparent;
  color: var(--color-teal);
  border: 2px solid var(--color-teal);
}
.btn-secondary:hover {
  background: var(--color-teal-pale);
  color: var(--color-teal-dark);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}
.btn-ghost:hover {
  background: var(--color-border);
  color: var(--color-text);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 1rem;
}

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

/* ── Inputs ── */
.input, .textarea, .select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--color-text);
  background: var(--color-white);
  transition: border-color 0.2s var(--ease-smooth), box-shadow 0.2s var(--ease-smooth);
}

.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--color-teal);
  box-shadow: 0 0 0 3px var(--color-teal-pale);
}

.input.error {
  border-color: var(--color-error);
  box-shadow: 0 0 0 3px var(--color-coral-pale);
}

.textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group {
  margin-bottom: var(--space-md);
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--space-xs);
}

.form-hint {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: var(--space-xs);
}

/* ── Cards ── */
.card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s var(--ease-smooth);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.badge-coral { background: var(--color-coral-pale); color: var(--color-coral-dark); }
.badge-teal { background: var(--color-teal-pale); color: var(--color-teal-dark); }
.badge-dark { background: var(--color-dark); color: var(--color-white); }

/* ── Code / Terminal Blocks ──
   The one place to paint a sample-code or JSON surface. Built on the
   --color-code-* tokens so it keeps its contrast in dark mode; never restate
   the background or the text colour at the call site. */
.code-block {
  margin: 0;
  padding: var(--space-md);
  background: var(--color-code-bg);
  color: var(--color-code-text);
  border: 1px solid var(--color-code-border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.6;
  overflow-x: auto;
  /* Sample code is always LTR even on a Hebrew page. */
  direction: ltr;
  text-align: left;
}
/* Teal-on-dark variant, for a webhook URL or a JSON payload. */
.code-block-accent { color: var(--color-code-accent); }
/* Wrap instead of scrolling — for a long single-line URL or embed snippet. */
.code-block-wrap { white-space: pre-wrap; word-break: break-word; }

/* ── Alerts / Flash Messages ── */
.alert {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  margin-bottom: var(--space-md);
}

.alert-success { background: var(--color-teal-pale); color: var(--color-teal-dark); border: 1px solid var(--color-teal-light); }
.alert-error { background: var(--color-coral-pale); color: var(--color-coral-dark); border: 1px solid var(--color-coral-light); }
.alert-info { background: var(--color-teal-pale); color: var(--color-teal-dark); border: 1px solid var(--color-teal); }

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

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background:
    radial-gradient(circle at 16% 8%, rgba(75, 191, 176, 0.16), transparent 28%),
    radial-gradient(circle at 92% 18%, rgba(232, 82, 58, 0.12), transparent 24%),
    linear-gradient(180deg, var(--sidebar-bg) 0%, #F5F4EF 100%);
  color: var(--color-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: width 0.3s var(--ease-smooth);
  overflow-y: auto;
  border-right: 1px solid var(--sidebar-border);
  box-shadow: 10px 0 34px rgba(15, 26, 26, 0.07);
  scrollbar-width: thin;
}

[dir="rtl"] .sidebar {
  left: auto;
  right: 0;
  border-right: none;
  border-left: 1px solid var(--sidebar-border);
}

/* ── Logo ── */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 16px;
  position: relative;
  min-height: 76px;
  background: var(--sidebar-logo-bg);
  border-bottom: 1px solid var(--sidebar-border);
  backdrop-filter: blur(16px);
}

.sidebar-logo::after {
  content: '';
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, var(--color-coral), var(--color-teal));
  border-radius: var(--radius-pill);
  opacity: 0.86;
}

[dir="rtl"] .sidebar-logo::after {
  background: linear-gradient(270deg, var(--color-coral), var(--color-teal));
}

.sidebar-logo svg {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  padding: 6px;
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 24px rgba(15, 26, 26, 0.1), inset 0 0 0 1px rgba(15, 26, 26, 0.06);
}

.sidebar-logo .wordmark {
  font-family: var(--font-display);
  font-size: 1.32rem;
  font-weight: 900;
  color: var(--sidebar-wordmark-color);
  letter-spacing: -0.7px;
  line-height: 1;
}

/* ── Nav ── */
.sidebar-nav {
  flex: 1;
  padding: 12px 12px 14px;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 14px;
  color: var(--sidebar-link-color);
  font-size: 0.86rem;
  font-weight: 650;
  transition: background 0.16s var(--ease-smooth), color 0.16s var(--ease-smooth), transform 0.16s var(--ease-smooth), box-shadow 0.16s var(--ease-smooth);
  margin-bottom: 3px;
  position: relative;
  text-decoration: none;
  border: 1px solid transparent;
}

[dir="rtl"] .sidebar-nav a {
  /* RTL handled by gap */
}

.sidebar-nav a .nav-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.9;
  border-radius: 12px;
  background: rgba(75, 191, 176, 0.09);
  box-shadow: inset 0 0 0 1px rgba(75, 191, 176, 0.08);
  transition: opacity 0.15s var(--ease-smooth), background 0.15s var(--ease-smooth), box-shadow 0.15s var(--ease-smooth), transform 0.15s var(--ease-smooth);
}

.sidebar-nav a .nav-icon svg {
  width: 18px;
  height: 18px;
  color: var(--color-coral);
}

.sidebar-nav a:hover {
  background: var(--sidebar-link-hover-bg);
  color: var(--sidebar-link-hover-color);
  border-color: rgba(75, 191, 176, 0.16);
  transform: translateX(2px);
}

[dir="rtl"] .sidebar-nav a:hover {
  transform: translateX(-2px);
}

.sidebar-nav a:hover .nav-icon {
  opacity: 1;
  background: rgba(255, 255, 255, 0.74);
  box-shadow: inset 0 0 0 1px rgba(75, 191, 176, 0.18);
}

.sidebar-nav a.active {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), var(--sidebar-link-active-bg));
  color: var(--sidebar-link-active-color);
  font-weight: 700;
  border-color: rgba(75, 191, 176, 0.24);
  box-shadow: 0 10px 24px rgba(15, 26, 26, 0.08);
}

.sidebar-nav a.active .nav-icon {
  opacity: 1;
  color: var(--sidebar-accent-line);
  background: linear-gradient(135deg, rgba(232, 82, 58, 0.14), rgba(75, 191, 176, 0.16));
  box-shadow: inset 0 0 0 1px rgba(75, 191, 176, 0.2);
}

/* Active indicator bar */
.sidebar-nav a.active::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 28px;
  background: linear-gradient(180deg, var(--color-coral), var(--color-teal));
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
}

[dir="rtl"] .sidebar-nav a.active::before {
  left: auto;
  right: 0;
  border-radius: 3px 0 0 3px;
}

.sidebar-nav a .nav-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Section Labels ── */
.sidebar-nav .section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--sidebar-section-label);
  padding: 22px 13px 8px;
  opacity: 0.78;
}

.sidebar-nav .section-label::after {
  content: '';
  height: 1px;
  flex: 1;
  background: linear-gradient(90deg, rgba(107, 128, 128, 0.24), transparent);
}

[dir="rtl"] .sidebar-nav .section-label::after {
  background: linear-gradient(270deg, rgba(107, 128, 128, 0.24), transparent);
}

.sidebar-nav .section-label:first-child {
  padding-top: 4px;
}

/* ── Sidebar Sub-menu (Conversations Open/Resolved) ── */
.nav-group .nav-submenu {
  display: none;
  margin: 3px 0 7px 28px;
  padding: 4px 0 4px 12px;
  border-left: 1px solid rgba(75, 191, 176, 0.22);
}
[dir="rtl"] .nav-group .nav-submenu {
  margin-left: 0;
  padding-left: 0;
  margin-right: 28px;
  padding-right: 12px;
  border-left: none;
  border-right: 1px solid rgba(75, 191, 176, 0.22);
}
.nav-group.open .nav-submenu {
  display: block;
}
.nav-sub-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  font-size: 0.79rem;
  font-weight: 620;
  color: var(--sidebar-link-color);
  text-decoration: none;
  border-radius: 12px;
  transition: all 0.15s var(--ease-smooth);
  margin-bottom: 1px;
}
.nav-sub-link .nav-sub-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  border-radius: 9px;
  background: rgba(232, 82, 58, 0.08);
  transition: opacity 0.15s var(--ease-smooth);
}
.nav-sub-link .nav-sub-icon svg {
  width: 14px;
  height: 14px;
  color: var(--color-coral);
}
.nav-sub-link:hover {
  background: var(--sidebar-link-hover-bg);
  color: var(--sidebar-link-hover-color);
}
.nav-sub-link:hover .nav-sub-icon {
  opacity: 0.8;
}
.nav-sub-link.active {
  color: var(--sidebar-accent-line);
  font-weight: 700;
  background: rgba(75, 191, 176, 0.12);
}
.nav-sub-link.active .nav-sub-icon {
  opacity: 1;
  color: var(--sidebar-accent-line);
}

/* ── Sidebar Queue Badges ── */
.nav-queue-link {
  position: relative;
}
.nav-queue-link.disabled {
  opacity: 0.4;
  pointer-events: none;
  cursor: not-allowed;
}
.nav-queue-badge {
  display: none;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--color-coral), var(--color-coral-dark));
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  flex-shrink: 0;
  margin-left: auto;
  box-shadow: 0 7px 14px rgba(232, 82, 58, 0.22);
}
[dir="rtl"] .nav-queue-badge {
  margin-left: 0;
  margin-right: auto;
}
.nav-queue-soon {
  font-size: 0.58rem;
  font-weight: 800;
  color: var(--color-teal-dark);
  opacity: 0.82;
  background: rgba(75, 191, 176, 0.11);
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
  margin-left: auto;
}
[dir="rtl"] .nav-queue-soon {
  margin-left: 0;
  margin-right: auto;
}

.sidebar.collapsed .nav-submenu {
  display: none !important;
}

/* ── Sidebar Dot Badge ("What has changed?" unread marker) ──
   A plain dot, no number: "there is something here you have not read yet".
   Anchored to the icon so it survives sidebar collapse, where labels vanish.
   Hidden via the [hidden] attribute; changelog_badge.js reveals it. */
.nav-icon-badged {
  position: relative;
}
.nav-dot-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--color-coral);
  border: 2px solid var(--sidebar-bg);
  box-shadow: 0 2px 6px rgba(232, 82, 58, 0.45);
  animation: nav-dot-pulse 2.2s var(--ease-smooth) infinite;
  pointer-events: none;
}
[dir="rtl"] .nav-dot-badge {
  right: auto;
  left: -2px;
}
.nav-dot-badge[hidden] {
  display: none;
}
@keyframes nav-dot-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.25); }
}
@media (prefers-reduced-motion: reduce) {
  .nav-dot-badge { animation: none; }
}

/* ── Sidebar Footer ── */
.sidebar-footer {
  padding: 14px 16px 16px;
  border-top: 1px solid var(--sidebar-border);
  background: var(--sidebar-footer-bg);
  backdrop-filter: blur(14px);
}

.sidebar-footer .sidebar-user-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 16px;
  transition: background 0.15s var(--ease-smooth), box-shadow 0.15s var(--ease-smooth), transform 0.15s var(--ease-smooth);
  text-decoration: none;
  color: inherit;
  border: 1px solid rgba(15, 26, 26, 0.06);
  background: rgba(255, 255, 255, 0.54);
}

.sidebar-footer .sidebar-user-link:hover {
  background: var(--sidebar-link-hover-bg);
  box-shadow: 0 10px 22px rgba(15, 26, 26, 0.08);
  transform: translateY(-1px);
}

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

[dir="rtl"] .main-content {
  margin-left: 0;
  margin-right: var(--sidebar-width);
}

/* ── Top Header ── */
.top-header {
  height: var(--header-height);
  background: rgba(255, 255, 255, 0.82);
  border-bottom: 1px solid rgba(15, 26, 26, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-lg);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(18px);
}

.top-header .page-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 900;
  color: var(--color-text);
}

.top-header .header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

/* ── Page Content ── */
.page-content {
  padding: var(--space-lg);
}

/* ── Table ── */
.table-wrapper {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  text-align: left;
  padding: var(--space-md);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
}

[dir="rtl"] .table th {
  text-align: right;
}

.table td {
  padding: var(--space-md);
  font-size: 0.9rem;
  border-bottom: 1px solid var(--color-border);
}

.table tr:last-child td {
  border-bottom: none;
}

.table tr:hover td {
  background: var(--color-bg);
}

/* ── Avatar ── */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-teal);
  color: var(--color-white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 900;
  flex-shrink: 0;
}

.avatar-sm { width: 28px; height: 28px; font-size: 0.65rem; }
.avatar-lg { width: 48px; height: 48px; font-size: 1rem; }

/* ── Status Indicators ── */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-online { background: var(--color-teal); }
.status-offline { background: var(--color-text-muted); }
.status-busy { background: var(--color-coral); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 26, 26, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s var(--ease-smooth), visibility 0.2s var(--ease-smooth);
}

.modal-overlay.active {
  display: flex;
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--color-white);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(10px);
  transition: transform 0.3s var(--ease-bounce);
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 900;
}

.modal-body {
  padding: var(--space-lg) var(--space-xl);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-xl);
  border-top: 1px solid var(--color-border);
}

.modal-wide {
  max-width: 640px;
  width: 95%;
}

.modal-wide .form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

.modal-wide .form-grid .form-group.full-width {
  grid-column: 1 / -1;
}

/* form-input alias — some templates use .form-input instead of .input */
.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--color-text);
  background: var(--color-white);
  transition: border-color 0.2s var(--ease-smooth), box-shadow 0.2s var(--ease-smooth);
}
.form-input:focus {
  outline: none;
  border-color: var(--color-teal);
  box-shadow: 0 0 0 3px var(--color-teal-pale);
}
textarea.form-input {
  resize: vertical;
  min-height: 80px;
}
select.form-input {
  cursor: pointer;
}

@media (max-width: 768px) {
  .modal-wide .form-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Utilities ── */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--color-text-muted); }
.text-coral { color: var(--color-coral); }
.text-teal { color: var(--color-teal); }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.7rem; }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* ── Loading Skeleton ── */
.skeleton {
  background: linear-gradient(90deg, var(--color-border) 25%, var(--color-bg) 50%, var(--color-border) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Sidebar Collapse Toggle Button ── */
.sidebar-collapse-btn {
  margin-left: auto;
  padding: 0 !important;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 0.7rem !important;
  line-height: 1;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.2s var(--ease-smooth);
  display: flex;
  align-items: center;
  justify-content: center;
}
[dir="rtl"] .sidebar-collapse-btn {
  margin-left: 0;
  margin-right: auto;
}
.sidebar-logo:hover .sidebar-collapse-btn,
.sidebar-collapse-btn:focus {
  opacity: 0.6;
}
.sidebar-collapse-btn:hover {
  opacity: 1;
  background: var(--sidebar-link-hover-bg);
}

/* ── Nav link icon/label structure ── */
.sidebar-nav a .nav-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sidebar-nav a .nav-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Main content transition ── */
.main-content {
  transition: margin 0.3s var(--ease-smooth);
}

/* ── Sidebar Collapsed State ── */
.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
  overflow: visible;
}
.sidebar.collapsed .sidebar-logo .wordmark {
  display: none;
}
.sidebar.collapsed .sidebar-logo {
  justify-content: center;
  padding: 16px 8px;
  position: relative;
}
/* Reposition the collapse button inside collapsed logo */
.sidebar.collapsed .sidebar-collapse-btn {
  margin-left: 0;
  position: absolute;
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  padding: 0 !important;
  border-radius: 50%;
  background: var(--color-white);
  border: 1px solid var(--sidebar-border);
  box-shadow: var(--shadow-sm);
  opacity: 0;
  pointer-events: auto;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
}
[dir="rtl"] .sidebar.collapsed .sidebar-collapse-btn {
  right: auto;
  left: -12px;
  margin-right: 0;
}
.sidebar.collapsed:hover .sidebar-collapse-btn {
  opacity: 1;
}
.sidebar.collapsed .sidebar-nav .section-label {
  display: none;
}
.sidebar.collapsed .sidebar-nav {
  overflow: visible;
  padding: 12px 8px;
}
.sidebar.collapsed .sidebar-nav a {
  justify-content: center;
  padding: 9px 0;
  position: relative;
  border-radius: 16px;
  margin-bottom: 5px;
}
.sidebar.collapsed .sidebar-nav a::before {
  display: none;
}
.sidebar.collapsed .sidebar-nav a .nav-label {
  display: none;
}
.sidebar.collapsed .sidebar-nav a .nav-icon {
  width: 38px;
  height: 38px;
  opacity: 0.84;
}
.sidebar.collapsed .sidebar-nav a.active .nav-icon {
  opacity: 1;
  color: var(--sidebar-accent-line);
}
/* ── Hover tooltip on collapsed nav links ── */
.sidebar.collapsed .sidebar-nav a::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  /* Not --color-dark: that token flips light in dark mode and the hard-coded
     white text below went white-on-white. A tooltip stays dark in both. */
  background: var(--color-code-bg);
  color: #fff;
  border: 1px solid var(--color-code-border);
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s var(--ease-smooth);
  z-index: 200;
  box-shadow: var(--shadow-md);
}
[dir="rtl"] .sidebar.collapsed .sidebar-nav a::after {
  left: auto;
  right: calc(100% + 10px);
}
.sidebar.collapsed .sidebar-nav a:hover::after {
  opacity: 1;
}
/* Footer in collapsed state */
.sidebar.collapsed .sidebar-footer {
  padding: 10px 8px 12px;
}
.sidebar.collapsed .sidebar-user-info {
  display: none;
}
.sidebar.collapsed .sidebar-user-link {
  justify-content: center;
}
/* Main content adjusts when sidebar is collapsed */
.main-content.sidebar-is-collapsed {
  margin-left: var(--sidebar-collapsed-width);
}
[dir="rtl"] .main-content.sidebar-is-collapsed {
  margin-left: 0;
  margin-right: var(--sidebar-collapsed-width);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 18px 0 42px rgba(15, 26, 26, 0.18);
  }
  [dir="rtl"] .sidebar {
    transform: translateX(100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}
