/* ============================================================
   Life OS — Design System v2  (Linear-style, dark-first, RTL)
   ------------------------------------------------------------
   01. FONT
   02. TOKENS — dark (default)
   03. TOKENS — light (html.light)
   04. LEGACY ALIASES
   05. RESET + BASE
   06. APP SHELL (topbar / page-body)
   07. DOCK
   08. COMMAND PALETTE
   09. COMPONENTS (legacy class names, new skin)
   10. FULLCALENDAR THEME
   11. UTILITIES
   12. RESPONSIVE
   ============================================================ */

/* ---- 01. FONT ------------------------------------------------ */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&display=swap');

/* ---- 02. TOKENS — DARK (default) ------------------------------ */
:root {
  color-scheme: dark;

  /* surfaces */
  --bg-base:    #0a0a0b;
  --bg-surface: #131316;
  --bg-raised:  #19191e;
  --bg-overlay: #1c1c22;
  --bg-input:   #101013;
  --bg-hover:   rgba(255,255,255,.045);
  --bg-active:  rgba(255,255,255,.08);

  /* borders */
  --border-subtle: rgba(255,255,255,.07);
  --border-strong: rgba(255,255,255,.14);

  /* text */
  --text-1: #ededef;
  --text-2: #a1a1aa;
  --text-3: #6e6e78;

  /* brand */
  --accent:        #22c55e;
  --accent-strong: #16a34a;
  --accent-soft:   #4ade80;
  --accent-muted:  rgba(34,197,94,.14);
  --accent-ring:   rgba(34,197,94,.35);

  /* status */
  --red:    #f87171;  --red-bg:    rgba(248,113,113,.13);
  --amber:  #fbbf24;  --amber-bg:  rgba(251,191,36,.13);
  --blue:   #60a5fa;  --blue-bg:   rgba(96,165,250,.13);
  --purple: #c084fc;  --purple-bg: rgba(192,132,252,.13);
  --teal:   #2dd4bf;  --teal-bg:   rgba(45,212,191,.13);
  --green:  #4ade80;  --green-bg:  rgba(74,222,128,.13);
  --gray-fg:#a1a1aa;  --gray-bg:   rgba(255,255,255,.07);

  /* geometry */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 999px;

  /* elevation */
  --shadow-sm:  0 1px 2px rgba(0,0,0,.3);
  --shadow-md:  0 4px 16px rgba(0,0,0,.35);
  --shadow-pop: 0 8px 40px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.35);

  /* type scale */
  --fs-xs: 11px; --fs-sm: 12.5px; --fs-base: 13.5px;
  --fs-lg: 15px; --fs-xl: 18px;   --fs-2xl: 22px;

  /* layering */
  --z-topbar: 50; --z-dock: 100; --z-popover: 110;
  --z-palette: 200; --z-modal: 300;

  --font: 'IBM Plex Sans Arabic', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --ease: cubic-bezier(.25,.1,.25,1);
}

/* ---- 03. TOKENS — LIGHT ---------------------------------------- */
html.light {
  color-scheme: light;

  --bg-base:    #f7f8f8;
  --bg-surface: #ffffff;
  --bg-raised:  #f2f3f5;
  --bg-overlay: #ffffff;
  --bg-input:   #ffffff;
  --bg-hover:   rgba(0,0,0,.035);
  --bg-active:  rgba(0,0,0,.06);

  --border-subtle: rgba(0,0,0,.08);
  --border-strong: rgba(0,0,0,.16);

  --text-1: #17171c;
  --text-2: #5f606a;
  --text-3: #9a9aa3;

  --accent:        #16a34a;
  --accent-strong: #15803d;
  --accent-soft:   #16a34a;
  --accent-muted:  rgba(22,163,74,.1);
  --accent-ring:   rgba(22,163,74,.25);

  --red:    #dc2626;  --red-bg:    rgba(220,38,38,.09);
  --amber:  #b45309;  --amber-bg:  rgba(217,119,6,.11);
  --blue:   #2563eb;  --blue-bg:   rgba(37,99,235,.09);
  --purple: #9333ea;  --purple-bg: rgba(147,51,234,.09);
  --teal:   #0d9488;  --teal-bg:   rgba(13,148,136,.1);
  --green:  #16a34a;  --green-bg:  rgba(22,163,74,.11);
  --gray-fg:#5f606a;  --gray-bg:   rgba(0,0,0,.06);

  --shadow-sm:  0 1px 2px rgba(0,0,0,.05);
  --shadow-md:  0 4px 14px rgba(0,0,0,.07);
  --shadow-pop: 0 8px 36px rgba(0,0,0,.14), 0 2px 8px rgba(0,0,0,.07);
}

