:root, [data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --border: #475569;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --accent: #14b8a6;
  --accent-hover: #0d9488;
  --accent-muted: rgba(20, 184, 166, 0.15);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
  --success: #22c55e;
  --urgent: #f97316;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Vazirmatn', Tahoma, system-ui, sans-serif;
  --org-card-bg: #ffffff;
  --org-card-text: #0f172a;
  --org-card-muted: #64748b;
  --header-bg: rgba(15, 23, 42, 0.92);
  --row-alt: rgba(30, 41, 59, 0.55);
  --row-hover: rgba(20, 184, 166, 0.1);
  --table-head-bg: #0d9488;
  --table-head-text: #ffffff;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --border: #d0d7e2;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --accent: #0f766e;
  --accent-hover: #115e59;
  --accent-muted: rgba(15, 118, 110, 0.12);
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --warning: #d97706;
  --success: #15803d;
  --urgent: #ea580c;
  --shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
  --org-card-bg: #ffffff;
  --org-card-text: #0f172a;
  --org-card-muted: #64748b;
  --header-bg: rgba(255, 255, 255, 0.95);
  --row-alt: #f1f5f9;
  --row-hover: rgba(15, 118, 110, 0.08);
  --table-head-bg: #0f766e;
  --table-head-text: #ffffff;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  max-width: 100%;
  overflow-x: hidden;
}

#app {
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: auto;
  overflow-x: hidden;
  max-width: 100%;
  width: 100%;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text-primary);
}

input, select, textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 0.625rem 0.875rem;
  width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

textarea { resize: vertical; min-height: 80px; }

select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 0.75rem center; padding-left: 2rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #0d9488);
  color: white;
  box-shadow: 0 2px 12px rgba(20, 184, 166, 0.35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(20, 184, 166, 0.45); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-ghost {
  color: var(--text-secondary);
  padding: 0.5rem 0.75rem;
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-input); border-radius: var(--radius-sm); }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.875rem; }

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Login */
.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(20, 184, 166, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(59, 130, 246, 0.08) 0%, transparent 40%),
    var(--bg-primary);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo h1 {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-logo p { color: var(--text-secondary); font-size: 0.9rem; margin-top: 0.25rem; }

.form-group { margin-bottom: 1.25rem; }
.form-group label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

/* Layout — sidebar shell (RTL: sidebar on the right) */
.app-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  max-width: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg-primary);
}

/* Modal host — full viewport, never zero-sized (breaks overlay paint) */
#modal-root {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
}
#modal-root:empty { display: none; }
#modal-root > * {
  pointer-events: auto;
}

.app-sidebar {
  grid-column: 1;
  grid-row: 1 / -1;
  display: flex;
  flex-direction: column;
  background: var(--bg-card, var(--header-bg));
  border-inline-end: 1px solid var(--border);
  padding: 1rem 0.75rem;
  gap: 0.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  z-index: 40;
}

.sidebar-brand {
  padding: 0.35rem 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.35rem;
}
.sidebar-brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.3;
}
.sidebar-brand-sub {
  font-size: 0.72rem;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  margin-top: 0.15rem;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.25rem 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.35);
  border-radius: 999px;
}
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }

.sidebar-group { display: flex; flex-direction: column; gap: 0.2rem; }
.sidebar-group-title {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0.35rem 0.7rem 0.45rem;
  text-transform: none;
  opacity: 0.9;
}

.sidebar-link {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: right;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: normal;
  line-height: 1.35;
  overflow: visible;
  word-break: keep-all;
}
.sidebar-link:hover { background: var(--bg-hover, rgba(255,255,255,0.06)); }
.sidebar-link.active {
  background: rgba(15, 118, 110, 0.18);
  color: var(--accent);
  font-weight: 600;
}
[data-theme='light'] .sidebar-link.active {
  background: rgba(15, 118, 110, 0.12);
}

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 0.65rem;
  margin-top: auto;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  padding: 0.45rem 0.55rem;
  border-radius: 10px;
  cursor: pointer;
  text-align: right;
}
.sidebar-user:hover { background: var(--bg-hover, rgba(255,255,255,0.06)); }
.sidebar-user .chip-avatar,
.sidebar-user img {
  width: 40px;
  height: 40px;
  max-width: 40px;
  max-height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.sidebar-user-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.sidebar-user-text strong {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-text small {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.app-topbar {
  grid-column: 2;
  grid-row: 1;
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.app-topbar #btn-nav-toggle { display: none; }
.app-topbar .topbar-end {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}
.app-topbar .header-search-wrap {
  width: min(340px, 42vw);
  flex: 0 1 340px;
  grid-column: auto;
  min-width: 0;
}
.app-topbar .header-utils {
  margin-inline-start: 0;
  flex-shrink: 0;
  grid-column: auto;
  justify-self: auto;
}

.nav-backdrop {
  display: none;
}

/* Mobile shell — flex column; sidebar always off-canvas until toggled */
@media (max-width: 960px) {
  .app-layout {
    display: flex !important;
    flex-direction: column;
    grid-template-columns: none !important;
    grid-template-rows: none !important;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
  }
  .app-sidebar {
    position: fixed !important;
    inset-block: 0 !important;
    inset-inline-end: 0 !important;
    inset-inline-start: auto !important;
    top: 0 !important;
    width: min(300px, 88vw) !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    grid-column: auto !important;
    grid-row: auto !important;
    transform: translate3d(110%, 0, 0) !important;
    transition: transform 0.22s ease, visibility 0.22s;
    box-shadow: none;
    border-inline-end: 1px solid var(--border);
    z-index: 50 !important;
    visibility: hidden;
    pointer-events: none;
    overflow: hidden;
  }
  html[dir='rtl'] .app-sidebar {
    transform: translate3d(110%, 0, 0) !important;
  }
  html[dir='ltr'] .app-sidebar {
    transform: translate3d(-110%, 0, 0) !important;
    inset-inline-end: auto !important;
    inset-inline-start: 0 !important;
  }
  body.sidebar-open .app-sidebar {
    transform: translate3d(0, 0, 0) !important;
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.45);
    visibility: visible;
    pointer-events: auto;
  }
  .app-topbar {
    grid-column: auto !important;
    grid-row: auto !important;
    position: sticky;
    top: 0;
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    flex-wrap: nowrap;
    gap: 0.45rem;
    padding: 0.5rem 0.65rem;
    padding-top: max(0.5rem, env(safe-area-inset-top));
    z-index: 30;
  }
  .app-topbar #btn-nav-toggle {
    display: inline-flex !important;
    flex-shrink: 0;
    order: -1;
  }
  .app-topbar .topbar-end {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: flex-end;
    gap: 0.4rem;
  }
  .app-topbar .header-search-wrap {
    width: auto;
    flex: 1 1 6rem;
    min-width: 0;
    max-width: none;
  }
  .app-topbar .header-utils {
    flex-shrink: 0;
  }
  .app-topbar .btn-logout {
    padding: 0.35rem 0.55rem;
    font-size: 0.8rem;
  }
  .app-main {
    grid-column: auto !important;
    grid-row: auto !important;
    flex: 1 1 auto;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    min-height: 0;
    padding: 0.75rem 0.85rem;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 45;
  }
  .nav-backdrop[hidden] { display: none !important; }
  body.sidebar-open { overflow: hidden; }
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(120px, 220px) 1fr auto;
  align-items: center;
  gap: 0.75rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  justify-self: start;
  min-width: 0;
  grid-column: 1;
}

.header-brand h1 {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--accent);
}

.header-search-wrap {
  grid-column: 2;
  position: relative;
  min-width: 0;
}

.header-search {
  width: 100%;
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated, var(--card-bg));
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
}

.global-search-results {
  position: absolute;
  top: calc(100% + 4px);
  inset-inline-start: 0;
  inset-inline-end: 0;
  min-width: 260px;
  max-height: 360px;
  overflow: auto;
  z-index: 200;
  background: var(--card-bg, var(--bg-elevated));
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  padding: 0.35rem;
}

