/* ===== دواجن — design tokens (from Stitch DESIGN.md) ===== */
:root {
  --primary: #15803D;
  --primary-dark: #166534;
  --primary-tint: #DCFCE7;
  --bg: #F6F8F5;
  --surface: #FFFFFF;
  --text: #16241C;
  --muted: #64746B;
  --border: #E3E8E3;
  --success: #16A34A;
  --warning: #F59E0B;
  --warning-tint: #FEF3C7;
  --danger: #DC2626;
  --danger-tint: #FEE2E2;
  --info: #2563EB;
  --info-tint: #DBEAFE;
  --radius-card: 16px;
  --radius-btn: 14px;
  --shadow: 0 1px 3px rgba(22, 36, 28, .06), 0 4px 14px rgba(22, 36, 28, .05);
  --touch: 56px;
  --nav-h: 68px;
  --sidebar-w: 250px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: 'Tajawal', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; }
p { margin: 0; }

.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 24;
  vertical-align: middle;
  user-select: none;
}

.num { direction: ltr; unicode-bidi: embed; }

/* ===== App shell: mobile-first, sidebar on desktop ===== */
.app-shell { min-height: 100vh; }

.app-content {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 1.25rem calc(var(--nav-h) + 96px);
}

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(246, 248, 245, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid transparent;
  margin: 0 -1.25rem;
  padding: .9rem 1.25rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  min-height: var(--touch);
}
.topbar .title {
  font-size: 22px; font-weight: 700; flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .title small { display: block; font-size: 13px; color: var(--muted); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.topbar .back-btn, .topbar .icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--text); background: transparent; border: none; cursor: pointer;
}
.topbar .back-btn:hover, .topbar .icon-btn:hover { background: #eaefe6; }

.day-badge {
  background: var(--primary-tint); color: var(--primary-dark);
  border-radius: 999px; padding: .15rem .7rem; font-size: 14px; font-weight: 700;
  white-space: nowrap;
}

/* ---- Bottom navigation (mobile) ---- */
.bottom-nav {
  position: fixed; bottom: 0; right: 0; left: 0; z-index: 50;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  height: var(--nav-h);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); font-size: 12.5px; font-weight: 600; position: relative;
}
.bottom-nav a.active { color: var(--primary); }
.bottom-nav .nav-badge {
  position: absolute; top: 8px; margin-right: 22px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 999px;
  display: grid; place-items: center; padding: 0 4px;
}

/* ---- Sidebar (desktop) ---- */
.sidebar { display: none; }

@media (min-width: 768px) {
  /* Full-width dashboard. The sidebar sits on the RIGHT (RTL), so the empty
     space is reserved on the right via margin-right — content fills the rest
     and never slides under the sidebar. */
  .app-content {
    max-width: none;
    margin-right: var(--sidebar-w);
    margin-left: 0;
    padding: 0 2.5rem 3rem;
  }

  .bottom-nav { display: none; }

  .sidebar {
    display: flex; flex-direction: column;
    position: fixed; top: 0; bottom: 0; right: 0; width: var(--sidebar-w); z-index: 50;
    background: var(--surface); border-left: 1px solid var(--border);
    box-shadow: -2px 0 12px rgba(22, 36, 28, .04);
    padding: 1.5rem 1rem;
    gap: .35rem;
  }
  .sidebar .brand {
    font-size: 26px; font-weight: 800; color: var(--primary-dark);
    display: flex; align-items: center; gap: .5rem; padding: 0 .75rem 1.25rem;
  }
  .sidebar a.nav-item {
    display: flex; align-items: center; gap: .75rem;
    padding: .8rem .9rem; border-radius: 12px;
    color: var(--muted); font-weight: 600; font-size: 16px; position: relative;
    min-height: 48px;
  }
  .sidebar a.nav-item:hover { background: var(--bg); }
  .sidebar a.nav-item.active { background: var(--primary-tint); color: var(--primary-dark); }
  .sidebar .nav-badge {
    margin-right: auto;
    background: var(--danger); color: #fff; font-size: 11.5px; font-weight: 700;
    min-width: 20px; height: 20px; border-radius: 999px;
    display: grid; place-items: center; padding: 0 5px;
  }

  /* Cleaner, larger desktop header aligned to content (no full-bleed blur strip) */
  .topbar {
    margin-inline: 0; padding-inline: 0;
    background: transparent; backdrop-filter: none;
    padding-top: 1.5rem; padding-bottom: .5rem;
  }
  .topbar .title { font-size: 30px; }
  .topbar .back-btn { display: none; }
}