/* ---- 04. LEGACY ALIASES ----------------------------------------
   الـ views القديمة تعتمد هذه الأسماء — تُحوَّل للنظام الجديد */
:root, html.light {
  --primary:       var(--accent);
  --primary-dark:  var(--accent-strong);
  --primary-light: var(--accent-muted);
  --success:       var(--accent);
  --warning:       var(--amber);
  --danger:        var(--red);
  --info:          var(--blue);
  --bg:            var(--bg-base);
  --card-bg:       var(--bg-surface);
  --text:          var(--text-1);
  --text-muted:    var(--text-2);
  --border:        var(--border-subtle);
  --shadow:        var(--shadow-sm);
  --radius:        var(--radius-lg);
  --transition:    .15s var(--ease);
}

/* ---- 05. RESET + BASE ------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { direction: rtl; }

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-1);
  font-size: var(--fs-base);
  line-height: 1.65;
  direction: rtl;
  text-align: right;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-soft); text-decoration: none; transition: color .15s var(--ease); }
a:hover { color: var(--accent); }

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

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
*::-webkit-scrollbar-track { background: transparent; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.icon { flex-shrink: 0; vertical-align: middle; }

.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  font-family: var(--font); font-size: 10.5px; font-weight: 600;
  color: var(--text-3); background: var(--bg-raised);
  border: 1px solid var(--border-subtle); border-bottom-width: 2px;
  border-radius: 4px; direction: ltr;
}

/* ---- 06. APP SHELL ---------------------------------------------- */
.app-wrapper { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: calc(52px + env(safe-area-inset-top, 0px));
  display: flex; align-items: center; gap: 10px;
  padding: env(safe-area-inset-top, 0px) 20px 0;
  background: color-mix(in srgb, var(--bg-base) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 0; z-index: var(--z-topbar);
}

.topbar-brand {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: var(--radius-md);
  background: var(--accent); color: #fff; flex-shrink: 0;
}
.topbar-brand .icon { width: 15px; height: 15px; }

.topbar-title { font-size: 14.5px; font-weight: 600; color: var(--text-1); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; min-width: 32px; padding: 0 8px;
  background: transparent; border: none; border-radius: var(--radius-md);
  color: var(--text-2); font-family: var(--font); font-size: var(--fs-sm); font-weight: 500;
  cursor: pointer; transition: background .15s var(--ease), color .15s var(--ease);
  position: relative; text-decoration: none;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-1); }

.search-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 10px;
  background: var(--bg-hover); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); color: var(--text-3);
  font-family: var(--font); font-size: var(--fs-sm); cursor: pointer;
  transition: border-color .15s var(--ease), color .15s var(--ease);
}
.search-btn:hover { border-color: var(--border-strong); color: var(--text-2); }
.search-btn .search-label { min-width: 60px; text-align: right; }

.notif-badge, .nav-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 17px; height: 17px; padding: 0 5px;
  background: var(--red); color: #fff;
  font-size: 10px; font-weight: 700; border-radius: var(--radius-full);
  line-height: 1;
}
.icon-btn .notif-badge {
  position: absolute; top: 1px; left: 1px;
}

.theme-toggle .i-moon { display: none; }
html.light .theme-toggle .i-sun  { display: none; }
html.light .theme-toggle .i-moon { display: block; }

.topbar-avatar {
  width: 28px; height: 28px; border-radius: var(--radius-full);
  background: var(--accent-muted); color: var(--accent-soft);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; cursor: pointer; border: none;
  font-family: var(--font); flex-shrink: 0;
}

.user-menu {
  position: absolute; top: 44px; left: 12px;
  min-width: 180px; padding: 5px;
  background: var(--bg-overlay); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-pop);
  z-index: var(--z-popover);
  opacity: 0; transform: translateY(-4px); pointer-events: none;
  transition: opacity .13s var(--ease), transform .13s var(--ease);
}
.user-menu.open { opacity: 1; transform: none; pointer-events: auto; }
.user-menu-head { padding: 8px 10px 6px; border-bottom: 1px solid var(--border-subtle); margin-bottom: 4px; }
.user-menu-head .name { font-size: var(--fs-sm); font-weight: 600; color: var(--text-1); }
.user-menu-head .mail { font-size: var(--fs-xs); color: var(--text-3); direction: ltr; text-align: right; }
.user-menu a {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: var(--radius-md);
  font-size: var(--fs-sm); font-weight: 500; color: var(--text-2);
}
.user-menu a:hover { background: var(--bg-hover); color: var(--text-1); }

