/* ============================================================
   Agency OS — Design System v2.0
   Matrix Green · Cairo · RTL · Dark Only
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700&display=swap');

/* ============================================================
   LAYER 1 — Primitive Tokens (raw values, internal use)
   ============================================================ */
:root {
  /* Green palette */
  --_g-glow:   rgba(0,176,40,0.18);
  --_g-ghost:  rgba(0,176,40,0.08);
  --_g-muted:  #002d09;
  --_g-dim:    #008a20;
  --_g-base:   #00B028;
  --_g-hover:  #00c72e;

  /* Surface palette */
  --_s-0:  #080d08;
  --_s-1:  #0d140d;
  --_s-2:  #121f12;
  --_s-3:  #172417;

  /* Border palette */
  --_b-0:  #1a2e1a;
  --_b-1:  #234523;

  /* Text palette */
  --_t-0:  #d4f0d4;
  --_t-1:  #6b9e6b;
  --_t-2:  #3d5c3d;

  /* Danger */
  --_danger:    #cc3333;
  --_danger-bg: #1a0a0a;

  /* Warning */
  --_warn:    #cc8800;
  --_warn-bg: #1a1200;

  /* Info */
  --_info: #2288aa;
}

/* ============================================================
   LAYER 2 — Semantic Tokens (use these everywhere)
   ============================================================ */
:root {
  /* — Backgrounds — */
  --color-bg:          var(--_s-0);
  --color-surface:     var(--_s-1);
  --color-card:        var(--_s-2);
  --color-card-hover:  var(--_s-3);

  /* — Borders — */
  --color-border:        var(--_b-0);
  --color-border-strong: var(--_b-1);

  /* — Accent — */
  --color-accent:        var(--_g-base);
  --color-accent-hover:  var(--_g-hover);
  --color-accent-dim:    var(--_g-dim);
  --color-accent-muted:  var(--_g-muted);
  --color-accent-ghost:  var(--_g-ghost);

  /* — Text — */
  --color-text-primary:   var(--_t-0);
  --color-text-secondary: var(--_t-1);
  --color-text-muted:     var(--_t-2);
  --color-text-on-accent: #000000;

  /* — Semantic states — */
  --color-danger:     var(--_danger);
  --color-danger-bg:  var(--_danger-bg);
  --color-warning:    var(--_warn);
  --color-warning-bg: var(--_warn-bg);
  --color-success:    var(--_g-base);
  --color-info:       var(--_info);

  /* — Spacing scale — */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  /* — Border radius — */
  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* — Typography — */
  --font:         'Cairo', sans-serif;
  --fs-xs:   11px;
  --fs-sm:   13px;
  --fs-base: 15px;
  --fs-lg:   18px;
  --fs-xl:   22px;
  --fs-2xl:  28px;
  --fs-3xl:  36px;

  /* — Transitions — */
  --t-fast: 0.12s ease;
  --t-base: 0.2s ease;

  /* — Shadows — */
  --shadow-glow:  0 0 16px var(--_g-glow);
  --shadow-card:  0 2px 12px rgba(0,0,0,0.4);
  --shadow-modal: 0 8px 40px rgba(0,0,0,0.65);

  /* — Z-index layers — */
  --z-topbar:  100;
  --z-sidebar: 200;
  --z-drawer:  300;
  --z-modal:   400;
  --z-toast:   500;
  --z-palette: 600;

  /* ── Backward-Compat Aliases (existing PHP pages) ───────── */
  --bg-main:      var(--_s-0);
  --bg-content:   var(--_s-1);
  --bg-card:      var(--_s-2);
  --bg-card-alt:  var(--_s-1);
  --bg-secondary: var(--_g-muted);
  --card-bg:      var(--_s-2);
  --secondary:    var(--_g-muted);
  --accent:       var(--_g-base);
  --accent-dim:   var(--_g-dim);
  --border:       var(--_b-0);
  --text:         var(--_t-0);
  --text-muted:   var(--_t-2);
  --danger:       var(--_danger);
  --warning:      var(--_warn);
  --info:         var(--_info);
}

/* ============================================================
   LAYER 3 — Reset & Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text-primary);
  font-family: var(--font);
  font-size: var(--fs-base);
  font-weight: 400;
  direction: rtl;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

img, video {
  max-width: 100%;
  display: block;
}

button, input, select, textarea {
  font-family: inherit;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 700;
  line-height: 1.3;
}

p { margin: 0 0 var(--sp-4); }

::selection {
  background: var(--color-accent);
  color: var(--color-text-on-accent);
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--color-bg); }
::-webkit-scrollbar-thumb {
  background: var(--color-accent-muted);
  border-radius: 8px;
  border: 2px solid var(--color-bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--color-accent-dim); }

/* ============================================================
   LAYER 4 — App Shell Layout
   ============================================================ */

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  width: 256px;
  flex-shrink: 0;
  background: var(--color-bg);
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  transition: width var(--t-base);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 20px 18px;
  font-size: 19px;
  font-weight: 700;
  color: var(--color-accent);
  border-bottom: 1px solid var(--color-border);
  letter-spacing: -0.3px;
}

.sidebar-logo .logo-icon {
  width: 32px;
  height: 32px;
  background: var(--color-accent-ghost);
  border: 1px solid var(--color-accent-dim);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  color: var(--color-accent);
}