.gs-section { padding: 0.25rem 0; }
.gs-title {
  font-size: 0.72rem;
  color: var(--text-secondary);
  padding: 0.25rem 0.5rem;
  font-weight: 600;
}
.gs-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  text-align: right;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}
.gs-item:hover { background: var(--bg-hover, rgba(255,255,255,0.06)); }
.gs-empty { padding: 0.75rem; font-size: 0.85rem; }

.header-actions {
  grid-column: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0;
}

.header-logout {
  grid-column: 4;
  justify-self: end;
}

.header-utils {
  grid-column: 4;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.nav-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.nav-group + .nav-group {
  padding-inline-start: 0.55rem;
  margin-inline-start: 0.15rem;
  border-inline-start: 1px solid var(--border);
}

.btn-notif { position: relative; }
.notif-badge {
  position: absolute;
  top: -4px;
  left: -4px;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: var(--danger, #ef4444);
  color: #fff;
  font-size: 0.65rem;
  line-height: 1.1rem;
  text-align: center;
  font-weight: 700;
}

.home-dashboard {
  max-width: 1120px;
  width: 100%;
  margin-inline: auto;
  align-self: center;
}
.home-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.home-hero h2 {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-primary);
}
.home-hero-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.home-kpis { margin-bottom: 1.25rem; }
.home-section { margin-bottom: 1.35rem; }
.home-section h3,
.home-panel h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}
.home-list-item strong {
  color: var(--text-primary);
}
.dash-actions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.65rem;
}
.dash-action {
  text-align: right;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 0.95rem;
  cursor: pointer;
  color: var(--text-primary);
  transition: border-color 0.15s, background 0.15s;
}
.dash-action:hover {
  border-color: var(--accent);
  background: var(--accent-muted);
}
.dash-action-title {
  display: block;
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: var(--text-primary);
}
.dash-action-desc {
  display: block;
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.4;
}
.home-panels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.home-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}
.home-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.home-panel-head h3 { margin: 0; }
.home-list { list-style: none; margin: 0; padding: 0; }
.home-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.2rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.home-list-item:last-child { border-bottom: 0; }
.home-list-item:hover { color: var(--accent); }
.settings-page {
  max-width: 1120px;
  width: 100%;
  margin-inline: auto;
  align-self: center;
}

@media (max-width: 900px) {
  .home-panels { grid-template-columns: 1fr; }
  .dash-actions { grid-template-columns: 1fr; }
  .home-hero {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
  .home-hero-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
  }
  .home-hero-actions .btn {
    width: 100%;
    justify-content: center;
    padding-inline: 0.4rem;
    font-size: 0.82rem;
  }
  .home-list-item {
    padding: 0.75rem 0;
    gap: 0.5rem;
  }
  .home-panel {
    padding: 0.85rem 0.9rem;
  }
}

.page-head { margin-bottom: 1rem; }
.page-head h2 { font-size: 1.25rem; font-weight: 700; margin: 0 0 0.25rem; }
.page-sub { color: var(--text-secondary); margin: 0; font-size: 0.875rem; }
.page-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.settings-page .settings-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.settings-card h3 {
  margin: 0 0 0.85rem;
  font-size: 1rem;
  font-weight: 600;
}
.settings-actions { margin-top: 1.25rem; }

/* Page-local sidebar shell — full-height under topbar */
.page-shell,
.settings-shell {
  display: grid;
  grid-template-columns: 212px minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: var(--bg-card);
  border-inline-start: 1px solid var(--border);
}
.page-shell-nav,
.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.85rem 0.65rem;
  border-inline-end: 1px solid var(--border);
  overflow: auto;
  min-height: 0;
  height: 100%;
  background: rgba(0, 0, 0, 0.14);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}
.settings-nav-head {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0.15rem 0.7rem 0.55rem;
}
[data-theme='light'] .page-shell-nav,
[data-theme='light'] .settings-nav {
  background: rgba(15, 23, 42, 0.03);
}
.page-shell-nav-item,
.settings-nav-item {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  text-align: right;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
}
.page-shell-nav-item:hover,
.settings-nav-item:hover {
  background: var(--bg-hover, rgba(255,255,255,0.06));
}
.page-shell-nav-item.active,
.settings-nav-item.active {
  background: rgba(15, 118, 110, 0.18);
  color: var(--accent);
  font-weight: 600;
}
.settings-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.settings-toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.9rem 1.15rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
}
.settings-toolbar h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 0.2rem;
}
.settings-toolbar .page-sub { margin: 0; }
#settings-msg:empty { display: none; }
#settings-msg {
  flex-shrink: 0;
  padding: 0.65rem 1.15rem 0;
}
.page-shell-panels,
.settings-panels {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 1rem 1.15rem 1.35rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.settings-panel { display: none; }
.settings-panel.active { display: block; }
.settings-panel h3 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 650;
}
.app-main.settings-page {
  padding: 0;
  overflow: hidden;
  min-height: 0;
  height: 100%;
}
@media (max-width: 800px) {
  .page-shell,
  .settings-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .page-shell-nav,
  .settings-nav {
    height: auto;
    border-inline-end: 0;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.3rem;
    overflow: auto;
    padding: 0.55rem;
  }
  .settings-nav-head { width: 100%; padding-bottom: 0.25rem; }
  .page-shell-nav-item,
  .settings-nav-item {
    width: auto;
    flex: 0 0 auto;
    font-size: 0.8rem;
    padding: 0.45rem 0.6rem;
  }
}

.cols-check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.35rem 0.75rem;
  max-height: 220px;
  overflow: auto;
}
.toolbar-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.toolbar-select {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.65rem;
}

.notif-list { display: flex; flex-direction: column; gap: 0.55rem; }
.notif-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.65rem;
  align-items: start;
  padding: 0.75rem 0.85rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.notif-item.unread { border-color: var(--accent); background: rgba(45, 212, 191, 0.06); }
.notif-title { font-weight: 600; margin-bottom: 0.2rem; }
.notif-text { font-size: 0.875rem; color: var(--text-secondary); }
.notif-ord { display: flex; flex-direction: column; gap: 0.15rem; }
.tr-done td { opacity: 0.65; }

.btn-logout {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
}
.btn-logout:hover { background: rgba(239, 68, 68, 0.22); }

.user-chip {
  cursor: pointer;
}
.chip-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.7rem;
  font-weight: 700;
}

.role-intro {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}
.role-hint {
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.85rem;
  font-size: 0.82rem;
  color: var(--text-primary);
}