.page-body {
  flex: 1; padding: 24px 28px 110px;
  width: 100%; max-width: 1440px; margin: 0 auto;
}
.page-body--full { max-width: none; padding: 0; position: relative; }

/* ---- 07. DOCK ---------------------------------------------------- */
.dock {
  position: fixed; bottom: 14px; right: 50%;
  transform: translateX(50%);
  z-index: var(--z-dock);
}
.dock-inner {
  display: flex; align-items: center; gap: 2px;
  padding: 6px;
  background: color-mix(in srgb, var(--bg-overlay) 88%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: var(--shadow-pop);
}
.dock-sep { width: 1px; height: 22px; background: var(--border-subtle); margin: 0 4px; flex-shrink: 0; }

.dock-group { position: relative; }

.dock-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  background: transparent; border: none; border-radius: 11px;
  color: var(--text-2); cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease), transform .15s var(--ease);
  text-decoration: none;
}
.dock-btn:hover { background: var(--bg-hover); color: var(--text-1); transform: translateY(-2px); }
.dock-btn .icon { width: 19px; height: 19px; }

.dock-btn.is-active { color: var(--accent-soft); }
.dock-btn .dock-dot {
  position: absolute; bottom: 3px; right: 50%; transform: translateX(50%);
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--accent); opacity: 0;
  transition: opacity .15s var(--ease);
}
.dock-btn.is-active .dock-dot { opacity: 1; }

.dock-btn .nav-badge { position: absolute; top: 2px; left: 2px; }

.dock-btn-accent { background: var(--accent); color: #fff; }
.dock-btn-accent:hover { background: var(--accent-strong); color: #fff; }

/* tooltip */
.dock-btn[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute; bottom: calc(100% + 10px); right: 50%; transform: translateX(50%) translateY(2px);
  padding: 4px 9px; white-space: nowrap;
  background: var(--bg-overlay); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-1);
  opacity: 0; pointer-events: none;
  transition: opacity .12s var(--ease), transform .12s var(--ease);
}
.dock-btn[data-tooltip]:hover::after { opacity: 1; transform: translateX(50%); }
.dock-group.open .dock-btn[data-tooltip]::after { opacity: 0; }

/* popover */
.dock-popover {
  position: absolute; bottom: calc(100% + 12px); right: 50%; transform: translateX(50%) translateY(6px);
  min-width: 208px; padding: 5px;
  background: var(--bg-overlay); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-pop);
  opacity: 0; pointer-events: none;
  transition: opacity .14s var(--ease), transform .14s var(--ease);
  z-index: var(--z-popover);
}
.dock-group.open .dock-popover { opacity: 1; transform: translateX(50%); pointer-events: auto; }

.dock-pop-title {
  padding: 6px 10px 4px;
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-3);
}
.dock-pop-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: var(--radius-md);
  font-size: var(--fs-sm); font-weight: 500; color: var(--text-2);
  transition: background .12s var(--ease), color .12s var(--ease);
}
.dock-pop-item:hover { background: var(--bg-hover); color: var(--text-1); }
.dock-pop-item.is-active { color: var(--accent-soft); background: var(--accent-muted); }
.dock-pop-item .icon { width: 16px; height: 16px; color: var(--text-3); }
.dock-pop-item:hover .icon, .dock-pop-item.is-active .icon { color: currentColor; }
.dock-pop-item .nav-badge { margin-right: auto; }

/* mobile more button — hidden on desktop */
.dock-more { display: none; }

/* mobile bottom sheet */
.dock-sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  z-index: calc(var(--z-dock) + 1);
  opacity: 0; pointer-events: none; transition: opacity .2s var(--ease);
}
.dock-sheet {
  position: fixed; bottom: 0; right: 0; left: 0;
  max-height: 72vh; overflow-y: auto;
  background: var(--bg-overlay);
  border-top: 1px solid var(--border-subtle);
  border-radius: 18px 18px 0 0;
  padding: 10px 14px calc(16px + env(safe-area-inset-bottom));
  z-index: calc(var(--z-dock) + 2);
  transform: translateY(100%); transition: transform .25s var(--ease);
}
.dock-sheet.open { transform: none; }
.dock-sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.dock-sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 2px auto 12px; }
.dock-sheet-section { margin-bottom: 12px; }
.dock-sheet-title { font-size: var(--fs-xs); font-weight: 600; color: var(--text-3); padding: 0 4px 6px; }
.dock-sheet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; }