.sidebar-nav {
  flex: 1;
  padding: var(--sp-3) var(--sp-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-section-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: var(--sp-3) var(--sp-3) var(--sp-2);
  margin-top: var(--sp-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-3);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-weight: 500;
  font-size: var(--fs-sm);
  transition: background var(--t-fast), color var(--t-fast);
  cursor: pointer;
  position: relative;
}

.nav-item i {
  width: 18px;
  text-align: center;
  font-size: 15px;
  flex-shrink: 0;
  color: var(--color-text-muted);
  transition: color var(--t-fast);
}

.nav-item:hover {
  background: var(--color-accent-ghost);
  color: var(--color-text-primary);
}

.nav-item:hover i { color: var(--color-accent); }

.nav-item.active {
  background: var(--color-accent-ghost);
  color: var(--color-accent);
  font-weight: 600;
}

.nav-item.active i { color: var(--color-accent); }

.nav-item.active::before {
  content: '';
  position: absolute;
  right: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  background: var(--color-accent);
  border-radius: 2px 0 0 2px;
}

.nav-item .nav-badge {
  margin-right: auto;
  background: var(--color-accent-muted);
  color: var(--color-accent);
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: var(--sp-4) var(--sp-4);
  border-top: 1px solid var(--color-border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--t-fast);
}

.sidebar-user:hover { background: var(--color-accent-ghost); }

.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--color-accent-muted);
  color: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  border: 1px solid var(--color-accent-dim);
}

.sidebar-user-info { flex: 1; min-width: 0; }

.sidebar-user-name {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  font-weight: 300;
}

/* ============================================================
   Main Content Area
   ============================================================ */
.main-content {
  flex: 1;
  background: var(--color-surface);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ============================================================
   Topbar
   ============================================================ */
.topbar {
  padding: var(--sp-4) var(--sp-6);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

.topbar-hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: var(--sp-2);
  min-height: 44px;
  min-width: 44px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.topbar-hamburger:hover {
  background: var(--color-accent-ghost);
  color: var(--color-accent);
}

.topbar-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--color-text-primary);
  flex: 1;
  min-width: 0;
}

.topbar-subtitle {
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  font-weight: 300;
  margin-top: 1px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-shrink: 0;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  flex: 1;
  min-width: 0;
}

.breadcrumb a:hover { color: var(--color-accent); }
.breadcrumb .current { color: var(--color-text-primary); font-weight: 600; }
.breadcrumb .sep { font-size: 10px; color: var(--color-text-muted); }

/* Page Content */
.page-content {
  padding: var(--sp-6) var(--sp-6) 80px;
  flex: 1;
}

/* ============================================================
   Page Header
   ============================================================ */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

.page-header h1, .page-header-title {
  font-size: var(--fs-xl);
  font-weight: 700;
  color: var(--color-text-primary);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.page-header h1 i { color: var(--color-accent); font-size: 20px; }

.page-subtitle {
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
  font-weight: 300;
  margin-top: var(--sp-1);
}

/* ============================================================
   Grid System
   ============================================================ */
.grid { display: grid; gap: var(--sp-5); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--sp-5);
  margin-bottom: var(--sp-5);
  transition: border-color var(--t-fast);
}

.card:hover { border-color: var(--color-border-strong); }

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-accent);
  margin: 0 0 var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: var(--sp-3);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--color-border);
}

/* ============================================================
   Stat Boxes
   ============================================================ */
.stat-box {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.stat-box:hover {
  border-color: var(--color-border-strong);
  box-shadow: var(--shadow-card);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--color-accent-ghost);
  color: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  border: 1px solid var(--color-accent-muted);
}

.stat-value {
  font-size: var(--fs-2xl);
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: 1.1;
}

.stat-label {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  font-weight: 300;
  margin-top: 2px;
}

.stat-delta {
  font-size: var(--fs-xs);
  font-weight: 600;
  margin-top: 2px;
}

.stat-delta.up { color: var(--color-success); }
.stat-delta.down { color: var(--color-danger); }

/* Big stat cards */
.big-stat-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--sp-6);
  text-align: center;
}

.big-stat-card .label {
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
  font-weight: 300;
  margin-bottom: var(--sp-2);
}

.big-stat-card .value {
  font-size: var(--fs-3xl);
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: 1;
}

.big-stat-card.income .value { color: var(--color-accent); }
.big-stat-card.expense .value { color: var(--color-danger); }

/* Entity card */
.entity-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  transition: border-color var(--t-fast), background var(--t-fast);
  cursor: pointer;
}

.entity-card:hover {
  border-color: var(--color-accent-dim);
  background: var(--color-card-hover);
}

.entity-card-title {
  font-weight: 600;
  color: var(--color-text-primary);
  font-size: 15px;
  margin-bottom: var(--sp-2);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--sp-2);
}

.entity-card-meta {
  color: var(--color-text-muted);
  font-size: var(--fs-xs);
  font-weight: 300;
  margin-bottom: var(--sp-3);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 9px var(--sp-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-card);
  color: var(--color-text-secondary);
  font-family: var(--font);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast);
  white-space: nowrap;
  text-decoration: none;
  min-height: 38px;
}

.btn:hover {
  background: var(--color-card-hover);
  color: var(--color-text-primary);
  border-color: var(--color-border-strong);
}

/* Primary */
.btn-primary {
  background: var(--color-accent);
  color: var(--color-text-on-accent);
  border-color: var(--color-accent);
  font-weight: 700;
}

.btn-primary:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
  box-shadow: var(--shadow-glow);
  color: var(--color-text-on-accent);
}

/* Secondary */
.btn-secondary {
  background: var(--color-accent-ghost);
  color: var(--color-accent);
  border-color: var(--color-accent-dim);
}

.btn-secondary:hover {
  background: var(--color-accent-muted);
  color: var(--color-accent);
  border-color: var(--color-accent);
}

