:root {
  --primary: #14285A;
  --primary-dark: #0B1A3D;
  --accent: #D9B45A;
  --accent-text: #8A6A1F;
  --accent-soft: #FBF3DF;
  --bg: #F4F5F8;
  --card: #FFFFFF;
  --text: #1B1F2A;
  --muted: #4A5163;
  --line: #E6E9F0;
  --line-strong: #C4C9D6;
  --danger: #B42318;
  --danger-soft: #FEF3F2;
  --success: #1E7A3E;
  --success-soft: #E7F5EC;
  --info-soft: #E8ECF6;
  --shadow: 0 1px 2px rgba(20, 40, 90, 0.08);
  --radius: 14px;
  --font: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, system-ui, sans-serif;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0F1420;
  --card: #1A2131;
  --text: #E8EBF2;
  --muted: #A3AABB;
  --line: #2A3347;
  --line-strong: #3B4660;
  --danger-soft: #3A1714;
  --success-soft: #12301E;
  --info-soft: #1F2A44;
  --accent-soft: #3A3018;
  --accent-text: #E5C677;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
.hidden { display: none !important; }

/* layout */
.shell { min-height: 100%; display: flex; }
.sidebar { display: none; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; padding-bottom: 76px; }
.page { width: 100%; max-width: 760px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.topbar { background: var(--primary); color: #fff; padding: 18px 16px 52px; }
.topbar-inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: baseline; gap: 6px; }
.brand b { font-size: 22px; color: var(--accent); }
.brand span { font-size: 13px; color: #C7CDE0; }
.brand img { height: 32px; }
.overlap { margin-top: -40px; }
.subbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.subbar-inner { max-width: 760px; margin: 0 auto; padding: 8px 12px; display: flex; align-items: center; gap: 8px; min-height: 60px; }
.subbar h1 { font-size: 17px; font-weight: 600; flex: 1; }

.bottomnav { position: fixed; inset: auto 0 0 0; background: var(--card); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); padding: 6px 4px calc(8px + env(safe-area-inset-bottom)); z-index: 10; }
.navlink { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 48px; font-size: 11px; color: var(--muted); position: relative; }
.navlink.active { color: var(--primary); font-weight: 600; }
[data-theme="dark"] .navlink.active { color: var(--accent); }
.navlink .fab { width: 48px; height: 48px; border-radius: 16px; background: var(--accent); color: var(--primary); display: flex; align-items: center; justify-content: center; }
.dot { position: absolute; top: 2px; inset-inline-start: calc(50% + 4px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

@media (min-width: 900px) {
  .bottomnav { display: none; }
  .main { padding-bottom: 0; }
  .sidebar { display: flex; flex-direction: column; gap: 20px; width: 240px; flex-shrink: 0; background: var(--primary); color: #fff; padding: 24px 14px; position: sticky; top: 0; height: 100vh; }
  .sidebar .navlink { flex-direction: row; justify-content: flex-start; gap: 10px; font-size: 14px; color: #C7CDE0; padding: 10px 12px; border-radius: 10px; min-height: 44px; }
  .sidebar .navlink.active { background: rgba(217, 180, 90, 0.18); color: #fff; }
  .sidebar .dot { position: static; margin-inline-start: auto; }
  .sidebar .navlink .fab { width: auto; height: auto; background: none; color: inherit; }
}

/* components */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.card.flush { padding: 0; overflow: hidden; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat b { display: block; font-size: 22px; color: var(--primary); }
[data-theme="dark"] .stat b { color: var(--accent); }
.stat span { font-size: 12px; color: var(--muted); }
.section-title { font-size: 15px; font-weight: 600; color: var(--primary); display: flex; align-items: center; gap: 8px; }
[data-theme="dark"] .section-title { color: var(--accent); }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.title { font-size: 15px; font-weight: 600; }
.big-title { font-size: 20px; font-weight: 700; color: var(--primary); }
[data-theme="dark"] .big-title { color: var(--text); }
.empty { text-align: center; color: var(--muted); padding: 24px 12px; font-size: 14px; }

.tag { display: inline-flex; align-items: center; font-size: 11px; font-weight: 600; border-radius: 6px; padding: 2px 8px; white-space: nowrap; background: var(--info-soft); color: var(--primary); }
[data-theme="dark"] .tag { color: var(--text); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.gold { background: var(--accent-soft); color: var(--accent-text); }
.tag.success { background: var(--success-soft); color: var(--success); }
.tag.gray { background: var(--bg); color: var(--muted); }

.btn { height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--card); font-weight: 600; font-size: 14px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.gold { background: var(--accent); border-color: var(--accent); color: var(--primary); }
.btn.danger { color: var(--danger); border-color: #F5C2BD; }
.btn.block { width: 100%; }
.btn.lg { height: 50px; font-size: 15px; }
.btn.icon { width: 44px; padding: 0; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-row { display: flex; gap: 8px; }
.btn-row > .btn { flex: 1; }
.iconbtn { width: 44px; height: 44px; border-radius: 12px; border: none; background: rgba(255, 255, 255, 0.12); color: #fff; display: inline-flex; align-items: center; justify-content: center; position: relative; cursor: pointer; }
.iconbtn .dot { top: 4px; inset-inline-start: auto; inset-inline-end: 4px; background: var(--accent); color: var(--primary); }
.back { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border: none; background: none; cursor: pointer; color: var(--primary); }
[data-theme="dark"] .back { color: var(--text); }
[dir="ltr"] .flip { transform: scaleX(-1); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--primary); }
[data-theme="dark"] .field label { color: var(--text); }
.input, select.input, textarea.input { width: 100%; min-height: 46px; border: 1px solid var(--line-strong); border-radius: 12px; padding: 10px 12px; background: var(--card); font-size: 15px; }
textarea.input { resize: vertical; min-height: 90px; line-height: 1.6; }
.input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); border-radius: 10px; padding: 8px 12px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; }

.task-card { display: flex; flex-direction: column; gap: 8px; cursor: pointer; }
.progress { flex: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--primary); }
[data-theme="dark"] .progress > i { background: var(--accent); }
.banner { display: flex; align-items: center; gap: 12px; background: var(--danger-soft); border: 1px solid #F5C2BD; border-radius: var(--radius); padding: 12px 14px; color: var(--danger); cursor: pointer; }
.banner.info { background: var(--info-soft); border-color: transparent; color: var(--primary); }
[data-theme="dark"] .banner.info { color: var(--text); }

.part { padding: 12px 14px; display: flex; gap: 10px; border-bottom: 1px solid var(--line); }
.part:last-child { border-bottom: none; }
.part.me { background: var(--accent-soft); }
.status-ic { width: 26px; height: 26px; border-radius: 13px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; border: 2px solid var(--line-strong); }
.status-ic.done { background: var(--success-soft); border-color: transparent; color: var(--success); }
.status-ic.review { border-color: var(--primary); color: var(--primary); }
.status-ic.prog { border-color: var(--accent); }
.status-ic.blocked, .status-ic.rejected { border-color: var(--danger); color: var(--danger); }
.quote { background: var(--bg); border-radius: 10px; padding: 8px 10px; font-size: 13px; line-height: 1.6; white-space: pre-wrap; }

.list-item { display: flex; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); align-items: flex-start; cursor: pointer; }
.list-item:last-child { border-bottom: none; }
.list-item.unread { background: var(--info-soft); }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tab { height: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--line-strong); background: var(--card); font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer; }
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.stars { display: flex; gap: 6px; justify-content: center; }
.star { width: 44px; height: 44px; border: none; background: none; color: var(--line-strong); cursor: pointer; padding: 0; }
.star.on { color: var(--accent); }

/* modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(11, 26, 61, 0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal { background: var(--card); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; max-height: 92vh; overflow: auto; }
@media (min-width: 600px) { .modal-back { align-items: center; } .modal { border-radius: 18px; } }
.modal h2 { font-size: 17px; }
.toast { position: fixed; bottom: calc(90px + env(safe-area-inset-bottom)); inset-inline: 16px; margin: 0 auto; max-width: 420px; background: #1B1F2A; color: #fff; border-radius: 12px; padding: 12px 16px; font-size: 14px; z-index: 60; text-align: center; }
.toast.error { background: var(--danger); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: var(--primary); }
.auth .card { width: 100%; max-width: 400px; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.auth .brand { justify-content: center; }
.auth .brand b { font-size: 30px; }
.auth .brand span { color: var(--muted); }
.link { color: var(--primary); font-weight: 600; background: none; border: none; cursor: pointer; padding: 8px 0; font-size: 14px; }
[data-theme="dark"] .link { color: var(--accent); }
table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple td, table.simple th { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: start; }
@media (min-width: 900px) { .topbar .brand { visibility: hidden; } }