/* ---- 08. COMMAND PALETTE ----------------------------------------- */
.palette-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  z-index: var(--z-palette);
  opacity: 0; pointer-events: none; transition: opacity .15s var(--ease);
}
.palette-backdrop.open { opacity: 1; pointer-events: auto; }

.palette {
  position: fixed; top: 16vh; right: 50%; transform: translateX(50%) scale(.98);
  width: min(560px, calc(100vw - 32px));
  background: var(--bg-overlay); border: 1px solid var(--border-subtle);
  border-radius: 14px; box-shadow: var(--shadow-pop);
  z-index: calc(var(--z-palette) + 1);
  opacity: 0; pointer-events: none;
  transition: opacity .15s var(--ease), transform .15s var(--ease);
  overflow: hidden;
}
.palette.open { opacity: 1; transform: translateX(50%) scale(1); pointer-events: auto; }

.palette-input-wrap {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-3);
}
.palette-input-wrap .icon { width: 17px; height: 17px; }
.palette-input {
  flex: 1; background: none; border: none; outline: none; box-shadow: none;
  font-family: var(--font); font-size: var(--fs-lg); color: var(--text-1);
  padding: 0; direction: rtl; text-align: right;
}
.palette-input::placeholder { color: var(--text-3); }

.palette-results { max-height: 340px; overflow-y: auto; padding: 6px; }

.palette-section {
  padding: 8px 10px 3px;
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-3);
}
.palette-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-md);
  font-size: var(--fs-base); font-weight: 500; color: var(--text-2);
  cursor: pointer;
}
.palette-item .icon { width: 16px; height: 16px; color: var(--text-3); }
.palette-item .palette-item-hint { margin-right: auto; font-size: var(--fs-xs); color: var(--text-3); }
.palette-item.selected { background: var(--bg-hover); color: var(--text-1); }
.palette-item.selected .icon { color: var(--accent-soft); }
.palette-empty { padding: 28px 16px; text-align: center; color: var(--text-3); font-size: var(--fs-sm); }

.palette-footer {
  display: flex; align-items: center; gap: 14px;
  padding: 9px 16px;
  border-top: 1px solid var(--border-subtle);
  font-size: var(--fs-xs); color: var(--text-3);
}
.palette-footer span { display: inline-flex; align-items: center; gap: 5px; }

/* ---- 09. COMPONENTS ------------------------------------------------ */