/* Accent alias */
.btn-accent {
  background: var(--color-accent);
  color: var(--color-text-on-accent);
  border-color: var(--color-accent);
  font-weight: 700;
}

.btn-accent:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
  box-shadow: var(--shadow-glow);
  color: var(--color-text-on-accent);
}

/* Ghost */
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-text-secondary);
}

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

/* Danger */
.btn-danger {
  background: transparent;
  color: var(--color-danger);
  border-color: var(--color-danger);
}

.btn-danger:hover { background: var(--color-danger-bg); }

/* Sizes */
.btn-xs { padding: 4px 10px; font-size: var(--fs-xs); min-height: 28px; }
.btn-sm { padding: 6px var(--sp-3); font-size: var(--fs-xs); min-height: 32px; }
.btn-lg { padding: var(--sp-3) var(--sp-6); font-size: 15px; min-height: 46px; }

/* Icon button */
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--color-surface);
  border-color: var(--color-border);
  border-radius: var(--radius-sm);
}

.btn-icon:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--color-accent-ghost);
}

/* Disabled state */
.btn:disabled, .btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ============================================================
   Forms & Inputs
   ============================================================ */
.form-group { margin-bottom: var(--sp-4); }

.form-row {
  display: flex;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.form-row .form-group {
  flex: 1;
  min-width: 200px;
  margin-bottom: 0;
}

label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
}

label .req { color: var(--color-danger); margin-right: 2px; }

input[type=text],
input[type=email],
input[type=password],
input[type=number],
input[type=date],
input[type=tel],
input[type=month],
input[type=search],
input[type=url],
select,
textarea {
  width: 100%;
  padding: 10px var(--sp-3);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-primary);
  font-family: var(--font);
  font-size: var(--fs-base);
  font-weight: 400;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  appearance: none;
}

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

input::placeholder, textarea::placeholder {
  color: var(--color-text-muted);
  font-weight: 300;
}

textarea {
  resize: vertical;
  min-height: 90px;
  line-height: 1.6;
}

select { cursor: pointer; }

select option {
  background: var(--color-card);
  color: var(--color-text-primary);
}

.field-hint {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  font-weight: 300;
  margin-top: 5px;
}

.field-error {
  font-size: var(--fs-xs);
  color: var(--color-danger);
  margin-top: 5px;
  display: none;
}

.field-error.show { display: block; }

.checkbox-wrap {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.checkbox-wrap input[type=checkbox] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-accent);
  cursor: pointer;
  flex-shrink: 0;
}

.checkbox-wrap label {
  margin: 0;
  cursor: pointer;
  font-weight: 400;
  color: var(--color-text-primary);
}

fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  margin-bottom: var(--sp-5);
}

legend {
  color: var(--color-accent);
  font-weight: 700;
  font-size: var(--fs-sm);
  padding: 0 var(--sp-3);
}

.form-actions {
  display: flex;
  gap: var(--sp-3);
  margin-top: var(--sp-6);
  border-top: 1px solid var(--color-border);
  padding-top: var(--sp-5);
}

/* Search input */
.search-input-wrap {
  position: relative;
  flex: 1;
}

.search-input-wrap i {
  position: absolute;
  right: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  font-size: 14px;
  pointer-events: none;
}

.search-input-wrap input {
  padding-right: 36px;
}

/* Filter bar */
.filter-bar {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
  align-items: flex-end;
}

.filter-bar .form-group {
  margin-bottom: 0;
  min-width: 160px;
}

/* ============================================================
   Tables
   ============================================================ */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
  background: var(--color-card);
}

thead th {
  background: var(--color-surface);
  color: var(--color-text-secondary);
  text-align: right;
  padding: var(--sp-3) var(--sp-4);
  font-weight: 600;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  border-bottom: 1px solid var(--color-border);
}

thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--color-accent); }

tbody td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-primary);
  vertical-align: middle;
}

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

tbody tr:hover td { background: var(--color-card-hover); }

.actions-cell {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}

/* ============================================================
   Empty / Loading / Error States
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 64px var(--sp-5);
  color: var(--color-text-muted);
}

.empty-state .empty-icon {
  font-size: 40px;
  color: var(--color-accent-muted);
  margin-bottom: var(--sp-4);
  display: block;
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: var(--sp-2);
}

.empty-state p {
  font-size: var(--fs-sm);
  font-weight: 300;
  max-width: 320px;
  margin: 0 auto var(--sp-5);
}

/* لـ backward compat */
.empty-state i {
  font-size: 40px;
  color: var(--color-accent-muted);
  margin-bottom: var(--sp-4);
  display: block;
}

.loading-state {
  text-align: center;
  padding: 48px var(--sp-5);
  color: var(--color-text-muted);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto var(--sp-4);
}

@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg,
    var(--color-card) 25%,
    var(--color-card-hover) 50%,
    var(--color-card) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
}

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

/* ============================================================
   Badges
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge-green, .badge-success {
  background: rgba(0,176,40,0.12);
  color: var(--color-accent);
  border-color: var(--color-accent-dim);
}

.badge-red, .badge-danger {
  background: rgba(204,51,51,0.12);
  color: var(--color-danger);
  border-color: var(--color-danger);
}

.badge-yellow, .badge-warning {
  background: rgba(204,136,0,0.12);
  color: var(--color-warning);
  border-color: var(--color-warning);
}

.badge-blue, .badge-info {
  background: rgba(34,136,170,0.12);
  color: var(--color-info);
  border-color: var(--color-info);
}

.badge-gray, .badge-secondary, .badge-default {
  background: rgba(212,240,212,0.05);
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}

/* ============================================================
   Alerts
   ============================================================ */