.app-main {
  grid-column: 2;
  grid-row: 2;
  min-height: 0;
  min-width: 0;
  padding: 1rem;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

/* Re-assert mobile main sizing AFTER the desktop grid-column rule above */
@media (max-width: 960px) {
  .app-main {
    grid-column: auto !important;
    grid-row: auto !important;
    flex: 1 1 auto;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .kanban-board {
    grid-template-columns: repeat(5, minmax(140px, 1fr));
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

.page-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 40vh;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Stats bar */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.875rem 1rem;
  color: var(--text-primary);
}

.stat-card .label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}
.stat-card .value {
  font-size: 1.375rem;
  font-weight: 700;
  margin-top: 0.125rem;
  color: var(--text-primary);
}
.stat-card.urgent .value { color: var(--urgent); }
.stat-card.success .value { color: var(--success); }
.stat-card.accent .value { color: var(--accent); }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.toolbar .search-box {
  flex: 1 1 180px;
  min-width: 140px;
  max-width: 260px;
  position: relative;
}

.toolbar .toolbar-select,
.toolbar select.toolbar-select {
  width: auto;
  min-width: 8.25rem;
  max-width: 13rem;
  flex: 0 1 auto;
}

.toolbar .toolbar-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
  flex: 0 0 auto;
  margin-inline-start: auto;
}

@media (min-width: 901px) {
  .toolbar {
    flex-wrap: nowrap;
  }
  .toolbar .search-box {
    flex: 1 1 auto;
  }
  .toolbar .toolbar-select,
  .toolbar select.toolbar-select {
    flex: 0 0 auto;
  }
}

.search-box {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.search-box input { padding-right: 2.5rem; width: 100%; }
.search-box svg {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  width: 18px;
  height: 18px;
}

/* Toast notifications (non-blocking, compact) */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  z-index: 10050;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 0.4rem;
  width: auto;
  max-width: min(360px, calc(100vw - 1.5rem));
  pointer-events: none;
}
.toast-item {
  pointer-events: auto;
  width: fit-content;
  max-width: 100%;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  line-height: 1.35;
  white-space: pre-wrap;
  text-align: center;
  animation: toast-in 0.22s ease-out;
}
.toast-item.ok { border-color: rgba(34, 197, 94, 0.45); background: rgba(34, 197, 94, 0.14); }
.toast-item.error {
  border-radius: 12px;
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.12);
  text-align: right;
}
.toast-item.info { border-color: rgba(20, 184, 166, 0.45); background: rgba(20, 184, 166, 0.1); }
.toast-item.leaving { opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.msg-group-panel {
  margin-top: 0.65rem;
  padding: 0.75rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: rgba(148, 163, 184, 0.06);
}
.msg-group-panel h4 {
  margin: 0 0 0.45rem;
  font-size: 0.9rem;
}
.msg-group-panel .finance-muted { margin: 0.15rem 0; }
.msg-group-status {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8rem;
  margin-inline-end: 0.5rem;
}

/* Table */
.table-wrapper {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  min-width: 1200px;
}

.data-table th {
  position: sticky;
  top: 0;
  background: var(--table-head-bg);
  color: var(--table-head-text);
  font-weight: 600;
  padding: 0.75rem 0.625rem;
  text-align: right;
  white-space: nowrap;
  z-index: 2;
  border-left: 1px solid rgba(255,255,255,0.1);
}

.data-table td {
  padding: 0.625rem;
  border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border);
  vertical-align: middle;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
}
.data-table td .btn,
.data-table td button {
  max-width: none !important;
  overflow: visible !important;
  text-overflow: clip !important;
  white-space: nowrap !important;
  display: inline-flex;
  align-items: center;
}
.data-table td.actions-cell,
.data-table td:has(.btn) {
  max-width: none;
  overflow: visible;
  white-space: normal;
}

.data-table tbody tr { transition: background 0.15s; cursor: pointer; color: var(--text-primary); }
.data-table tbody tr:hover { background: var(--row-hover); }
.data-table tbody tr:nth-child(even) { background: var(--row-alt); }
.data-table tbody tr:nth-child(even):hover { background: var(--row-hover); }

.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-high { background: rgba(249, 115, 22, 0.2); color: #ea580c; }
.badge-normal { background: rgba(100, 116, 139, 0.18); color: var(--text-secondary); }
.badge-yes { background: rgba(34, 197, 94, 0.18); color: var(--success); }
.badge-no { background: rgba(239, 68, 68, 0.12); color: var(--danger); }
[data-theme="dark"] .badge-high { color: #fb923c; }
[data-theme="dark"] .badge-normal { color: #cbd5e1; }
[data-theme="dark"] .badge-yes { color: #4ade80; }
[data-theme="dark"] .badge-no { color: #f87171; }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem 0;
  flex-wrap: wrap;
}

.pagination span { color: var(--text-secondary); font-size: 0.875rem; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: fadeIn 0.2s;
}

.confirm-overlay {
  z-index: 12000;
  align-items: center;
  justify-content: center;
  background: rgba(2, 6, 23, 0.72);
}
.confirm-modal {
  max-width: 420px;
  width: min(420px, calc(100vw - 2rem));
  margin: auto;
  border: 1px solid var(--border);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}
.confirm-message {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
}
.btn-danger {
  background: var(--danger, #ef4444);
  color: #fff;
  border: none;
}
.btn-danger:hover {
  background: var(--danger-hover, #dc2626);
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 900px;
  max-height: calc(100dvh - 2rem);
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  animation: slideUp 0.25s ease-out;
  margin: auto;
  overflow: hidden;
  color: var(--text-primary);
}

/* Form that wraps body+footer must participate in flex scroll */
.modal > form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-secondary);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-secondary);
  z-index: 1;
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--text-primary);
}

.modal-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* Form sections */
.form-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.form-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.form-section-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.form-grid-full { grid-column: 1 / -1; }

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  cursor: pointer;
  padding: 0.375rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  user-select: none;
}

.checkbox-item:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-muted);
}

.checkbox-item input { width: auto; accent-color: var(--accent); }

.followup-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.followup-item label {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
  display: block;
}

/* Date picker overrides */
.rmdp-wrapper { direction: rtl; }
.rmdp-container { width: 100%; }
.rmdp-input {
  background: var(--bg-input) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius-sm) !important;
  padding: 0.625rem 0.875rem !important;
  width: 100% !important;
  font-family: var(--font) !important;
}
.rmdp-calendar { background: var(--bg-secondary) !important; border: 1px solid var(--border) !important; }
.rmdp-day rmdp-selected span { background: var(--accent) !important; }
.rmdp-time-picker { direction: ltr; }

.datetime-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: end;
}

.time-input {
  width: 100px !important;
  text-align: center;
  direction: ltr;
}

.loading-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.empty-state svg { width: 64px; height: 64px; margin-bottom: 1rem; opacity: 0.4; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .header-brand h1 { font-size: 1rem; }
  .btn span.hide-mobile { display: none; }
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .modal { max-height: calc(100dvh - 1rem); margin: 0.5rem; }
}