/* Cards */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.card-header h3 { font-size: 14px; font-weight: 600; color: var(--text-1); }
.card-body { padding: 18px; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex; align-items: flex-start; gap: 12px;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.stat-card:hover { border-color: var(--border-strong); }
.stat-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.stat-icon.blue   { background: var(--blue-bg);   color: var(--blue); }
.stat-icon.green  { background: var(--green-bg);  color: var(--green); }
.stat-icon.orange { background: var(--amber-bg);  color: var(--amber); }
.stat-icon.red    { background: var(--red-bg);    color: var(--red); }
.stat-icon.purple { background: var(--purple-bg); color: var(--purple); }
.stat-icon.teal   { background: var(--teal-bg);   color: var(--teal); }
.stat-value { font-size: 21px; font-weight: 700; line-height: 1.25; color: var(--text-1); font-variant-numeric: tabular-nums; }
.stat-label { font-size: var(--fs-xs); color: var(--text-2); margin-top: 2px; font-weight: 500; }

/* Alerts */
.alert {
  padding: 11px 14px; border-radius: var(--radius-md);
  margin-bottom: 14px; display: flex; align-items: flex-start; gap: 10px;
  font-size: var(--fs-sm); font-weight: 500;
  border: 1px solid transparent;
}
.alert-success { background: var(--green-bg); border-color: color-mix(in srgb, var(--green) 25%, transparent); color: var(--green); }
.alert-error, .alert-danger { background: var(--red-bg); border-color: color-mix(in srgb, var(--red) 25%, transparent); color: var(--red); }
.alert-warning { background: var(--amber-bg); border-color: color-mix(in srgb, var(--amber) 25%, transparent); color: var(--amber); }
.alert-info { background: var(--blue-bg); border-color: color-mix(in srgb, var(--blue) 25%, transparent); color: var(--blue); }

/* Subscription alert box */
.sub-alert-box {
  background: var(--red-bg);
  border: 1px solid color-mix(in srgb, var(--red) 30%, transparent);
  color: var(--text-1);
  border-radius: var(--radius-lg); padding: 16px 18px; margin-bottom: 18px;
}
.sub-alert-box h3 { font-size: 14px; font-weight: 600; margin-bottom: 8px; color: var(--red); }
.sub-alert-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 9px 12px; margin-top: 7px; gap: 10px; flex-wrap: wrap;
}
.sub-alert-item .sub-name { font-weight: 600; font-size: var(--fs-sm); color: var(--text-1); }
.sub-alert-item .sub-meta { font-size: var(--fs-xs); color: var(--text-2); }
.sub-countdown {
  background: var(--amber-bg); color: var(--amber);
  padding: 3px 10px; border-radius: var(--radius-full);
  font-size: var(--fs-xs); font-weight: 700; white-space: nowrap;
}
.sub-countdown.urgent { background: var(--red-bg); color: var(--red); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: var(--radius-full);
  font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
  line-height: 1.6;
}
.badge-success   { background: var(--green-bg);  color: var(--green); }
.badge-primary   { background: var(--accent-muted); color: var(--accent-soft); }
.badge-warning   { background: var(--amber-bg);  color: var(--amber); }
.badge-danger    { background: var(--red-bg);    color: var(--red); }
.badge-secondary { background: var(--gray-bg);   color: var(--gray-fg); }
.badge-info      { background: var(--blue-bg);   color: var(--blue); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius-md);
  font-size: var(--fs-sm); font-weight: 600;
  border: 1px solid transparent; cursor: pointer;
  transition: background .13s var(--ease), border-color .13s var(--ease), color .13s var(--ease);
  white-space: nowrap; text-decoration: none;
  font-family: var(--font); line-height: 1.5;
}
.btn:active { transform: translateY(.5px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); color: #fff; }
.btn-success { background: var(--accent); color: #fff; }
.btn-success:hover { background: var(--accent-strong); color: #fff; }
.btn-danger { background: transparent; color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, transparent); }
.btn-danger:hover { background: var(--red-bg); color: var(--red); }
.btn-warning { background: var(--amber-bg); color: var(--amber); }
.btn-warning:hover { background: color-mix(in srgb, var(--amber) 22%, transparent); color: var(--amber); }
.btn-light {
  background: var(--bg-raised); color: var(--text-2);
  border-color: var(--border-subtle);
}
.btn-light:hover { color: var(--text-1); border-color: var(--border-strong); }
.btn-outline { background: transparent; color: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.btn-outline:hover { background: var(--accent-muted); color: var(--accent-soft); }
.btn-sm { padding: 4px 10px; font-size: var(--fs-xs); }
.btn-xs { padding: 2px 8px; font-size: var(--fs-xs); border-radius: var(--radius-sm); }
.btn-icon { padding: 7px; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
.table { width: 100%; border-collapse: collapse; }
th {
  text-align: right; padding: 9px 14px;
  font-size: var(--fs-xs); font-weight: 600;
  letter-spacing: .3px;
  color: var(--text-3); border-bottom: 1px solid var(--border-subtle);
  background: transparent; white-space: nowrap;
}
td {
  padding: 10px 14px; border-bottom: 1px solid var(--border-subtle);
  font-size: var(--fs-sm); vertical-align: middle; color: var(--text-1);
  font-variant-numeric: tabular-nums;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }

/* Forms */
.form-group { margin-bottom: 16px; }
label {
  display: block; font-size: var(--fs-xs); font-weight: 600;
  color: var(--text-2); margin-bottom: 6px;
}
input, select, textarea {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
  font-size: var(--fs-base); font-family: var(--font);
  color: var(--text-1); background: var(--bg-input);
  transition: border-color .13s var(--ease), box-shadow .13s var(--ease);
  outline: none;
  direction: rtl; text-align: right;
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}
input.is-invalid, select.is-invalid, textarea.is-invalid { border-color: var(--red); }
.form-error { color: var(--red); font-size: var(--fs-xs); margin-top: 4px; }
textarea { resize: vertical; min-height: 90px; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236e6e78' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 10px center;
  padding-right: 12px; padding-left: 30px;
}
.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.form-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-check input[type=checkbox] { width: auto; cursor: pointer; direction: ltr; accent-color: var(--accent); }
.form-check label { margin-bottom: 0; font-weight: 500; cursor: pointer; color: var(--text-1); font-size: var(--fs-sm); }

/* Page header */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; gap: 12px; flex-wrap: wrap;
}
.page-header h1 { font-size: 19px; font-weight: 700; color: var(--text-1); letter-spacing: -.2px; }
.page-header p { color: var(--text-2); font-size: var(--fs-sm); margin-top: 2px; }

/* Grid layouts */
.grid-2    { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3    { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }

/* Task list */
.task-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border-subtle); }
.task-item:last-child { border-bottom: none; }
.task-check {
  width: 20px; height: 20px; border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-full); cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: border-color .13s var(--ease), background .13s var(--ease);
  font-size: 11px; color: transparent;
}
.task-check.done { background: var(--accent); border-color: var(--accent); color: #fff; }
.task-check:hover { border-color: var(--accent); }
.task-title { flex: 1; font-size: var(--fs-sm); font-weight: 500; color: var(--text-1); }
.task-title.done { text-decoration: line-through; color: var(--text-3); }
.task-due { font-size: var(--fs-xs); color: var(--text-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.task-due.overdue { color: var(--red); font-weight: 600; }

/* Progress */
.progress-bar-wrap { background: var(--bg-active); border-radius: var(--radius-full); height: 6px; overflow: hidden; direction: ltr; }
.progress-bar {
  height: 100%; border-radius: var(--radius-full);
  background: var(--accent);
  transition: width .4s var(--ease);
}
.progress-bar.green  { background: var(--green); }
.progress-bar.orange { background: var(--amber); }

/* Habits */
.habit-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 15px 17px; margin-bottom: 12px;
  transition: border-color .15s var(--ease);
}
.habit-card:hover { border-color: var(--border-strong); }
.habit-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.habit-title { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; color: var(--text-1); }
.habit-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.habit-streak { font-size: var(--fs-xs); color: var(--text-2); }
.habit-streak strong { color: var(--amber); }
.habit-grid { display: flex; gap: 3px; flex-wrap: wrap; direction: ltr; }
.habit-day { width: 13px; height: 13px; border-radius: 3px; background: var(--bg-active); }
.habit-day.logged { background: var(--accent); }
.habit-log-btn {
  width: 34px; height: 34px; border-radius: var(--radius-full);
  border: 1.5px solid var(--border-strong); background: transparent;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 16px; transition: all .15s var(--ease); flex-shrink: 0;
  color: var(--text-3);
}
.habit-log-btn.logged { background: var(--accent); border-color: var(--accent); color: #fff; }
.habit-log-btn:hover { border-color: var(--accent); color: var(--accent-soft); transform: scale(1.06); }
.habit-log-btn.logged:hover { color: #fff; }

.dash-habit-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); background: var(--bg-surface);
  transition: border-color .15s var(--ease);
}
.dash-habit-item.logged { background: var(--accent-muted); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }

/* Calendar container */
#calendar-container {
  background: var(--bg-surface); border-radius: var(--radius-lg);
  padding: 16px; border: 1px solid var(--border-subtle);
  overflow: hidden;
}
#calendar { min-height: 500px; }

/* Stats bar charts */
.bar-chart { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label { font-size: var(--fs-xs); font-weight: 500; color: var(--text-2); min-width: 80px; text-align: right; white-space: nowrap; }
.bar-track { flex: 1; background: var(--bg-active); border-radius: var(--radius-full); height: 8px; overflow: hidden; direction: ltr; }
.bar-fill  { height: 100%; border-radius: var(--radius-full); background: var(--accent); transition: width .5s var(--ease); }
.bar-fill.income  { background: var(--green); }
.bar-fill.expense { background: var(--red); }
.bar-fill.habit   { background: var(--teal); }
.bar-val  { font-size: var(--fs-xs); font-weight: 600; min-width: 60px; text-align: left; color: var(--text-1); font-variant-numeric: tabular-nums; }

/* Donut ring stats */
.ring-stat { display: flex; align-items: center; gap: 16px; }
.ring-stat .ring-info { flex: 1; }
.ring-stat .ring-pct  { font-size: 26px; font-weight: 700; color: var(--accent-soft); font-variant-numeric: tabular-nums; }
.ring-stat .ring-label{ font-size: var(--fs-xs); color: var(--text-2); }

/* Period filter */
.period-filter {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-surface); padding: 8px 12px; border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle); margin-bottom: 20px; flex-wrap: wrap;
}
.period-filter label { margin: 0; font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); white-space: nowrap; }
.period-btn {
  padding: 4px 12px; border-radius: var(--radius-full);
  font-size: var(--fs-xs); font-weight: 600;
  background: var(--bg-raised); color: var(--text-2); border: none; cursor: pointer;
  transition: background .13s var(--ease), color .13s var(--ease);
  text-decoration: none; display: inline-block;
  font-family: var(--font);
}
.period-btn.active, .period-btn:hover { background: var(--accent); color: #fff; }

/* Empty state */
.empty-state { text-align: center; padding: 44px 20px; color: var(--text-2); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; display: block; opacity: .8; }
.empty-state > .icon { width: 40px; height: 40px; margin-bottom: 12px; color: var(--text-3); }
.empty-state h3 { font-size: 15px; color: var(--text-1); margin-bottom: 6px; font-weight: 600; }
.empty-state p  { font-size: var(--fs-sm); margin-bottom: 16px; }

/* Filter bar */
.filter-bar {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 18px; flex-wrap: wrap;
}
.filter-bar select, .filter-bar input { width: auto; min-width: 140px; font-size: var(--fs-sm); padding: 6px 10px; }
.filter-bar select { padding-left: 30px; }
.filter-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 12px; border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
  font-size: var(--fs-xs); font-weight: 600; background: transparent;
  color: var(--text-2); cursor: pointer;
  transition: border-color .13s var(--ease), color .13s var(--ease), background .13s var(--ease);
  text-decoration: none; font-family: var(--font);
}
.filter-btn:hover { border-color: var(--border-strong); color: var(--text-1); }
.filter-btn.active { border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: var(--accent-soft); background: var(--accent-muted); }