.alert {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-sm);
  margin-bottom: var(--sp-5);
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  font-size: var(--fs-sm);
  font-weight: 400;
  border: 1px solid transparent;
}

.alert i { margin-top: 1px; flex-shrink: 0; }

.alert-success {
  background: var(--color-accent-ghost);
  border-color: var(--color-accent-dim);
  color: var(--color-accent);
}

.alert-error {
  background: var(--color-danger-bg);
  border-color: var(--color-danger);
  color: var(--color-danger);
}

.alert-warning {
  background: var(--color-warning-bg);
  border-color: var(--color-warning);
  color: var(--color-warning);
}

.alert-info {
  background: rgba(34,136,170,0.08);
  border-color: var(--color-info);
  color: var(--color-info);
}

/* ============================================================
   Tabs
   ============================================================ */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--sp-5);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab-link {
  padding: 10px var(--sp-4);
  color: var(--color-text-muted);
  font-weight: 500;
  font-size: var(--fs-sm);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color var(--t-fast), border-color var(--t-fast);
}

.tab-link:hover {
  color: var(--color-text-secondary);
  border-color: var(--color-border-strong);
}

.tab-link.active {
  color: var(--color-accent);
  border-color: var(--color-accent);
  font-weight: 600;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  z-index: var(--z-modal);
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  backdrop-filter: blur(2px);
}

.modal-overlay.open { display: flex; }

.modal-box, .modal {
  background: var(--color-card);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--sp-6);
  box-shadow: var(--shadow-modal);
  position: relative;
}

.modal-structured, .modal-box.modal-structured { padding: 0; }
.modal-structured .modal-header { padding: var(--sp-5) var(--sp-6) 0; }
.modal-structured .modal-body { padding: var(--sp-4) var(--sp-6); }

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

.modal-header h3, .modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text-primary);
  margin: 0;
}

.modal-close {
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 18px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--t-fast), color var(--t-fast);
  flex-shrink: 0;
}

.modal-close:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.modal-body { padding: var(--sp-5) var(--sp-6); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--color-border);
  margin-top: var(--sp-3);
}

/* ============================================================
   Context Drawer (Right panel)
   ============================================================ */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: var(--z-drawer);
  backdrop-filter: blur(1px);
}

.drawer-overlay.open { display: block; }

.drawer {
  position: fixed;
  top: 0;
  left: -480px;
  width: 480px;
  max-width: 95vw;
  height: 100vh;
  background: var(--color-card);
  border-right: 1px solid var(--color-border-strong);
  z-index: calc(var(--z-drawer) + 1);
  display: flex;
  flex-direction: column;
  transition: left var(--t-base);
  box-shadow: 4px 0 40px rgba(0,0,0,0.5);
}

.drawer.open { left: 0; }

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-5) var(--sp-5);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.drawer-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text-primary);
}

.drawer-close {
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 18px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  transition: background var(--t-fast), color var(--t-fast);
}

.drawer-close:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-5);
}

.drawer-footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: var(--sp-3);
  justify-content: flex-end;
  flex-shrink: 0;
}

/* ============================================================
   Command Palette (Ctrl+K)
   ============================================================ */
.palette-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: var(--z-palette);
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  backdrop-filter: blur(4px);
}

.palette-overlay.open { display: flex; }

.palette-box {
  background: var(--color-card);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  width: 580px;
  max-width: 95vw;
  box-shadow: var(--shadow-modal), 0 0 40px var(--_g-ghost);
  overflow: hidden;
}

.palette-input-wrap {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4);
  border-bottom: 1px solid var(--color-border);
}

.palette-input-wrap i {
  color: var(--color-accent);
  font-size: 16px;
  flex-shrink: 0;
}

.palette-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--color-text-primary);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 400;
  padding: 0;
}

.palette-input::placeholder {
  color: var(--color-text-muted);
  font-weight: 300;
}

.palette-results {
  max-height: 400px;
  overflow-y: auto;
  padding: var(--sp-2) 0;
}

.palette-section-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: var(--sp-2) var(--sp-4);
}

.palette-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-4);
  cursor: pointer;
  transition: background var(--t-fast);
  font-size: var(--fs-sm);
  color: var(--color-text-primary);
}

.palette-item i {
  width: 20px;
  text-align: center;
  color: var(--color-accent);
  flex-shrink: 0;
}

.palette-item.active, .palette-item:hover {
  background: var(--color-accent-ghost);
}

.palette-item .palette-shortcut {
  margin-right: auto;
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: monospace;
}

.palette-footer {
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: var(--sp-4);
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
}

.palette-footer kbd {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: monospace;
  font-size: 11px;
}

/* ============================================================
   Toast Notifications
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: var(--sp-6);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  align-items: center;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--color-card);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--color-text-primary);
  box-shadow: var(--shadow-modal);
  pointer-events: all;
  animation: toast-in 0.25s ease forwards;
  min-width: 260px;
  max-width: 440px;
}

.toast.hiding { animation: toast-out 0.2s ease forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(12px) scale(0.95); }
}

.toast-success { border-color: var(--color-accent-dim); }
.toast-success i { color: var(--color-accent); }

.toast-error { border-color: var(--color-danger); }
.toast-error i { color: var(--color-danger); }

.toast-warning { border-color: var(--color-warning); }
.toast-warning i { color: var(--color-warning); }

.toast-info { border-color: var(--color-info); }
.toast-info i { color: var(--color-info); }

/* ============================================================
   FAB — Floating Action Button
   ============================================================ */