/* Standalone action buttons shouldn't stretch across the whole dashboard;
   buttons inside modal sheets and those marked .block stay full width. */
@media (min-width: 768px) {
  .btn { width: auto; min-width: 220px; }
  .sheet .btn, .btn.block { width: 100%; }
}

/* Wider screens: more KPI columns, bigger charts */
@media (min-width: 1280px) {
  .tile-grid { grid-template-columns: repeat(4, 1fr); }
  .stat-tile .value { font-size: 40px; }
}

/* ===== Small-phone tightening (avoid cramped / overflowing layout) ===== */
@media (max-width: 400px) {
  .app-content { padding-left: 1rem; padding-right: 1rem; }
  .topbar { margin-inline: -1rem; padding-inline: 1rem; gap: .4rem; }
  .topbar .title { font-size: 20px; }
  .field-row { gap: .45rem; }
  .field-row .input { padding-inline: .55rem; font-size: 15px; }
  .stat-tile { padding: .9rem .4rem; }
  .stat-tile .value { font-size: 25px; }
  .hero-card .hero-name { font-size: 21px; }
  .hero-stats { gap: .4rem; }
  .hero-stats .mini { padding: .5rem .2rem; }
  .hero-stats .mini .v { font-size: 18px; }
  .hero-stats .mini .l { font-size: 11.5px; }
  .seg-control a { font-size: 14px; padding: .5rem .3rem; }
  .list-row { padding: .8rem .85rem; gap: .65rem; }
  .list-row .row-icon { width: 42px; height: 42px; }
}