/* Misc */
.section-title { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .4px; color: var(--text-3); margin-bottom: 10px; }
.divider { border: none; border-top: 1px solid var(--border-subtle); margin: 18px 0; }

/* Notifications */
.notif-item {
  display: flex; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  transition: background .13s var(--ease);
}
.notif-item:hover { background: var(--bg-hover); }
.notif-item.unread { background: var(--accent-muted); }
.notif-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; margin-top: 7px; }
.notif-dot.danger  { background: var(--red); }
.notif-dot.warning { background: var(--amber); }
.notif-dot.info    { background: var(--blue); }
.notif-dot.success { background: var(--green); }

/* Project card */
.project-card {
  background: var(--bg-surface); border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  transition: border-color .15s var(--ease);
}
.project-card:hover { border-color: var(--border-strong); }

/* Auth pages */
.auth-page {
  min-height: 100vh;
  background: var(--bg-base);
  background-image: radial-gradient(ellipse 60% 40% at 50% -10%, var(--accent-muted), transparent);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; direction: rtl;
}
.auth-card {
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: 16px; padding: 36px 32px;
  width: 100%; max-width: 400px; box-shadow: var(--shadow-pop);
}
.auth-logo { text-align: center; margin-bottom: 26px; }
.auth-logo .icon {
  width: 52px; height: 52px; background: var(--accent); border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; margin: 0 auto 12px; color: #fff;
}
.auth-logo h1 { font-size: 21px; font-weight: 700; color: var(--text-1); }
.auth-logo p  { color: var(--text-2); font-size: var(--fs-sm); }