.fab {
  position: fixed;
  bottom: var(--sp-6);
  left: var(--sp-6);
  z-index: calc(var(--z-sidebar) - 10);
  width: 52px;
  height: 52px;
  background: var(--color-accent);
  color: var(--color-text-on-accent);
  border: none;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow), var(--shadow-card);
  transition: background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}

.fab:hover {
  background: var(--color-accent-hover);
  transform: scale(1.08);
  box-shadow: 0 0 28px var(--_g-glow);
}

.fab:active { transform: scale(0.96); }

.fab-label {
  position: fixed;
  bottom: calc(var(--sp-6) + 58px);
  left: var(--sp-6);
  background: var(--color-card);
  color: var(--color-accent);
  font-size: var(--fs-xs);
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--color-accent-dim);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--t-fast);
}

.fab:hover + .fab-label, .fab:focus + .fab-label { opacity: 1; }

/* backward compat — desktop: visible via footer.php style */

/* ============================================================
   Progress Bar
   ============================================================ */
.progress-track {
  background: var(--color-surface);
  border-radius: 20px;
  height: 8px;
  overflow: hidden;
  border: 1px solid var(--color-border);
}

.progress-fill {
  background: var(--color-accent);
  height: 100%;
  border-radius: 20px;
  transition: width 0.4s ease;
}

.progress-fill.danger { background: var(--color-danger); }
.progress-fill.warning { background: var(--color-warning); }

/* ============================================================
   Kanban
   ============================================================ */
.kanban-board {
  display: flex;
  gap: var(--sp-4);
  overflow-x: auto;
  padding-bottom: var(--sp-4);
  align-items: flex-start;
  min-height: 300px;
  -webkit-overflow-scrolling: touch;
}

.kanban-col {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--sp-3);
  min-width: 240px;
  width: 240px;
  flex-shrink: 0;
}

.kanban-col-title {
  font-weight: 600;
  font-size: var(--fs-sm);
  color: var(--color-text-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-3);
  padding: 0 var(--sp-1);
}

.kanban-count {
  background: var(--color-accent-ghost);
  color: var(--color-accent);
  border-radius: 20px;
  font-size: var(--fs-xs);
  padding: 2px 8px;
  font-weight: 700;
}

.kanban-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--sp-3);
  margin-bottom: var(--sp-2);
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}

.kanban-card:hover {
  border-color: var(--color-accent-dim);
  background: var(--color-card-hover);
}

.kanban-card .name {
  font-weight: 600;
  color: var(--color-text-primary);
  display: block;
  margin-bottom: var(--sp-1);
  font-size: var(--fs-sm);
}

.kanban-card .meta {
  color: var(--color-text-muted);
  font-size: var(--fs-xs);
  font-weight: 300;
}

/* ============================================================
   Timeline
   ============================================================ */
.timeline-item {
  border-right: 2px solid var(--color-border);
  padding: 0 var(--sp-5) var(--sp-5);
  position: relative;
  margin-right: var(--sp-2);
}

.timeline-item::before {
  content: '';
  position: absolute;
  right: -7px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-card);
}

.timeline-date {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  font-weight: 300;
  margin-bottom: var(--sp-1);
}

.timeline-title {
  font-weight: 600;
  color: var(--color-text-primary);
  font-size: var(--fs-sm);
  margin-bottom: var(--sp-1);
}

.timeline-body {
  font-size: var(--fs-xs);
  color: var(--color-text-secondary);
  font-weight: 300;
}

/* ============================================================
   Profile / Client Header
   ============================================================ */
.profile-header {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}

.profile-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--color-accent-muted);
  color: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  flex-shrink: 0;
  border: 2px solid var(--color-accent-dim);
}

/* ============================================================
   Calc Box (Invoices / Finance)
   ============================================================ */
.calc-box {
  background: var(--color-surface);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-5);
}

.calc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--color-border);
  font-size: var(--fs-sm);
  color: var(--color-text-secondary);
}

.calc-row:last-child { border-bottom: none; }

.calc-row.total {
  font-weight: 700;
  color: var(--color-accent);
  font-size: 17px;
  padding-top: var(--sp-3);
}

/* ============================================================
   File Browser
   ============================================================ */
.file-browser {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: var(--sp-5);
}

.folder-tree a {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 9px var(--sp-3);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: var(--fs-sm);
  transition: background var(--t-fast), color var(--t-fast);
}

.folder-tree a i { color: var(--color-accent); }

.folder-tree a:hover,
.folder-tree a.active {
  background: var(--color-accent-ghost);
  color: var(--color-accent);
}

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: var(--sp-3);
}

.file-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-3);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--t-fast);
}

.file-card:hover { border-color: var(--color-accent-dim); }

.file-card i.file-icon {
  font-size: 32px;
  color: var(--color-accent);
  margin-bottom: var(--sp-2);
  display: block;
}

.file-card .file-name {
  font-size: var(--fs-xs);
  word-break: break-word;
  color: var(--color-text-primary);
  font-weight: 500;
}

.file-card .file-meta {
  font-size: 10px;
  color: var(--color-text-muted);
  margin-top: var(--sp-1);
  font-weight: 300;
}

/* ============================================================
   Calendar
   ============================================================ */
.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-4);
}

.calendar-header h2 {
  color: var(--color-text-primary);
  font-size: var(--fs-xl);
}

.calendar-daynames, .calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--sp-2);
}