/* ===== Cards & tiles ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 1rem;
  border: 1px solid rgba(227, 232, 227, .6);
}

.section-title {
  font-size: 20px; font-weight: 700;
  margin: 1.5rem 0 .75rem;
  display: flex; align-items: center; gap: .5rem;
}
.section-title .count {
  background: #eaefe6; color: var(--muted);
  font-size: 13px; border-radius: 999px; padding: 0 .6rem; font-weight: 700;
}

.stack { display: flex; flex-direction: column; gap: .75rem; }

.tile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (min-width: 768px) { .tile-grid { grid-template-columns: repeat(4, 1fr); } }
.tile-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 420px) { .tile-grid.cols-3 { grid-template-columns: 1fr 1fr; } }

.stat-tile { text-align: center; padding: 1.1rem .6rem; }
.stat-tile .icon { color: var(--primary); }
.stat-tile .value { font-size: 30px; font-weight: 800; line-height: 1.2; }
@media (min-width: 768px) { .stat-tile .value { font-size: 36px; } }
.stat-tile .label { font-size: 13.5px; color: var(--muted); font-weight: 600; margin-top: 2px; }
.stat-tile.danger .value, .stat-tile.danger .icon { color: var(--danger); }
.stat-tile.success .value, .stat-tile.success .icon { color: var(--success); }
.stat-tile.info .value, .stat-tile.info .icon { color: var(--info); }

/* ===== Badges ===== */
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  border-radius: 999px; padding: .2rem .75rem;
  font-size: 13.5px; font-weight: 700; white-space: nowrap;
}
.badge.active { background: var(--primary-tint); color: var(--primary-dark); }
.badge.finished { background: #eceff0; color: var(--muted); }
.badge.due { background: var(--warning-tint); color: #92400E; }
.badge.danger { background: var(--danger-tint); color: var(--danger); }
.badge.info { background: var(--info-tint); color: var(--info); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: var(--touch);
  border-radius: var(--radius-btn);
  font-family: inherit; font-size: 18px; font-weight: 700;
  border: none; cursor: pointer; padding: .6rem 1.4rem;
  transition: filter .15s ease, background .15s ease;
  width: 100%;
}
@media (min-width: 768px) { .btn.fit { width: auto; } }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.secondary { background: transparent; color: var(--primary-dark); border: 2px solid var(--primary); }
.btn.secondary:hover { background: var(--primary-tint); }
.btn.danger-outline { background: transparent; color: var(--danger); border: 2px solid var(--danger-tint); }
.btn.danger-outline:hover { background: var(--danger-tint); }
.btn.sm { min-height: 42px; font-size: 15px; width: auto; padding: .3rem 1rem; border-radius: 11px; }

.fab {
  position: fixed; bottom: calc(var(--nav-h) + 18px); left: 18px; z-index: 45;
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(21, 128, 61, .35);
}
.fab:hover { filter: brightness(1.08); }
@media (min-width: 768px) { .fab { bottom: 28px; left: 28px; } }

/* ===== List rows ===== */
.list-row {
  display: flex; align-items: center; gap: .85rem;
  background: var(--surface);
  border-radius: var(--radius-card);
  border: 1px solid rgba(227, 232, 227, .6);
  box-shadow: var(--shadow);
  padding: .9rem 1rem;
  min-height: var(--touch);
}
a.list-row:hover { border-color: var(--primary-tint); }
.list-row .row-icon {
  width: 46px; height: 46px; border-radius: 13px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--primary-tint); color: var(--primary-dark);
}
.list-row .row-icon.amber { background: var(--warning-tint); color: #92400E; }
.list-row .row-icon.red { background: var(--danger-tint); color: var(--danger); }
.list-row .row-icon.blue { background: var(--info-tint); color: var(--info); }
.list-row .row-icon.grey { background: #eceff0; color: var(--muted); }
.list-row .row-body { flex: 1; min-width: 0; }
.list-row .row-title { font-weight: 700; font-size: 16.5px; }
.list-row .row-sub { font-size: 13.5px; color: var(--muted); margin-top: 1px; }
.list-row .row-end { text-align: left; flex-shrink: 0; }
.list-row .chevron { color: var(--muted); flex-shrink: 0; transform: scaleX(-1); }

/* ===== Segmented control / chips ===== */
.seg-control {
  display: flex; background: #eaefe6; border-radius: 999px; padding: 4px; gap: 4px;
}
.seg-control a {
  flex: 1; text-align: center; border-radius: 999px;
  padding: .55rem .5rem; font-weight: 700; font-size: 15px; color: var(--muted);
}
.seg-control a.active { background: var(--surface); color: var(--primary-dark); box-shadow: var(--shadow); }

.chip-row { display: flex; gap: .5rem; overflow-x: auto; padding: .25rem 0; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  border: 1.5px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: .35rem .95rem;
  font-size: 14.5px; font-weight: 600; color: var(--muted); white-space: nowrap; cursor: pointer;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ===== Alert banner ===== */
.alert-banner {
  display: flex; align-items: center; gap: .7rem;
  background: var(--warning-tint); color: #92400E;
  border: 1px solid #FDE68A;
  border-radius: var(--radius-card);
  padding: .85rem 1rem; font-weight: 700;
}
.alert-banner a { color: #92400E; text-decoration: underline; margin-right: auto; font-size: 15px; }

.toast-error {
  background: var(--danger-tint); color: var(--danger);
  border-radius: var(--radius-card); padding: .85rem 1rem;
  font-weight: 700; margin-top: 1rem;
}

/* ===== Forms ===== */
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.field label { font-weight: 700; font-size: 15.5px; }
.field .hint { font-size: 13px; color: var(--muted); }
.input, select.input, textarea.input {
  min-height: var(--touch);
  border: 1.5px solid var(--border); border-radius: 13px;
  background: var(--surface);
  font-family: inherit; font-size: 17px; color: var(--text);
  padding: .5rem .9rem; width: 100%;
}
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.input[readonly] { background: #f0f5ec; color: var(--primary-dark); font-weight: 700; }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: 0 13px 13px 0; flex: 1; min-width: 0; }
.field-row .input { min-width: 0; }
.input-group .suffix {
  display: grid; place-items: center; padding: 0 .9rem;
  background: #eaefe6; color: var(--muted); font-weight: 700; font-size: 15px;
  border: 1.5px solid var(--border); border-right: none; border-radius: 13px 0 0 13px;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .6rem; }

.switch { position: relative; display: inline-block; width: 52px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px;
  background: #d6dcd3; transition: .2s; cursor: pointer;
}
.switch .track::before {
  content: ""; position: absolute; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; top: 3px; right: 3px; transition: .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::before { transform: translateX(-22px); }

/* ===== Bottom sheet (mobile) / modal (desktop) ===== */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(22, 36, 28, .45);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.sheet {
  position: fixed; z-index: 95;
  right: 0; left: 0; bottom: 0;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 1.25rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  transform: translateY(105%); transition: transform .25s ease;
  box-shadow: 0 -8px 30px rgba(22, 36, 28, .18);
}
.sheet .sheet-handle {
  width: 44px; height: 5px; border-radius: 999px; background: var(--border);
  margin: 0 auto .9rem;
}
.sheet .sheet-title { font-size: 20px; font-weight: 800; margin-bottom: 1.1rem; }
.sheet-open .sheet-backdrop { opacity: 1; pointer-events: auto; }
.sheet.open { transform: translateY(0); }
body.sheet-open { overflow: hidden; }

@media (min-width: 768px) {
  .sheet {
    right: 50%; left: auto; bottom: auto; top: 50%;
    transform: translate(50%, -45%); opacity: 0; pointer-events: none;
    width: 520px; border-radius: 22px;
    transition: opacity .2s ease, transform .2s ease;
  }
  .sheet.open { transform: translate(50%, -50%); opacity: 1; pointer-events: auto; }
  .sheet .sheet-handle { display: none; }
}

/* ===== Hero cycle card ===== */
.hero-card {
  position: relative; overflow: hidden;
  padding: 1.25rem;
}
.hero-card::before {
  content: ""; position: absolute; top: 0; bottom: 0; right: 0; width: 6px;
  background: var(--primary);
  border-radius: 0 var(--radius-card) var(--radius-card) 0;
}
.hero-card .hero-head { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; }
.hero-card .hero-name { font-size: 24px; font-weight: 800; flex: 1; }
.hero-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: 1.1rem; }
.hero-stats .mini { text-align: center; background: var(--bg); border-radius: 13px; padding: .6rem .3rem; }
.hero-stats .mini .v { font-size: 20px; font-weight: 800; }
.hero-stats .mini .l { font-size: 12.5px; color: var(--muted); font-weight: 600; }

/* ===== Action cards grid (cycle hub) ===== */
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (min-width: 768px) { .action-grid { grid-template-columns: repeat(3, 1fr); } }
.action-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem;
  padding: 1.3rem .5rem; text-align: center; font-weight: 700; font-size: 16px;
}
.action-card .material-symbols-outlined { font-size: 32px; color: var(--primary); }
.action-card:hover { border-color: var(--primary); }

/* ===== Charts ===== */
.chart-box { position: relative; height: 220px; }
.chart-box.tall { height: 260px; }

/* chart pair: stacks on phones, side-by-side from tablet up */
.chart-row { display: grid; grid-template-columns: 1fr; gap: .75rem; }
@media (min-width: 560px) { .chart-row { grid-template-columns: 1fr 1fr; gap: 1rem; } }
.donut-legend { display: flex; flex-wrap: wrap; gap: .4rem .9rem; margin-top: .75rem; justify-content: center; }
.donut-legend span { font-size: 13.5px; color: var(--muted); font-weight: 600; display: inline-flex; align-items: center; gap: .35rem; }
.donut-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* ===== Empty state ===== */
.empty-state {
  text-align: center; padding: 3.5rem 1.5rem; color: var(--muted);
}
.empty-state .material-symbols-outlined { font-size: 62px; color: #becabc; }
.empty-state p { margin-top: .75rem; font-weight: 600; }

/* ===== Notifications ===== */
.notif-row { align-items: flex-start; }
.notif-row.unread { border-right: 4px solid var(--primary); }
.notif-row .time { font-size: 12.5px; color: var(--muted); }

/* ===== Report ===== */
.report-section h3 { font-size: 18px; margin-bottom: .75rem; display: flex; align-items: center; gap: .5rem; }
.report-kv { display: flex; justify-content: space-between; padding: .45rem 0; border-bottom: 1px dashed var(--border); font-size: 15.5px; }
.report-kv:last-child { border-bottom: none; }
.report-kv .k { color: var(--muted); font-weight: 600; }
.report-kv .v { font-weight: 800; }
.profit-big { font-size: 34px; font-weight: 800; text-align: center; padding: .5rem 0; }
.pos { color: var(--success); }
.neg { color: var(--danger); }

@media print {
  .bottom-nav, .sidebar, .fab, .topbar .back-btn, .no-print { display: none !important; }
  .app-content { margin: 0; max-width: none; padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid var(--border); }
}

/* =====================================================================
   Desktop dashboard enhancements — placed LAST so they win over the
   base .stack/.card/.action-grid rules (media queries add no specificity,
   so source order decides).
   ===================================================================== */
@media (min-width: 768px) {
  /* Lists render as a responsive card grid, not one stretched column.
     Inside the narrow modal sheet this collapses back to a single column. */
  .app-content .stack {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1rem;
    align-items: start;
  }
  .sheet .stack { display: flex; }

  /* Room to breathe on big screens */
  .card { padding: 1.25rem; }
  .section-title { font-size: 22px; margin-top: 2rem; }
  .chart-box { height: 300px; }

  /* All six cycle-hub action cards in one row */
  .action-grid { grid-template-columns: repeat(6, 1fr); }
}

@media (min-width: 1280px) {
  .stat-tile .value { font-size: 40px; }
}