/* Finance */
.finance-summary {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-bottom: 22px;
}
.finance-stat {
  background: var(--bg-surface); border-radius: var(--radius-lg); padding: 16px;
  border: 1px solid var(--border-subtle); text-align: center;
}
.finance-stat .amount { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.finance-stat .label  { font-size: var(--fs-xs); color: var(--text-2); font-weight: 600; margin-top: 4px; }

/* ---- 10. FULLCALENDAR THEME ---------------------------------------- */
:root {
  --fc-border-color: var(--border-subtle);
  --fc-today-bg-color: var(--accent-muted);
  --fc-page-bg-color: transparent;
  --fc-neutral-bg-color: var(--bg-raised);
  --fc-list-event-hover-bg-color: var(--bg-hover);
  --fc-event-text-color: #fff;
}
.fc { direction: rtl; font-family: var(--font); }
.fc .fc-toolbar { flex-wrap: wrap; gap: 6px; }
.fc .fc-toolbar-title { font-size: 15px !important; font-weight: 600 !important; color: var(--text-1); }
.fc .fc-button {
  border-radius: var(--radius-md) !important; font-size: var(--fs-xs) !important;
  padding: 4px 10px !important; font-family: var(--font) !important;
  box-shadow: none !important;
}
.fc .fc-button-primary {
  background: var(--bg-raised) !important;
  border-color: var(--border-subtle) !important;
  color: var(--text-2) !important;
}
.fc .fc-button-primary:hover { color: var(--text-1) !important; border-color: var(--border-strong) !important; }
.fc .fc-button-primary:not(:disabled).fc-button-active,
.fc .fc-button-primary:not(:disabled):active {
  background: var(--accent) !important; border-color: var(--accent) !important; color: #fff !important;
}
.fc .fc-event { font-size: 11px; border-radius: 4px; padding: 1px 4px; border: none !important; }
.fc .fc-daygrid-day-number, .fc .fc-col-header-cell-cushion { color: var(--text-2); }
.fc .fc-day-today .fc-daygrid-day-number { color: var(--accent-soft); font-weight: 700; }
.fc .fc-list-day-cushion { background: var(--bg-raised) !important; }
.fc .fc-list-event td { color: var(--text-1); }
.fc-theme-standard .fc-list { border-color: var(--border-subtle); }

/* ---- 11. UTILITIES --------------------------------------------------- */
.text-muted   { color: var(--text-2); }
.text-success { color: var(--green); }
.text-danger  { color: var(--red); }
.text-warning { color: var(--amber); }
.fw-bold  { font-weight: 700; }
.fs-sm    { font-size: var(--fs-xs); }
.text-xs  { font-size: var(--fs-xs); }
.text-sm  { font-size: var(--fs-sm); }
.tabular  { font-variant-numeric: tabular-nums; }

.mt-1 { margin-top: 4px; }    .mt-2 { margin-top: 8px; }    .mt-3 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 16px; }