.calendar-daynames {
  margin-bottom: var(--sp-2);
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--color-accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.calendar-day {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  min-height: 90px;
  padding: var(--sp-2);
  transition: border-color var(--t-fast);
}

.calendar-day:hover { border-color: var(--color-border-strong); }
.calendar-day.other-month { opacity: 0.3; }
.calendar-day.today {
  border-color: var(--color-accent);
  box-shadow: inset 0 0 0 1px var(--color-accent);
}

.calendar-day-num {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-bottom: var(--sp-1);
  font-weight: 600;
}

.event-pill {
  display: block;
  font-size: 10px;
  padding: 2px var(--sp-2);
  border-radius: 4px;
  margin-bottom: 2px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 700;
  border: none;
}

.event-pill.type-meeting         { background: #00B028; color: #000; }
.event-pill.type-deadline        { background: var(--color-danger); color: #fff; }
.event-pill.type-photo_shoot     { background: #cc8800; color: #000; }
.event-pill.type-content_publish { background: var(--color-info); color: #fff; }
.event-pill.type-reminder        { background: var(--color-card-hover); color: var(--color-text-primary); }
.event-pill.type-milestone       { background: #7b4fff; color: #fff; }
.event-pill.type-task            { background: var(--color-accent-dim); color: #000; }

/* ============================================================
   Notification Bell
   ============================================================ */
.notif-bell-wrap { position: relative; flex-shrink: 0; }

.notif-bell {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}

.notif-bell:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--color-accent-ghost);
}

.notif-badge {
  position: absolute;
  top: -4px;
  left: -4px;
  background: var(--color-accent);
  color: var(--color-text-on-accent);
  font-size: 10px;
  font-weight: 700;
  border-radius: 20px;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
  line-height: 1.4;
}

.notif-dropdown {
  display: none;
  position: absolute;
  top: 46px;
  left: 0;
  width: 320px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--color-card);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-modal);
  z-index: 50;
}

.notif-dropdown.open { display: block; }

.notif-dropdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--color-border);
  font-weight: 700;
  color: var(--color-text-primary);
  font-size: var(--fs-sm);
}

.notif-dropdown-header a {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--color-text-muted);
}

.notif-dropdown-header a:hover { color: var(--color-accent); }

.notif-empty {
  padding: var(--sp-6);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
}

.notif-item {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  font-size: var(--fs-xs);
  transition: background var(--t-fast);
  cursor: pointer;
}

.notif-item:hover { background: var(--color-card-hover); }
.notif-item:last-child { border-bottom: none; }
.notif-item i { color: var(--color-accent); margin-top: 2px; flex-shrink: 0; }
.notif-item.unread .notif-item-title { font-weight: 700; color: var(--color-text-primary); }
.notif-item-date { color: var(--color-text-muted); font-size: 10px; margin-top: 2px; font-weight: 300; }

/* ============================================================
   Dynamic List
   ============================================================ */
.dynamic-list-row {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  margin-bottom: var(--sp-2);
}

.dynamic-list-row input { flex: 1; }

/* ============================================================
   Quick Tabs (custom pill tabs)
   ============================================================ */
.quick-tabs {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-5);
  overflow-x: auto;
  scrollbar-width: none;
}

.quick-tabs::-webkit-scrollbar { display: none; }

.quick-tab-btn {
  padding: 6px var(--sp-4);
  border-radius: 20px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-family: var(--font);
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}

.quick-tab-btn.active {
  background: var(--color-accent);
  color: var(--color-text-on-accent);
  border-color: var(--color-accent);
}

.quick-tab-btn:not(.active):hover {
  background: var(--color-accent-ghost);
  color: var(--color-accent);
  border-color: var(--color-accent-dim);
}

/* ============================================================
   Quick Sale Tabs (modal)
   ============================================================ */
.quick-sale-tabs {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: var(--sp-3);
  overflow-x: auto;
  scrollbar-width: none;
}

.quick-sale-tabs::-webkit-scrollbar { display: none; }

.quick-sale-tab {
  flex-shrink: 0;
  padding: 7px var(--sp-4);
  white-space: nowrap;
  font-size: var(--fs-sm);
  background: var(--color-surface);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 500;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}

.quick-sale-tab.active {
  background: var(--color-accent);
  color: var(--color-text-on-accent);
  border-color: var(--color-accent);
  font-weight: 700;
}

/* ============================================================
   Contact Search Results
   ============================================================ */
.contact-search-results {
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  background: var(--color-card);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  max-height: 220px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: var(--shadow-modal);
}

.contact-search-result-item {
  padding: 10px var(--sp-4);
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  font-size: var(--fs-sm);
  color: var(--color-text-primary);
  transition: background var(--t-fast);
  min-height: 44px;
  display: flex;
  align-items: center;
}

.contact-search-result-item:hover { background: var(--color-accent-ghost); }
.contact-search-result-item:last-child { border-bottom: none; }

/* ============================================================
   Sort Items
   ============================================================ */
.sort-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-3);
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  margin-bottom: var(--sp-2);
  cursor: grab;
  transition: border-color var(--t-fast);
}

.sort-item:hover { border-color: var(--color-border-strong); }
.sort-item:active { cursor: grabbing; }

/* ============================================================
   Categories Layout
   ============================================================ */
.categories-layout {
  display: grid;
  grid-template-columns: 220px 220px 1fr;
  gap: 0;
}

.categories-col-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0;
  overflow-y: auto;
  max-height: calc(100vh - 160px);
}

.categories-col-card:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.categories-col-card:last-child  { border-radius: 0 var(--radius) var(--radius) 0; border-right: none; }

