/* سفر | Safar — RTL, offline, mobile-first */
:root {
  --accent: #0e7490;
  --accent-strong: #155e75;
  --accent-soft: #cffafe;
  --hero-from: #0e7490;
  --hero-to: #155e75;
  --accent-btn: #0e7490;
  --bg: #f6f8fa;
  --surface: #ffffff;
  --text: #1f2937;
  --text-dim: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --ok: #16a34a;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .05);
  --radius: 14px;
}
[data-theme="dark"] {
  --accent: #22d3ee;
  --accent-strong: #67e8f9;
  --accent-soft: #164e63;
  --hero-from: #155e75;
  --hero-to: #134e4a;
  --accent-btn: #0e7490;
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0, 0, 0, .35), 0 4px 14px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Tahoma, "Noto Kufi Arabic", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
/* Theme transition only after first paint: avoids a mid-transition flash when a stored dark theme applies at load. */
body.theme-ready { transition: background .25s, color .25s; }

/* Header */
.app-header {
  background: linear-gradient(135deg, var(--hero-from), var(--hero-to));
  color: #fff;
  padding: 18px 16px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-icon { font-size: 30px; }
.brand-name { margin: 0; font-size: 24px; font-weight: 800; }
.brand-en { font-size: 14px; font-weight: 600; opacity: .8; letter-spacing: .4px; }
.brand-sub { margin: 0; font-size: 12.5px; opacity: .92; }
.header-actions { display: flex; gap: 6px; }
.icon-btn {
  background: rgba(255, 255, 255, .16);
  border: none;
  color: #fff;
  font-size: 17px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .2s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .3); }
.icon-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

/* Layout */
.container { max-width: 860px; margin: 0 auto; padding: 18px 14px 60px; }
section { margin-bottom: 18px; }
h2 { font-size: 17px; margin: 0 0 10px; }

/* Trips bar */
.trips-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.trips-list {
  display: flex;
  gap: 8px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}
.trip-chip {
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: all .18s;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trip-chip[aria-pressed="true"] {
  background: var(--accent-btn);
  border-color: var(--accent-btn);
  color: #fff;
  font-weight: 700;
}
.trip-chip:hover { border-color: var(--accent); }
.trip-chip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Countdown */
.countdown-card {
  background: linear-gradient(135deg, var(--hero-from), var(--hero-to));
  color: #fff;
  border-radius: var(--radius);
  padding: 20px 18px;
  box-shadow: var(--shadow);
  text-align: center;
}
.cd-title { margin: 0; font-size: 20px; color: #fff; overflow-wrap: anywhere; }
.cd-meta { margin: 4px 0 14px; font-size: 13.5px; opacity: .93; }
.countdown-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cd-cell {
  background: rgba(255, 255, 255, .14);
  border-radius: 12px;
  padding: 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cd-num { font-size: clamp(24px, 7vw, 38px); font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.cd-label { font-size: 12px; opacity: .9; }
.cd-state { margin: 12px 0 0; font-size: 14px; font-weight: 600; min-height: 1.4em; }

/* Progress */
.progress-card, .categories .cat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.progress-head { display: flex; justify-content: space-between; align-items: center; }
.progress-text { font-weight: 800; color: var(--accent); font-size: 18px; font-variant-numeric: tabular-nums; }
.progress-track {
  height: 12px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--ok));
  border-radius: 999px;
  transition: width .45s ease;
}
.progress-hint { margin: 8px 0 0; font-size: 13px; color: var(--text-dim); }

/* Checklist */
.list-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.list-tools { display: flex; gap: 8px; }
.cat-card { margin-bottom: 14px; }
.cat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  padding: 2px 0;
}
.cat-head h3 { margin: 0; font-size: 15.5px; flex: 1; }
.cat-icon { display: inline-flex; align-items: center; color: var(--accent); }
.cat-icon svg { width: 19px; height: 19px; }
.cat-count { font-size: 12.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.cat-caret { transition: transform .2s; color: var(--text-dim); font-size: 12px; }
.cat-head:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 8px; }
.cat-card.collapsed .cat-caret { transform: rotate(-90deg); }
.cat-card.collapsed .cat-items { display: none; }
.cat-items { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  transition: background .15s, opacity .15s;
}
.item-row:hover { background: var(--accent-soft); }
.item-row.done { opacity: .62; }
.item-row.done .item-label { text-decoration: line-through; }
.item-check {
  appearance: none;
  width: 22px;
  height: 22px;
  border: 2px solid var(--accent);
  border-radius: 7px;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-content: center;
  background: var(--surface);
  margin: 0;
}
.item-check:checked { background: var(--accent); }
.item-check:checked::after { content: "✓"; color: #fff; font-size: 14px; font-weight: 800; }
.item-check:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.item-label { flex: 1; font-size: 14.5px; cursor: pointer; overflow-wrap: anywhere; }
.item-del {
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 15px;
  padding: 4px 6px;
  border-radius: 6px;
}
.item-del:hover { color: var(--danger); background: rgba(220, 38, 38, .1); }

/* Add item */
.add-item { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.add-item input[type="text"] { flex: 1; min-width: 160px; }
.add-item select { max-width: 160px; }

/* Forms */
input[type="text"], input[type="datetime-local"], select, textarea {
  font-family: inherit;
  font-size: 14.5px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
label { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; font-weight: 600; margin-bottom: 12px; }

/* Buttons */
.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all .18s;
}
.btn-primary { background: var(--accent-btn); color: #fff; }
.btn-primary:hover { background: var(--hero-from); }
.btn-ghost { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.danger-zone { text-align: center; margin-top: 26px; }

/* Modal */
.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: min(440px, 92vw);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal::backdrop { background: rgba(15, 23, 42, .55); }
.modal-body { padding: 22px; }
.modal-body h2 { margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  inset-inline-start: 50%;
  transform: translateX(50%) translateY(80px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transition: all .3s;
  pointer-events: none;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(50%) translateY(0); }
.toast-undo {
  font-family: inherit;
  border: none;
  background: none;
  color: var(--accent);
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  margin-inline-start: 12px;
  padding: 2px 8px;
  border-radius: 6px;
}
[data-theme="dark"] .toast-undo { color: #7dd3fc; }
[data-theme="dark"] .progress-fill { background: linear-gradient(90deg, #0891b2, #22c55e); }
.toast-undo:hover { text-decoration: underline; }
.toast-undo:focus-visible { outline: 2px solid currentColor; }

.empty-note { text-align: center; color: var(--text-dim); padding: 30px 10px; font-size: 15px; }

@media (max-width: 560px) {
  .brand-sub { display: none; }
  .countdown-grid { gap: 6px; }
  .list-head { flex-direction: column; align-items: stretch; }
  .list-tools { justify-content: stretch; }
  .list-tools .btn { flex: 1; }
}

@media print {
  .app-header, .trips-bar, .add-item, .danger-zone, .list-tools, .item-del,
  .countdown-grid, .cd-state, .toast, .progress-card { display: none !important; }
  body { background: #fff; color: #000; }
  .countdown-card { box-shadow: none; border: none; color: #000; background: #fff; padding: 0 0 10px; text-align: start; }
  .cat-card { box-shadow: none; border: 1px solid #ccc; color: #000; background: #fff; break-inside: avoid; }
  .cd-title, .cd-meta { color: #000; }
  .item-row { border-color: #999; }
  .item-check { border-color: #000; }
  .item-row.done .item-label { text-decoration: line-through; }
}