.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.flex-col { flex-direction: column; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 16px; }
.flex-1 { flex: 1; }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.w-100 { width: 100%; }

.muted-box {
  background: var(--bg-raised); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); padding: 10px 12px;
}

/* ---- 12. RESPONSIVE --------------------------------------------------- */
@media (max-width: 900px) {
  .topbar { padding: env(safe-area-inset-top, 0px) 12px 0; }
  .page-body { padding: 14px 14px 96px; }
  /* منع تكبير iOS التلقائي عند التركيز على الحقول */
  input, select, textarea { font-size: 16px; }
  .palette-input { font-size: 16px; }
  .grid-2, .grid-3, .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .finance-summary { grid-template-columns: 1fr 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .card .card-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 480px; }
  .page-header h1 { font-size: 17px; }
  .topbar-title { font-size: 13.5px; }
  .filter-bar { gap: 6px; }
  .filter-btn { font-size: var(--fs-xs); padding: 4px 9px; }
  .hide-mobile { display: none !important; }
  .search-btn .search-label, .search-btn .kbd { display: none; }

  /* dock → bottom tab bar */
  .dock { bottom: 0; right: 0; left: 0; transform: none; }
  .dock-inner {
    border-radius: 0; border-left: none; border-right: none; border-bottom: none;
    justify-content: space-around; gap: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .dock-sep { display: none; }
  .dock-group { display: none; }          /* المجموعات تنتقل للـ sheet */
  .dock-group.dock-group-create { display: block; }
  .dock-more { display: inline-flex; }
  .dock-btn:hover { transform: none; }
  .dock-btn[data-tooltip]::after { display: none; }

  /* Calendar responsive */
  #calendar-container { padding: 10px 6px; }
  #calendar { min-height: 400px; }
  .fc .fc-toolbar { flex-wrap: wrap; gap: 4px; justify-content: center; }
  .fc .fc-toolbar-chunk { display: flex; gap: 4px; }
  .fc .fc-toolbar-title { font-size: 13px !important; }
  .fc .fc-button { font-size: 11px !important; padding: 3px 7px !important; }
  .fc .fc-daygrid-day-number { font-size: 12px; }
  .fc .fc-col-header-cell-cushion { font-size: 11px; }
  .fc .fc-event { font-size: 10px; }
}

@media (max-width: 540px) {
  .stat-grid { grid-template-columns: 1fr; }
  .finance-summary { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-header .btn { align-self: flex-start; }
  .card-header { flex-wrap: wrap; gap: 8px; }
  td .btn { padding: 3px 7px; font-size: var(--fs-xs); }
  .sub-alert-item { flex-direction: column; align-items: flex-start; }
  .auth-card { padding: 26px 18px; }
  .period-filter { padding: 8px; gap: 4px; }
  .palette { top: 8vh; }

  #calendar-container { padding: 8px 4px; }
  #calendar { min-height: 320px; }
  .fc .fc-toolbar { flex-direction: column; align-items: center; gap: 6px; }
  .fc .fc-toolbar-title { font-size: 14px !important; }
  .fc .fc-daygrid-body { overflow-x: auto; }
}