.categories-col-header {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  background: var(--color-surface);
}

.categories-col-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px var(--sp-4);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}

.categories-col-link:hover { background: var(--color-accent-ghost); color: var(--color-accent); }
.categories-col-link.active { background: var(--color-accent-ghost); color: var(--color-accent); font-weight: 600; }

/* ============================================================
   Permissions Layout
   ============================================================ */
.permissions-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: var(--sp-5);
}

.permissions-users-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow-y: auto;
  max-height: calc(100vh - 160px);
  position: sticky;
  top: 80px;
}

.permissions-users-header {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--color-border);
}

.permissions-user-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-4);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}

.permissions-user-link:hover { background: var(--color-accent-ghost); color: var(--color-accent); }
.permissions-user-link.active { background: var(--color-accent-ghost); color: var(--color-accent); font-weight: 600; }

.perm-module-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: var(--sp-3);
  overflow: hidden;
}

.perm-module-header {
  padding: var(--sp-3) var(--sp-4);
  font-weight: 600;
  font-size: var(--fs-sm);
  color: var(--color-text-primary);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.perm-item-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
  padding: var(--sp-4);
}

/* ============================================================
   Sidebar Overlay (mobile)
   ============================================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: calc(var(--z-sidebar) - 10);
  backdrop-filter: blur(2px);
}

/* ============================================================
   Bottom Nav (mobile)
   ============================================================ */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-card);
  border-top: 1px solid var(--color-border);
  z-index: 7000;
  height: 60px;
}

.bottom-nav-inner {
  display: flex;
  height: 100%;
  align-items: stretch;
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 10px;
  font-weight: 500;
  transition: color var(--t-fast);
  padding: 6px 0;
  border: none;
  background: none;
  cursor: pointer;
  min-height: 48px;
  font-family: var(--font);
}

.bottom-nav-item i { font-size: 18px; }
.bottom-nav-item.active, .bottom-nav-item:hover { color: var(--color-accent); }

/* Quick sale button in bottom nav */
.bottom-nav-quick {
  width: 64px !important;
  flex: none !important;
  flex-shrink: 0 !important;
  background: var(--color-accent) !important;
  color: var(--color-text-on-accent) !important;
  font-weight: 700;
  font-size: 9px;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 60px;
  touch-action: manipulation;
  font-family: var(--font);
}

.bottom-nav-quick i { font-size: 22px; }
.bottom-nav-quick:hover { background: var(--color-accent-hover) !important; }

/* PWA Install bar */
.pwa-install-bar {
  position: fixed;
  bottom: 60px;
  left: 0;
  right: 0;
  background: var(--color-accent);
  color: var(--color-text-on-accent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px var(--sp-4);
  z-index: 6900;
  font-size: var(--fs-sm);
  font-weight: 600;
}

.pwa-install-bar button {
  background: #000;
  color: var(--color-accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px var(--sp-4);
  font-size: var(--fs-sm);
  cursor: pointer;
  font-weight: 700;
  font-family: var(--font);
}

/* ============================================================
   Utility Classes
   ============================================================ */
.text-primary   { color: var(--color-text-primary) !important; }
.text-secondary { color: var(--color-text-secondary) !important; }
.text-muted     { color: var(--color-text-muted) !important; }
.text-accent    { color: var(--color-accent) !important; }
.text-danger    { color: var(--color-danger) !important; }
.text-warning   { color: var(--color-warning) !important; }
.text-center    { text-align: center !important; }
.text-start     { text-align: right !important; }

.fw-300 { font-weight: 300; }
.fw-400 { font-weight: 400; }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

.fs-xs   { font-size: var(--fs-xs); }
.fs-sm   { font-size: var(--fs-sm); }
.fs-base { font-size: var(--fs-base); }
.fs-lg   { font-size: var(--fs-lg); }

.d-none { display: none !important; }
.d-flex { display: flex !important; }
.d-block { display: block !important; }

.flex { display: flex; }
.flex-gap { display: flex; gap: var(--sp-3); align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-wrap { flex-wrap: wrap; }
.flex-col { flex-direction: column; }
.gap-1 { gap: var(--sp-1); }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }

.w-full { width: 100%; }
.min-w-0 { min-width: 0; }
.flex-1 { flex: 1; }

.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-5 { margin-bottom: var(--sp-5); }
.mb-6 { margin-bottom: var(--sp-6); }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); }

.p-0 { padding: 0 !important; }

.rounded { border-radius: var(--radius); }
.rounded-sm { border-radius: var(--radius-sm); }
.rounded-full { border-radius: 9999px; }

.border-top { border-top: 1px solid var(--color-border); }
.border-bottom { border-bottom: 1px solid var(--color-border); }

.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.actions-cell { display: flex; gap: var(--sp-2); align-items: center; }

/* ============================================================
   MOBILE — max-width: 768px
   ============================================================ */