@media (display-mode: standalone) {
  .app-header { padding-top: max(0.75rem, env(safe-area-inset-top)); }
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-right: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 400;
}
.form-readonly {
  background: var(--bg-input);
  opacity: 0.85;
  cursor: not-allowed;
}
.form-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.tr-shared {
  background: rgba(59, 130, 246, 0.06);
}
.shared-badge {
  display: inline-block;
  font-size: 0.68rem;
  background: rgba(59, 130, 246, 0.18);
  color: #60a5fa;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  margin-left: 0.35rem;
  vertical-align: middle;
  white-space: nowrap;
}
.expert-slot-row {
  padding: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.expert-perms {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.5rem;
}
.graph-legend {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  align-items: center;
}
.graph-legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.graph-legend .lg {
  width: 12px; height: 12px; border-radius: 3px; display: inline-block;
}
.graph-legend .lg.primary { background: #38bdf8; }
.graph-legend .lg.shared { background: #94a3b8; }
.graph-legend .lg.multi { background: #fbbf24; }
.graph-svg-wrap {
  overflow: auto;
  background: linear-gradient(180deg, #0b1628, #0f1f36);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
}
.rel-graph { width: 100%; min-width: 640px; height: auto; display: block; }
.graph-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.graph-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.graph-expert-name { font-weight: 600; margin-bottom: 0.25rem; }
.graph-expert-stats { font-size: 0.75rem; color: var(--text-secondary); }
.graph-bar {
  height: 6px;
  background: rgba(148,163,184,0.2);
  border-radius: 99px;
  margin: 0.75rem 0;
  overflow: hidden;
}
.graph-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #0ea5e9, #38bdf8);
  border-radius: 99px;
}
.graph-customer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow: auto;
}
.graph-customer {
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  margin-bottom: 0.35rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
}
.graph-customer.is-primary { border-color: rgba(56, 189, 248, 0.45); }
.graph-customer.is-shared { border-color: rgba(148, 163, 184, 0.35); }
.gc-name { display: block; font-size: 0.875rem; }
.gc-meta { display: block; font-size: 0.72rem; color: var(--text-secondary); margin-top: 0.15rem; }
.graph-empty { color: var(--text-secondary); font-size: 0.85rem; padding: 0.5rem; }
.nav-active {
  background: var(--accent-muted) !important;
  border-color: transparent !important;
  color: var(--text-primary) !important;
  box-shadow: inset 0 -2px 0 var(--accent);
}
.actions-cell {
  white-space: nowrap !important;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 1rem;
}
.detail-row {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.detail-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.detail-value {
  font-size: 0.875rem;
  word-break: break-word;
}
.form-ok {
  background: rgba(34,197,94,0.12);
  border: 1px solid rgba(34,197,94,0.3);
  color: var(--success);
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}
@media (max-width: 640px) {
  .detail-grid { grid-template-columns: 1fr; }
}

.col-order-list { display: flex; flex-direction: column; gap: 0.5rem; }
.col-order-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
}
.col-order-btns { display: flex; flex-direction: column; gap: 0; }
.col-order-btns .btn { padding: 0.1rem 0.4rem; line-height: 1; min-height: auto; }

/* Avatar */
.avatar-field .avatar-row { display:flex; gap:1rem; align-items:center; }
.avatar-preview, img.avatar-preview {
  width:72px; height:72px; border-radius:50%; object-fit:cover;
  border:2px solid var(--border); background:var(--bg-input);
}
.avatar-preview.placeholder {
  display:flex; align-items:center; justify-content:center;
  font-size:0.7rem; color:var(--text-secondary); text-align:center; padding:0.25rem;
}
.avatar-sm {
  width:28px; height:28px; border-radius:50%; overflow:hidden; display:inline-flex;
  align-items:center; justify-content:center; background:#1e3a5f; flex-shrink:0;
}
.avatar-sm img { width:100%; height:100%; object-fit:cover; }
.avatar-sm span { font-size:0.75rem; color:#e2e8f0; }
.share-expert-list { display:flex; flex-direction:column; gap:0.5rem; margin-top:0.5rem; }
.share-expert-item {
  border:1px solid var(--border); border-radius:10px; padding:0.65rem 0.75rem; background:var(--bg-input);
}
.share-expert-item.selected { border-color:rgba(56,189,248,0.55); }
.share-expert-head { display:flex; align-items:center; gap:0.6rem; cursor:pointer; margin:0; }
.share-perms { margin-top:0.55rem; }

/* Org graph */
.graph-page { display:flex; flex-direction:column; min-height:calc(100vh - 72px); }
.org-graph-root {
  display:grid; grid-template-columns:1fr 300px; grid-template-rows:auto 1fr;
  gap:0.75rem; flex:1; min-height:560px;
}
.org-toolbar {
  grid-column:1 / -1; display:flex; flex-wrap:wrap; gap:0.5rem; align-items:center;
}
.org-search { max-width:260px; }
.org-filter { width:auto; min-width:140px; }
.org-hint { font-size:0.75rem; color:var(--text-secondary); margin-right:auto; }
.org-stage {
  position:relative; overflow:hidden; border:1px solid var(--border); border-radius:14px;
  background:
    radial-gradient(circle at 20% 10%, rgba(56,189,248,0.08), transparent 40%),
    linear-gradient(180deg, #0b1628 0%, #0f1f36 100%);
  cursor:grab; min-height:520px;
}
.org-stage:active { cursor:grabbing; }
.org-edges, .org-world {
  position:absolute; left:0; top:0; overflow:visible; pointer-events:none;
}
.org-world { pointer-events:none; }
.org-card {
  position:absolute; width:228px; height:78px; display:flex; align-items:center; gap:0.7rem;
  padding:0.55rem 0.75rem; background:var(--org-card-bg); color:var(--org-card-text); border-radius:14px;
  box-shadow:0 8px 24px rgba(0,0,0,0.18); border:1px solid #e2e8f0;
  pointer-events:auto; cursor:grab; user-select:none; transition:box-shadow .15s, border-color .15s;
}
.org-card:active { cursor:grabbing; }
.org-card.selected { border-color:#0ea5e9; box-shadow:0 0 0 3px rgba(14,165,233,0.25); }
.org-card.type-admin { border-color:#f59e0b; }
.org-card.type-manager { border-color:#a78bfa; }
.org-card.type-expert { border-color:#38bdf8; }
.org-card.type-customer.multi { border-color:#fbbf24; }
.org-avatar { position:relative; width:44px; height:44px; flex-shrink:0; }
.org-avatar.lg { width:56px; height:56px; }
.org-avatar-img, .org-avatar-fallback {
  width:100%; height:100%; border-radius:50%; object-fit:cover; display:flex;
  align-items:center; justify-content:center; font-weight:700; font-size:0.85rem;
}
.org-avatar-fallback.tone-admin { background:#fef3c7; color:#b45309; }
.org-avatar-fallback.tone-manager { background:#ede9fe; color:#6d28d9; }
.org-avatar-fallback.tone-expert { background:#e0f2fe; color:#0369a1; }
.org-avatar-fallback.tone-customer { background:#ecfdf5; color:#047857; }
.org-status {
  position:absolute; right:0; bottom:0; width:11px; height:11px; border-radius:50%;
  background:#22c55e; border:2px solid #fff;
}
.org-meta { min-width:0; }
.org-card .org-name {
  font-weight:700; font-size:0.9rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; color:var(--org-card-text);
}
.org-card .org-role { font-size:0.72rem; color:var(--org-card-muted); margin-top:0.1rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.org-side .org-name {
  font-weight:700; font-size:1rem; color:var(--text-primary) !important; white-space:normal;
}
.org-side .org-role { font-size:0.8rem; color:var(--text-secondary) !important; margin-top:0.15rem; }
.org-side {
  border:1px solid var(--border); border-radius:14px; background:var(--bg-card);
  padding:1rem; overflow:auto; min-height:520px; color:var(--text-primary);
}
.org-side-empty { color:var(--text-secondary); font-size:0.85rem; }
.org-side-card { display:flex; gap:0.75rem; align-items:center; margin-bottom:1rem; }
.org-side-title { font-weight:600; margin:1rem 0 0.5rem; font-size:0.875rem; color:var(--text-primary); }
.org-side-section { font-size:0.85rem; margin-bottom:0.4rem; color:var(--text-secondary); }
.org-rel-list { display:flex; flex-direction:column; gap:0.4rem; margin-bottom:1rem; }
.org-rel {
  display:flex; justify-content:space-between; gap:0.5rem; align-items:center;
  background:var(--bg-input); border:1px solid var(--border); border-radius:8px;
  padding:0.45rem 0.6rem; color:var(--text-primary); cursor:pointer; text-align:right;
}
.org-rel small { color:var(--text-secondary); }
@media (max-width: 960px) {
  .org-graph-root { grid-template-columns:1fr; }
  .org-side { min-height:220px; }
}

.chip-avatar {
  width: 22px;
  height: 22px;
  max-width: 40px;
  max-height: 40px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  flex-shrink: 0;
}
img.chip-avatar {
  display: inline-block;
}


.share-perm-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  margin-top: 0.65rem;
}
.perm-chip {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(148,163,184,0.12);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 0.45rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all .15s ease;
}
.perm-chip.on {
  background: rgba(14,165,233,0.18);
  border-color: rgba(56,189,248,0.55);
  color: #7dd3fc;
  font-weight: 600;
}
[data-theme="light"] .perm-chip.on {
  background: rgba(13,148,136,0.14);
  border-color: rgba(13,148,136,0.45);
  color: #0f766e;
}
.perm-chip:disabled { opacity: 0.55; cursor: not-allowed; }
.share-expert-name { font-weight: 600; }
.share-toggle-label { font-weight: 500; }
.org-card.type-customer.orphan { border-color: #f87171; }

.org-stage { touch-action: none; }
.org-viewport {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.org-edges, .org-world {
  position: absolute;
  left: 0; top: 0;
  overflow: visible;
  pointer-events: none;
}
.org-world { pointer-events: none; }
.org-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.org-line.org { stroke: #94a3b8; stroke-dasharray: none; opacity: 0.95; }
.org-line.primary { stroke: #38bdf8; opacity: 1; }
.org-line.shared { stroke: #7dd3fc; opacity: 0.85; }
.org-side-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.org-layouts { width:auto; min-width:180px; max-width:240px; }
[data-theme='light'] .org-stage {
  background:
    radial-gradient(circle at 20% 10%, rgba(14,165,233,0.08), transparent 40%),
    linear-gradient(180deg, #e2e8f0 0%, #f8fafc 100%);
}
[data-theme='light'] .login-page {
  background: linear-gradient(160deg, #e2e8f0, #f8fafc);
}

.btn-icon-nav {
  width: 36px; height: 36px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon-nav svg { width: 18px; height: 18px; display: block; }
.user-chip { color: var(--text-secondary); }
[data-theme='light'] .btn-secondary { background: #fff; }
[data-theme='light'] .btn-secondary:hover { background: #eef2f7; }
[data-theme='light'] .login-page {
  background:
    radial-gradient(ellipse at 20% 50%, rgba(15,118,110,0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(14,165,233,0.06) 0%, transparent 40%),
    var(--bg-primary);
}
[data-theme='light'] .org-stage {
  background:
    radial-gradient(circle at 20% 10%, rgba(14,165,233,0.08), transparent 40%),
    linear-gradient(180deg, #e8eef5 0%, #f8fafc 100%);
}
[data-theme='light'] .badge, [data-theme='light'] .urgency-badge {
  color: inherit;
}
.finance-share-row {
  display: grid;
  grid-template-columns: 1.4fr 0.7fr 1fr auto;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 0.5rem;
}
.finance-pay-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr auto;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 0.5rem;
}
.finance-muted { color: var(--text-secondary); font-size: 0.8rem; }
.amount-pos { color: var(--success); font-weight: 600; }
.amount-neg { color: var(--danger); font-weight: 600; }
.amount-warn { color: var(--warning); font-weight: 600; }

/* ===== Unified responsive layout ===== */
.header-menu-btn { display: none; }
.nav-backdrop:not([hidden]) {
  position: fixed; inset: 0; background: rgba(15,23,42,0.45); z-index: 90;
}
.modal-lg { max-width: 820px; width: calc(100% - 1.5rem); }
.stats-bar-compact { margin-bottom: 1rem; }
.table-scroll-sm { max-height: 240px; }
.finance-pay-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 0.75rem;
}
.finance-share-row {
  grid-template-columns: 1.3fr 1fr 0.7fr 0.9fr 0.8fr;
}
.fin-pay-actions { display:flex; flex-wrap:wrap; gap:0.25rem; }
.hide-mobile { display: inline; }
.data-table.finance-table { min-width: 980px; }

@media (max-width: 900px) {
  .header-menu-btn { display: inline-flex; }
  .header-inner {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.5rem;
  }
  .header-brand { min-width: 0; flex: 1; }
  .header-logout {
    grid-column: auto;
    justify-self: auto;
    margin-inline-start: 0;
    flex: 0 0 auto;
    order: 3;
  }
  .header-utils {
    grid-column: auto;
    justify-self: auto;
    flex: 0 0 auto;
    order: 3;
  }
  .header-brand { min-width: 0; flex: 1; }
  .header-brand h1 { font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .header-actions {
    display: none;
    grid-column: auto;
    position: fixed;
    top: 0; bottom: 0;
    right: 0;
    left: auto;
    width: min(300px, 86vw);
    z-index: 95;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 1rem 0.75rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0.45rem;
    overflow-y: auto;
  }
  .header-actions.open { display: flex; }
  .header-actions .btn { width: 100%; justify-content: flex-start; }
  .header-actions .btn-icon-nav { width: 100%; height: 40px; }
  body.nav-open { overflow: hidden; }
  .user-chip {
    display: inline-flex;
    overflow: hidden;
    max-width: 36px;
    font-size: 0;
    gap: 0;
    margin: 0;
  }
  .hide-mobile { display: none !important; }
  .app-main { padding: 0.75rem; }
  .stats-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
  .stat-card { padding: 0.7rem 0.75rem; }
  .stat-card .value { font-size: 1.1rem; }
  .toolbar { gap: 0.45rem; flex-wrap: wrap; }
  .toolbar .search-box { min-width: 0; width: 100%; max-width: none; flex: 1 1 100%; }
  .toolbar .toolbar-select,
  .toolbar select.toolbar-select {
    width: auto;
    flex: 1 1 calc(50% - 0.35rem);
    min-width: 140px;
    max-width: none;
  }
  .toolbar .toolbar-actions {
    width: 100%;
    margin-inline-start: 0;
  }
  .table-wrapper { border-radius: 10px; -webkit-overflow-scrolling: touch; }
  .data-table { font-size: 0.75rem; }
  .data-table th, .data-table td { padding: 0.5rem 0.4rem; }
  .pagination { flex-wrap: wrap; gap: 0.5rem; font-size: 0.8rem; }
  .modal { width: calc(100% - 0.75rem); margin: 0.4rem; max-height: calc(100dvh - 0.8rem); }
  .modal-lg { max-width: none; }
  .modal-body { padding: 0.85rem; }
  .finance-share-row {
    grid-template-columns: 1fr 1fr;
  }
  .finance-pay-row, .finance-pay-form {
    grid-template-columns: 1fr 1fr;
  }
  .org-graph-root {
    grid-template-columns: 1fr;
    min-height: 0;
  }
  .org-stage { min-height: 360px; }
  .org-side { min-height: 180px; max-height: 40vh; }
  .org-search { max-width: none; width: 100%; flex: 1 1 100%; }
  .org-hint { display: none; }
  .graph-page { min-height: calc(100dvh - 64px); }
  .avatar-field .avatar-row { flex-wrap: wrap; }
  .share-perm-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .stats-bar { grid-template-columns: 1fr; }
  .finance-share-row,
  .finance-pay-row,
  .finance-pay-form {
    grid-template-columns: 1fr;
  }
  .btn-sm { font-size: 0.8rem; }
  .header-brand h1 { max-width: 140px; }
  .action-btns { flex-wrap: wrap; }
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr !important; }
  .checkbox-group { grid-template-columns: 1fr; }
}

/* ── Customer service tag ───────────────────────────── */
.cust-service-tag {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 400;
  margin-right: 0.25rem;
}

/* ── DB management ──────────────────────────────────── */
.db-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-bottom: 1rem;
}
.db-section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.db-explorer {
  display: flex;
  align-items: stretch;
  gap: 0.75rem;
  min-height: 420px;
  flex: 1;
}
.db-sidebar {
  flex: 0 0 240px;
  width: 240px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  overflow-y: auto;
  max-height: calc(100dvh - 220px);
}
.db-table-item {
  display: flex !important;
  flex-direction: column;
  width: 100%;
  text-align: right;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  margin-bottom: 0.45rem;
  color: var(--text-primary);
  cursor: pointer;
}
.db-table-item:hover { background: var(--bg-input); }
.db-table-item.active {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.1);
}
.db-t-name { font-weight: 600; font-size: 0.9rem; }
.db-t-meta { font-size: 0.72rem; color: var(--text-secondary); }
.db-main {
  flex: 1;
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.db-empty {
  color: var(--text-secondary);
  text-align: center;
  padding: 3rem 1rem;
}
.db-browse-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}
.db-browse-head h3 { margin: 0; font-size: 1.05rem; }
.db-t-code { font-size: 0.75rem; color: var(--text-secondary); margin-right: 0.4rem; }
.db-count { font-size: 0.8rem; color: var(--text-secondary); margin-right: 0.5rem; }
.db-browse-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.db-browse-actions input { min-width: 180px; }
.db-table-wrap { flex: 1; }
.db-row-click { cursor: pointer; }
.db-row-click:hover { background: var(--row-hover, rgba(56, 189, 248, 0.08)); }
.db-null { color: var(--text-secondary); font-style: italic; font-size: 0.8rem; }
.db-file-window .modal-header h2 {
  display: flex; align-items: center; gap: 0.45rem;
  max-width: calc(100% - 3rem); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.db-file-icon { flex-shrink: 0; font-style: normal; }
.db-json {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  overflow: auto;
  max-height: 280px;
  font-size: 0.78rem;
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
  color: var(--text-primary);
}
.db-view-grid { display: grid; gap: 0.65rem; }
.db-view-k { font-size: 0.8rem; color: var(--accent); margin-bottom: 0.25rem; font-weight: 600; }
.db-view-k small { color: var(--text-secondary); font-weight: 400; }

@media (max-width: 900px) {
  .db-explorer { flex-direction: column; }
  .db-sidebar { width: 100%; flex-basis: auto; max-height: 220px; }
}

/* Phase 2 Wave A */
.docs-list { margin-top: 0.75rem; }
.docs-ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.docs-item {
  display: flex; justify-content: space-between; gap: 0.75rem; align-items: flex-start;
  padding: 0.65rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.docs-actions { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.team-notes-compose { display: flex; flex-direction: column; gap: 0.5rem; position: relative; margin-bottom: 0.75rem; }
.mention-suggest {
  position: absolute; bottom: 100%; inset-inline: 0; z-index: 20;
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 6px;
  max-height: 160px; overflow: auto;
}
.mention-item {
  display: block; width: 100%; text-align: right; border: 0; background: transparent;
  color: inherit; padding: 0.4rem 0.6rem; cursor: pointer; font-family: inherit;
}
.mention-item:hover { background: rgba(255,255,255,0.06); }
.note-mention {
  color: var(--accent, #0d9488);
  font-weight: 600;
  background: rgba(13, 148, 136, 0.12);
  padding: 0 0.2em;
  border-radius: 3px;
}
.team-notes-list { display: flex; flex-direction: column; gap: 0.55rem; max-height: 280px; overflow: auto; }
.team-note { padding: 0.55rem 0.65rem; border: 1px solid var(--border); border-radius: 6px; }
.team-note-meta { display: flex; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.25rem; font-size: 0.82rem; }
.team-note-text { white-space: pre-wrap; font-size: 0.9rem; }
.team-notes-chat { gap: 0.65rem; padding: 0.35rem 0.15rem; }
.team-notes-chat .team-note {
  max-width: 88%;
  border: none;
  border-radius: 14px 14px 4px 14px;
  background: color-mix(in srgb, var(--accent, #14b8a6) 14%, var(--card-bg, #1e293b));
  align-self: flex-start;
}
.team-notes-chat .team-note.mine {
  align-self: flex-end;
  border-radius: 14px 14px 14px 4px;
  background: color-mix(in srgb, var(--accent, #14b8a6) 28%, transparent);
}
.team-notes-chat .team-note-meta { margin-bottom: 0.15rem; opacity: 0.85; }
.team-notes-list.list-mode .team-note { max-width: none; align-self: stretch; border: 1px solid var(--border); border-radius: 6px; background: transparent; }
.team-notes-list.list-mode .team-note.mine { background: transparent; }
.customer-timeline { display: flex; flex-direction: column; gap: 0.65rem; max-height: 320px; overflow: auto; }
.timeline-item { display: flex; gap: 0.65rem; }
.timeline-dot {
  width: 10px; height: 10px; border-radius: 50%; margin-top: 0.35rem; flex-shrink: 0;
  background: var(--accent);
}
.timeline-note .timeline-dot { background: #38bdf8; }
.timeline-payment .timeline-dot { background: #34d399; }
.timeline-message .timeline-dot { background: #fbbf24; }
.timeline-meta { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.15rem; font-size: 0.8rem; }
.kanban-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(180px, 1fr));
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}
.kanban-col {
  background: var(--card-bg, rgba(255,255,255,0.03));
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 280px;
  display: flex; flex-direction: column;
}
.kanban-col-head {
  padding: 0.65rem 0.75rem; font-weight: 600; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.kanban-col-body { padding: 0.5rem; display: flex; flex-direction: column; gap: 0.45rem; flex: 1; min-height: 120px; }
.kanban-col-body.drag-over { outline: 2px dashed var(--accent); outline-offset: -4px; }
.kanban-card {
  padding: 0.55rem 0.65rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-elevated, rgba(0,0,0,0.15)); cursor: grab;
}
.kanban-card.dragging { opacity: 0.5; }
.kanban-card-actions { margin-top: 0.35rem; }
.kanban-empty { font-size: 0.8rem; text-align: center; padding: 1rem 0; }

/* Customer pipeline modal */
.pipe-modal .modal-body { max-height: min(78vh, 720px); overflow: auto; }
.pipe-summary { margin-bottom: 1rem; }
.pipe-progress {
  margin-top: 0.45rem; height: 8px; border-radius: 999px;
  background: rgba(148, 163, 184, 0.25); overflow: hidden;
}
.pipe-progress-fill {
  height: 100%; background: var(--accent, #0d9488); border-radius: 999px;
  transition: width 0.25s ease;
}
.pipe-stage-bar {
  display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 1.1rem;
}
.pipe-stage {
  flex: 1 1 5.5rem; min-width: 5rem; text-align: center;
  padding: 0.45rem 0.35rem; border: 1px solid var(--border); border-radius: 6px;
  font-size: 0.78rem;
}
.pipe-stage-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-secondary); margin-inline-end: 0.25rem; vertical-align: middle;
}
.pipe-stage-current { border-color: var(--accent, #0d9488); background: rgba(13, 148, 136, 0.08); }
.pipe-stage-current .pipe-stage-dot { background: var(--accent, #0d9488); }
.pipe-stage-done .pipe-stage-dot { background: #16a34a; }
.pipe-stage-label { vertical-align: middle; }
.pipe-section {
  margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border);
}
.pipe-section h3 {
  margin: 0 0 0.55rem; font-size: 0.95rem; display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap;
}
.pipe-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.pipe-item {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem;
  padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 6px;
}
.pipe-item-done { opacity: 0.85; }
.pipe-task {
  margin-bottom: 0.65rem; padding: 0.55rem; border: 1px solid var(--border); border-radius: 6px;
}
.pipe-task-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; margin-bottom: 0.35rem;
}
.pipe-steps { margin-top: 0.35rem; }

.task-steps-editor { display: flex; flex-direction: column; gap: 0.65rem; }
.task-step-row {
  padding: 0.65rem; border: 1px dashed var(--border); border-radius: 6px;
  background: rgba(148, 163, 184, 0.06);
}
.expert-level-row { border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.task-share-tree { margin-bottom: 0.85rem; padding: 0.55rem; border: 1px solid var(--border); border-radius: 6px; }
.share-preview { font-size: 0.85rem; }
.badge-urgent { background: rgba(239,68,68,0.2); color: #fca5a5; padding: 0.1rem 0.4rem; border-radius: 4px; font-size: 0.72rem; }
.report-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.65rem;
}
.report-filter-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}
.report-filter-field label {
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.report-filter-field input.datetime-picker {
  width: auto;
  min-width: 178px;
  max-width: 210px;
}
.org-card.drop-target {
  outline: 2px solid var(--accent);
  box-shadow: 0 0 0 4px rgba(45, 212, 191, 0.2);
}
.org-side-linkbox {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.org-side-linkbox select {
  width: 100%;
}
.org-unlink {
  border: 0;
  background: transparent;
  color: #f87171;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.78rem;
  padding: 0;
}
.org-line.soft {
  stroke-dasharray: 5 5;
  opacity: 0.55;
}

.funnel-row { display: grid; grid-template-columns: 140px 1fr auto; gap: 0.65rem; align-items: center; }
.funnel-label { font-size: 0.85rem; }
.funnel-track { height: 18px; background: rgba(255,255,255,0.06); border-radius: 999px; overflow: hidden; }
.funnel-fill { height: 100%; background: var(--accent); border-radius: 999px; min-width: 4px; }
.funnel-meta { font-size: 0.8rem; white-space: nowrap; }
.funnel-drop { color: #f87171; margin-inline-start: 0.35rem; }
.modal-sm { max-width: 480px; }
.nested-modal { z-index: 300; }
.checklist-svc { font-weight: 600; margin: 0.5rem 0 0.25rem; color: var(--accent); font-size: 0.85rem; }
.checklist-item .done { text-decoration: line-through; opacity: 0.65; }
.checklist-edit-row { display: flex; gap: 0.35rem; align-items: center; margin-bottom: 0.35rem; }
.checklist-edit-row input { flex: 1; }
.cashflow-bars { display: flex; flex-direction: column; gap: 0.55rem; margin-top: 0.5rem; }
.notif-item.notif-sla { border-inline-start: 3px solid #ef4444; background: rgba(239,68,68,0.08); }
.notif-item.notif-overdue { border-inline-start: 3px solid #f59e0b; background: rgba(245,158,11,0.08); }

@media (max-width: 960px) {
  .header-inner {
    grid-template-columns: 1fr auto;
  }
  .header-brand { grid-column: 1; }
  .header-utils { grid-column: 2; }
  .header-search-wrap { grid-column: 1 / -1; order: 3; }
  .header-actions { grid-column: 1 / -1; }
  .funnel-row { grid-template-columns: 1fr; }
  .kanban-board { grid-template-columns: repeat(5, minmax(160px, 1fr)); }
}

/* ===== Persian Datepicker — dark chic, side time, never clipped ===== */
body.pdp-open {
  overflow: hidden;
}
.datepicker-container {
  z-index: 300000 !important;
  font-family: var(--font) !important;
  position: fixed !important;
}
.datepicker-container.pwt-hide {
  display: none !important;
}
.datepicker-plot-area {
  position: relative !important;
  display: grid !important;
  grid-template-columns: 112px minmax(220px, 1fr) !important;
  grid-template-rows: auto 1fr auto !important;
  grid-template-areas:
    "time nav"
    "time days"
    "tools tools" !important;
  width: min(390px, calc(100vw - 16px)) !important;
  min-width: 300px !important;
  max-width: calc(100vw - 16px) !important;
  padding: 0.65rem !important;
  border: 1px solid var(--border) !important;
  border-radius: 14px !important;
  background: var(--bg-card) !important;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55) !important;
  overflow: visible !important;
  font-family: var(--font) !important;
  font-size: 0.88rem !important;
  color: var(--text-primary) !important;
  float: none !important;
}
.datepicker-plot-area * {
  font-family: var(--font) !important;
  color: var(--text-primary) !important;
  box-sizing: border-box;
}
.datepicker-plot-area .datepicker-navigator {
  grid-area: nav !important;
  width: 100% !important;
  float: none !important;
  margin: 0 0 0.35rem !important;
  display: flex !important;
  gap: 0.35rem;
}
.datepicker-plot-area .datepicker-navigator .pwt-btn-next,
.datepicker-plot-area .datepicker-navigator .pwt-btn-prev,
.datepicker-plot-area .datepicker-navigator .pwt-btn-switch {
  background: var(--bg-input) !important;
  color: var(--text-primary) !important;
  border-radius: 8px !important;
  height: 32px !important;
  line-height: 32px !important;
  font-weight: 600 !important;
  float: none !important;
  width: auto !important;
  margin: 0 !important;
  flex: 0 0 auto;
}
.datepicker-plot-area .datepicker-navigator .pwt-btn-switch {
  flex: 1 1 auto !important;
}
.datepicker-plot-area .datepicker-day-view,
.datepicker-plot-area .datepicker-month-view,
.datepicker-plot-area .datepicker-year-view {
  grid-area: days !important;
  width: 100% !important;
  float: none !important;
  min-height: 210px !important;
  margin: 0 !important;
}
.datepicker-plot-area .datepicker-day-view .month-grid-box .header .header-row-cell {
  color: var(--text-secondary) !important;
  font-weight: 600 !important;
  font-size: 0.72rem !important;
}
.datepicker-plot-area .datepicker-day-view .table-days td span,
.datepicker-plot-area .datepicker-year-view .year-item,
.datepicker-plot-area .datepicker-month-view .month-item {
  background: transparent !important;
  color: var(--text-primary) !important;
  border-radius: 8px !important;
  text-shadow: none !important;
  font-size: 0.86rem !important;
}
.datepicker-plot-area .datepicker-day-view .table-days td span.other-month {
  color: var(--text-secondary) !important;
  opacity: 0.45;
}
.datepicker-plot-area .datepicker-day-view .table-days td.disabled span,
.datepicker-plot-area .datepicker-year-view .year-item-disable,
.datepicker-plot-area .datepicker-month-view .month-item-disable {
  background: transparent !important;
  color: var(--text-secondary) !important;
  opacity: 0.35;
}
.datepicker-plot-area .datepicker-day-view .table-days td.today span {
  background: rgba(20, 184, 166, 0.16) !important;
  color: var(--accent) !important;
  font-weight: 700 !important;
}
.datepicker-plot-area .datepicker-day-view .table-days td.selected span,
.datepicker-plot-area .datepicker-year-view .year-item.selected,
.datepicker-plot-area .datepicker-month-view .month-item.selected {
  background: var(--accent) !important;
  color: #06241f !important;
  font-weight: 700 !important;
  text-shadow: none !important;
}
.datepicker-plot-area .datepicker-day-view .table-days td span:hover,
.datepicker-plot-area .datepicker-year-view .year-item:hover,
.datepicker-plot-area .datepicker-month-view .month-item:hover {
  background: rgba(20, 184, 166, 0.22) !important;
  color: var(--text-primary) !important;
}
.datepicker-plot-area .datepicker-time-view {
  grid-area: time !important;
  width: 100% !important;
  float: none !important;
  min-height: 0 !important;
  height: 100% !important;
  margin: 0 !important;
  padding: 0.45rem 0.35rem !important;
  background: rgba(0, 0, 0, 0.22) !important;
  border: 0 !important;
  border-radius: 10px !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
  align-items: stretch !important;
  gap: 0.45rem !important;
}
.datepicker-plot-area .datepicker-time-view > .time-segment {
  width: 100% !important;
  float: none !important;
  border-radius: 8px !important;
  background: var(--bg-input) !important;
  overflow: hidden;
  display: block !important;
}
.datepicker-plot-area .datepicker-time-view .divider {
  display: none !important;
}
.datepicker-plot-area .datepicker-time-view .up-btn,
.datepicker-plot-area .datepicker-time-view .down-btn {
  color: var(--text-secondary) !important;
  height: 26px !important;
  line-height: 26px !important;
  background: transparent !important;
  font-size: 0.85rem !important;
}
.datepicker-plot-area .datepicker-time-view .up-btn:hover,
.datepicker-plot-area .datepicker-time-view .down-btn:hover {
  color: var(--accent) !important;
  background: rgba(20, 184, 166, 0.12) !important;
}
.datepicker-plot-area .datepicker-time-view input {
  color: var(--text-primary) !important;
  font-weight: 700 !important;
  font-size: 1.15rem !important;
  height: 32px !important;
  text-align: center !important;
  width: 100% !important;
  margin: 0 !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  padding: 0 !important;
}
.datepicker-plot-area .toolbox {
  grid-area: tools !important;
  clear: none !important;
  width: 100% !important;
  float: none !important;
  display: flex !important;
  justify-content: flex-end !important;
  gap: 0.4rem;
  margin-top: 0.55rem !important;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
}
.datepicker-plot-area .toolbox .pwt-btn-submit,
.datepicker-plot-area .toolbox .pwt-btn-today,
.datepicker-plot-area .toolbox .pwt-btn-calendar {
  float: none !important;
  margin: 0 !important;
  min-width: 64px;
  height: 34px !important;
  line-height: 34px !important;
  border-radius: 8px !important;
  background: var(--bg-input) !important;
  color: var(--text-primary) !important;
  font-weight: 600 !important;
  font-size: 0.8rem !important;
}
.datepicker-plot-area .toolbox .pwt-btn-submit {
  background: var(--accent) !important;
  color: #06241f !important;
}
.datepicker-plot-area .toolbox .pwt-btn-submit:hover,
.datepicker-plot-area .toolbox .pwt-btn-today:hover {
  filter: brightness(1.08);
}
[data-theme="light"] .datepicker-plot-area {
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18) !important;
}
[data-theme="light"] .datepicker-plot-area .datepicker-time-view {
  background: rgba(15, 23, 42, 0.05) !important;
}
@media (max-width: 420px) {
  .datepicker-plot-area {
    grid-template-columns: 1fr !important;
    grid-template-areas:
      "nav"
      "days"
      "time"
      "tools" !important;
  }
  .datepicker-plot-area .datepicker-time-view {
    flex-direction: row !important;
    min-height: 0 !important;
    height: auto !important;
    padding: 0.45rem !important;
  }
  .datepicker-plot-area .datepicker-time-view > .time-segment {
    width: 48% !important;
  }
}

/* Users page tabs + form builder */
.users-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.65rem;
}
.users-tab {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.users-tab.active {
  background: var(--accent-muted);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.users-tab-count {
  opacity: 0.75;
  font-size: 0.78rem;
  margin-inline-start: 0.25rem;
}
.form-builder-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  background: var(--bg-card);
}
.form-builder-sec-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  color: var(--text-primary);
}
.form-builder-section .fb-sec-label {
  margin-bottom: 0.55rem;
}
.form-builder-fields {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.fb-field {
  display: grid;
  grid-template-columns: auto 1fr minmax(120px, 1fr);
  gap: 0.45rem;
  align-items: center;
  color: var(--text-primary);
}
.fb-custom-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.4rem;
  margin-bottom: 0.45rem;
  align-items: center;
}
@media (max-width: 700px) {
  .fb-field { grid-template-columns: auto 1fr; }
  .fb-field .fb-field-label { grid-column: 1 / -1; }
}

/* Expert levels */
.expert-level-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  margin-bottom: 0.65rem;
  background: var(--surface-2, rgba(148, 163, 184, 0.06));
}
.expert-level-row-main {
  margin: 0;
}
.el-icon-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.55rem;
}
.el-icon-pick {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface, transparent);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.el-icon-pick.active,
.el-icon-pick:hover {
  border-color: var(--accent, #0ea5e9);
  background: rgba(14, 165, 233, 0.12);
}
.expert-level-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  padding: 0.2rem 0.5rem;
  border-radius: 8px;
  background: rgba(14, 165, 233, 0.1);
  color: var(--text-primary);
  font-size: 0.85rem;
  max-width: 220px;
}
.expert-level-icon {
  font-size: 1.1rem;
  line-height: 1;
}
.expert-level-title {
  font-weight: 600;
}
.tr-urgent-lead td:first-child {
  box-shadow: inset 3px 0 0 var(--danger, #ef4444);
}

/* Process / Workflow Engine */
.proc-dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.65rem;
  margin-bottom: 1rem;
}
.proc-builder {
  display: grid;
  grid-template-columns: minmax(240px, 300px) 1fr;
  gap: 0.75rem;
  min-height: calc(100vh - 160px);
}
.proc-palette {
  background: var(--bg-card, var(--bg-secondary));
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
  padding: 0.75rem;
  overflow: auto;
  max-height: calc(100vh - 160px);
}
.proc-palette-title {
  font-weight: 600;
  margin: 0.75rem 0 0.4rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.proc-canvas-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
  background:
    radial-gradient(circle, rgba(148,163,184,0.18) 1px, transparent 1px);
  background-size: 18px 18px;
  background-color: var(--bg-primary);
  overflow: hidden;
  min-height: 520px;
  position: relative;
}
.proc-canvas {
  width: 100%;
  height: 100%;
  min-height: 520px;
  display: block;
}
.proc-node-selected rect {
  filter: drop-shadow(0 0 4px rgba(14, 165, 233, 0.45));
}
.proc-node-label {
  font-family: 'Vazirmatn', Tahoma, system-ui, sans-serif;
  direction: rtl;
  text-align: right;
  padding: 2px 4px 2px 0;
  pointer-events: none;
  line-height: 1.35;
  color: var(--text-primary, #f1f5f9);
}
.proc-node-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary, #f1f5f9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.proc-node-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary, #94a3b8);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.proc-edge-label {
  font-family: 'Vazirmatn', Tahoma, system-ui, sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary, #f1f5f9);
  text-align: center;
  line-height: 22px;
  pointer-events: none;
  direction: rtl;
}
.proc-props {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.proc-props-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.proc-timeline {
  max-height: 420px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.proc-tl-item {
  border-right: 3px solid var(--accent, #14b8a6);
  padding: 0.35rem 0.65rem;
  background: rgba(148, 163, 184, 0.08);
  border-radius: 6px;
}
.proc-tl-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.15rem;
}
.badge-warn {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning, #f59e0b);
}
@media (max-width: 900px) {
  .proc-builder {
    grid-template-columns: 1fr;
  }
  .proc-palette {
    max-height: none;
  }
  .proc-canvas-wrap {
    min-height: 420px;
  }
}

/* Phase 3 UX — customer search + money inputs */
.cs-combo { position: relative; }
.cs-combo .cs-query {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm, 8px);
  border: 1px solid var(--border, #475569);
  background: var(--bg-input, #334155);
  color: var(--text-primary, #f1f5f9);
}
.cs-drop {
  position: absolute;
  inset-inline: 0;
  top: calc(100% + 4px);
  z-index: 80;
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--border, #475569);
  border-radius: var(--radius-sm, 8px);
  background: var(--bg-card, #1e293b);
  box-shadow: 0 12px 32px rgba(0,0,0,.35);
}
.cs-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  width: 100%;
  text-align: right;
  padding: 0.65rem 0.85rem;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  border-bottom: 1px solid rgba(148,163,184,.15);
}
.cs-item:hover { background: var(--accent-muted, rgba(20,184,166,.15)); }
.cs-item span { font-size: 0.8rem; color: var(--text-secondary, #94a3b8); }
.cs-empty { padding: 0.85rem; color: var(--text-secondary, #94a3b8); font-size: 0.85rem; }
.cs-meta { margin-top: 0.35rem; font-size: 0.8rem; }
.money-input {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
/* Floating page loading — keep main content visible */
.app-loading-bar {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  z-index: 180;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: var(--bg-card, #1e293b);
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  color: var(--text-primary);
  font-size: 0.875rem;
  pointer-events: none;
}
.app-loading-bar[hidden] { display: none !important; }
.spinner-sm {
  width: 1rem;
  height: 1rem;
  border-width: 2px;
}
.page-loading-soft {
  min-height: 40vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  opacity: 0.9;
}
.inline-loading {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 1rem 0.25rem;
  color: var(--text-secondary);
}
.btn {
  white-space: nowrap;
  overflow: visible !important;
  text-overflow: clip;
  max-width: none;
  flex-shrink: 0;
}
.sidebar-link,
.settings-nav-item,
.page-shell-nav-item,
.dash-action,
.dash-action-title {
  overflow: visible !important;
  text-overflow: unset !important;
  white-space: normal !important;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.sidebar-user-text strong,
.sidebar-user-text small {
  overflow: visible;
  text-overflow: unset;
  white-space: normal;
}
.page-head-actions,
.page-head-row,
.toolbar,
.report-filters,
.report-tabs {
  flex-wrap: wrap;
  gap: 0.4rem;
}
.data-table td .btn,
.data-table td button,
td .btn,
td button {
  max-width: none !important;
  overflow: visible !important;
  text-overflow: clip !important;
  white-space: nowrap !important;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.data-table td.actions-cell,
.data-table td:has(.btn),
.data-table td:has(button) {
  max-width: none;
  overflow: visible;
  white-space: normal;
}
.proc-palette-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  margin-bottom: 0.35rem;
  cursor: grab;
  user-select: none;
  text-align: right;
  justify-content: flex-start;
  white-space: normal !important;
  overflow: visible !important;
}
.proc-palette-item:active { cursor: grabbing; }
.proc-palette-item.dragging { opacity: 0.55; }
.proc-canvas-wrap.drag-over {
  outline: 2px dashed var(--accent, #14b8a6);
  outline-offset: -4px;
}
.proc-connect-hint {
  position: absolute;
  top: 0.65rem;
  left: 0.65rem;
  z-index: 2;
  background: rgba(15,23,42,.88);
  color: #e2e8f0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.65rem;
  font-size: 0.78rem;
  pointer-events: none;
  max-width: min(420px, calc(100% - 1.5rem));
  white-space: normal;
}
.datepicker-plot-area,
.datepicker-container,
.pwt-datepicker-input-element + .datepicker-container {
  z-index: 10050 !important;
}
@media (max-width: 960px) {
  .app-layout { grid-template-columns: 1fr; }
  .proc-builder { grid-template-columns: 1fr; min-height: auto; }
  .proc-palette { max-height: none; }
  .page-head-actions .btn,
  .page-head-row .btn { white-space: normal; }
  .app-main { padding: 0.75rem; }
  .report-filters { width: 100%; }
  .report-filter-field { flex: 1 1 140px; }
  .data-table { min-width: 720px; }
  .proc-canvas-wrap, .proc-canvas { min-height: 360px; }
}
@media (max-width: 640px) {
  .app-topbar { padding-inline: 0.5rem; }
  .header-search { min-width: 0; width: 100%; }
  .page-head h2 { font-size: 1.05rem; }
  .stat-card .value { font-size: 1.25rem; }
  .proc-dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}