@media (max-width: 768px) {
  /* Show bottom nav */
  .bottom-nav { display: block; }

  /* Content padding for bottom nav */
  .page-content { padding-bottom: 80px !important; }

  /* Sidebar becomes drawer */
  .sidebar {
    position: fixed;
    top: 0;
    right: -260px;
    height: 100%;
    width: 260px;
    z-index: var(--z-sidebar);
    transition: right var(--t-base);
    overflow-y: auto;
    display: flex;
  }

  .sidebar.open { right: 0; }
  .sidebar-overlay.open { display: block; }

  /* Hide all FAB variants on mobile — replaced by bottom-nav-quick */
  .fab,
  .fab-label,
  .global-quick-btn,
  .quick-sale-fab { display: none !important; }

  /* Full width main area */
  .main-content { margin-right: 0 !important; width: 100% !important; }

  /* Topbar */
  .topbar { padding: 10px var(--sp-4); }
  .topbar-hamburger { display: flex; }

  /* Grids → single column */
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr !important; }

  /* Form rows stack */
  .form-row { flex-direction: column; gap: 0; }
  .form-row .form-group { min-width: 100%; }

  /* Tables scroll */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 560px; }

  /* Page header */
  .page-header { flex-direction: column; align-items: flex-start; gap: var(--sp-3); }
  .page-header h1 { font-size: var(--fs-lg) !important; }

  /* Button touch targets */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; }
  .btn-icon { min-height: 44px; min-width: 44px; }

  /* Modals → bottom sheets */
  .modal-overlay { align-items: flex-end !important; padding: 0 !important; }
  .modal-box, .modal {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 92vh !important;
    min-height: 50vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0 !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: var(--sp-5) var(--sp-4) 80px !important;
    margin: 0 !important;
  }

  .modal-box::before, .modal::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--color-border-strong);
    border-radius: 2px;
    margin: 0 auto var(--sp-4);
  }

  /* Drawer full width on mobile */
  .drawer {
    left: -100%;
    width: 100%;
    max-width: 100%;
    top: auto;
    bottom: -100%;
    height: 90vh;
    left: 0;
    top: auto;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-right: none;
    border-top: 1px solid var(--color-border-strong);
    transition: bottom var(--t-base);
  }

  .drawer { top: auto; left: 0; bottom: -100%; right: 0; }
  .drawer.open { bottom: 0; }

  /* Inputs prevent iOS zoom */
  input, select, textarea { font-size: 16px !important; min-height: 44px; }

  /* Stat boxes full width */
  .stat-box { width: 100% !important; }

  /* File browser stacks */
  .file-browser { grid-template-columns: 1fr; }

  /* Calendar scrolls */
  .calendar-daynames, .calendar-grid {
    grid-template-columns: repeat(7, minmax(50px, 1fr));
    overflow-x: auto;
  }

  /* Categories mobile */
  .categories-layout { grid-template-columns: 1fr !important; gap: 0 !important; }

  .categories-col-card {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    max-height: none !important;
    width: 100% !important;
    border-radius: 0 !important;
    padding: var(--sp-2) !important;
    gap: var(--sp-2) !important;
    scrollbar-width: none;
  }

  .categories-col-card::-webkit-scrollbar { display: none; }
  .categories-col-header { display: none !important; }

  .categories-col-link {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    border-radius: 20px !important;
    padding: var(--sp-2) var(--sp-3) !important;
    font-size: var(--fs-xs) !important;
    display: inline-flex !important;
    border-bottom: none !important;
  }

  /* Permissions mobile */
  .permissions-layout { grid-template-columns: 1fr !important; }

  .permissions-users-card {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    max-height: none !important;
    position: static !important;
    padding: var(--sp-2) var(--sp-3) !important;
    gap: var(--sp-2) !important;
    scrollbar-width: none;
  }

  .permissions-users-card::-webkit-scrollbar { display: none; }
  .permissions-users-header { display: none !important; }

  .permissions-user-link {
    flex-shrink: 0 !important;
    border-radius: 20px !important;
    padding: var(--sp-2) var(--sp-3) !important;
    white-space: nowrap !important;
    border-bottom: none !important;
    flex-direction: row !important;
    gap: var(--sp-2) !important;
  }

  .perm-item-grid { grid-template-columns: 1fr !important; }

  .sort-item { min-height: 52px !important; }

  /* Modal inputs */
  .modal-box input, .modal input,
  .modal-box select, .modal select,
  .modal-box textarea, .modal textarea {
    height: 50px !important;
    font-size: 16px !important;
    padding: var(--sp-3) var(--sp-4) !important;
    border-radius: var(--radius-sm) !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .modal-box textarea, .modal textarea { height: 80px !important; }

  .modal-footer {
    position: sticky;
    bottom: 0;
    background: var(--color-card);
    padding: var(--sp-3) 0 4px;
    margin-top: var(--sp-4);
    border-top: 1px solid var(--color-border);
  }

  /* Contact search */
  .contact-search-results {
    position: relative !important;
    max-height: 200px;
    margin-top: var(--sp-1);
  }

  /* Tabs scrollable */
  .tabs { flex-wrap: nowrap; white-space: nowrap; }
  .tab-link { white-space: nowrap; flex-shrink: 0; }

  /* Breadcrumb compact */
  .breadcrumb { font-size: var(--fs-xs); }
  .breadcrumb .breadcrumb-item:not(:last-child):not(:nth-last-child(2)) { display: none; }

  /* Flex wrap utilities */
  .flex-gap { flex-wrap: wrap !important; }
  .page-header .flex-gap { flex-wrap: wrap; }

  /* Kanban horizontal scroll */
  .kanban-board { gap: var(--sp-3); }

  /* Command palette */
  .palette-box { width: 95vw; }
}

/* ============================================================
   MOBILE — max-width: 480px
   ============================================================ */
@media (max-width: 480px) {
  .page-content { padding: var(--sp-3) var(--sp-3) 80px !important; }
  h1 { font-size: var(--fs-lg) !important; }
  .card { padding: var(--sp-3); }
  .big-stat-card .value { font-size: var(--fs-xl); }
  .stat-value { font-size: 22px; }
  .calc-box { font-size: var(--fs-xs); }
  .topbar { padding: 8px var(--sp-3); }
}
