/* ===== Design tokens ===== */
:root {
  --bg: #F6F3EC;
  --surface: #FFFFFF;
  --surface-2: #FBF9F4;
  --ink: #1C2333;
  --ink-soft: #5B6478;
  --ink-faint: #8B93A3;
  --accent: #B8860B;
  --accent-deep: #8C6608;
  --accent-soft: #F3E7C8;
  --success: #2F7D5B;
  --success-soft: #E3F1EA;
  --danger: #C0392B;
  --danger-soft: #FBEAE7;
  --info: #3D5A80;
  --info-soft: #E7EEF5;
  --border: #E6E1D4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28,35,51,0.04), 0 4px 16px rgba(28,35,51,0.05);
  --font-display: 'Tajawal', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
  --nav-h: 58px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 15px;
  line-height: 1.6;
  direction: ltr;
  min-height: 100vh;
  /* Prevent horizontal scroll on mobile */
  overflow-x: hidden;
}
a { color: var(--accent-deep); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-weight: 700; margin: 0 0 .4em; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; color: var(--ink-soft); }
.mono { font-family: var(--font-mono); }
.container { max-width: 1080px; margin: 0 auto; padding: 0 20px 80px; }

/* ===== Top nav ===== */
.topnav {
  background: var(--ink);
  color: #fff;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}
.topnav-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 14px; height: var(--nav-h);
  position: relative;
}
.brand { font-weight: 800; font-size: 1.05rem; color: #fff; display:flex; align-items:center; gap:8px; flex-shrink:0; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); display:inline-block; }

/* Nav links — scrollable row on all screens */
.nav-links {
  display: flex; gap: 2px; flex: 1;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
}
.nav-links::-webkit-scrollbar { display: none; }
.nav-links a {
  color: rgba(255,255,255,0.72); padding: 8px 11px; border-radius: 8px;
  font-size: .88rem; font-weight: 600; white-space: nowrap; flex-shrink:0;
}
.nav-links a:hover { color: #fff; text-decoration: none; background: rgba(255,255,255,0.08); }
.nav-links a.active { color: var(--ink); background: var(--accent); }
.nav-right { display: flex; align-items: center; gap: 10px; flex-shrink:0; }
.bell { position: relative; color: #fff; font-size: 1.15rem; }
.bell .badge {
  position: absolute; top: -6px; right: -8px; background: var(--danger); color: #fff;
  font-size: .65rem; font-weight: 700; border-radius: 99px; padding: 1px 5px; line-height: 1.4;
}
.who { font-size: .82rem; color: rgba(255,255,255,0.75); }
.who:hover { text-decoration: none; opacity: .85; }
.who b { color: #fff; }
.who .who-name { display: inline; }
.logout-btn {
  background: none; border: 1px solid rgba(255,255,255,0.25); color: rgba(255,255,255,0.85);
  padding: 5px 10px; border-radius: 7px; font-size: .82rem; cursor: pointer;
  font-family: var(--font-display); white-space: nowrap;
}
.logout-btn:hover { border-color: #fff; color: #fff; }

/* ===== Page header ===== */
.page-head { padding: 22px 0 16px; }
.page-head .eyebrow { color: var(--accent-deep); font-weight: 700; font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 4px; }
.page-head p { margin: 0; }

/* ===== Cards / surfaces ===== */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.card-tight { padding: 12px 14px; }

/* ===== Grid ===== */
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

/* ===== Stats ===== */
.stat { display:flex; flex-direction:column; gap:4px; }
.stat .num { font-family: var(--font-mono); font-size: 1.7rem; font-weight: 700; color: var(--ink); }
.stat .label { font-size: .82rem; color: var(--ink-faint); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; cursor: pointer;
  font-family: var(--font-display); font-weight: 700; font-size: .88rem;
  padding: 10px 16px; border-radius: 8px; transition: transform .06s ease;
  /* Minimum tap target size on mobile */
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-deep); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: var(--surface-2); color: var(--ink); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-sm { padding: 6px 12px; font-size: .8rem; min-height: 36px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ===== Forms ===== */
label { display:block; font-size:.84rem; font-weight:700; color: var(--ink-soft); margin-bottom:5px; }
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%; font-family: var(--font-display); font-size: .95rem; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--ink);
  /* Prevent iOS zoom on focus (font-size must be ≥16px on mobile) */
  -webkit-appearance: none; appearance: none;
}
input[type="checkbox"], input[type="radio"] {
  width: auto; cursor: pointer; accent-color: var(--accent);
  width: 18px; height: 18px;
}
input:not([type="checkbox"]):not([type="radio"]):focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: 0; background: #fff;
}
.field { margin-bottom: 14px; }
.inline-fields { display:flex; gap: 10px; flex-wrap: wrap; }
.inline-fields > * { flex: 1; min-width: 140px; }
.checkbox-row { display:flex; gap:8px; flex-wrap:wrap; }
.checkbox-row label {
  display:flex; align-items:center; gap:5px; font-weight:600;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 7px; padding: 8px 12px; font-size:.82rem; cursor:pointer;
  min-height: 40px;
}
.checkbox-row input { width: auto; }

/* ===== File input — custom style with camera capture support ===== */
.file-input-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.file-input-wrap input[type="file"] {
  /* Keep native input for accessibility but style it consistently */
  padding: 8px;
  cursor: pointer;
  font-size: .85rem;
  background: var(--surface-2);
  min-height: 44px;
}
/* On mobile: show a full-width tappable area for file/camera */
.file-input-wrap input[type="file"]::-webkit-file-upload-button {
  background: var(--accent-soft);
  color: var(--accent-deep);
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: .82rem;
  cursor: pointer;
  margin-right: 8px;
}

/* ===== Badges / status pills ===== */
.pill { display:inline-flex; align-items:center; gap:5px; font-size:.74rem; font-weight:700; padding: 3px 10px; border-radius: 99px; }
.pill-pending { background: var(--info-soft); color: var(--info); }
.pill-active { background: var(--accent-soft); color: var(--accent-deep); }
.pill-success { background: var(--success-soft); color: var(--success); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-muted { background: #EEE; color: #777; }

/* ===== Tables — horizontal scroll on small screens ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; min-width: 420px; }
th, td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--ink-faint); font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
tr:hover td { background: var(--surface-2); }

/* ===== Target gauge ===== */
.gauge-wrap { margin: 10px 0; }
.gauge-track {
  position: relative; height: 26px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 99px; overflow: hidden;
}
.gauge-fill {
  position: absolute; top: 0; left: 0; height: 100%;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent));
  border-radius: 99px; transition: width .4s ease;
}
.gauge-labels { display:flex; justify-content: space-between; font-family: var(--font-mono); font-size:.78rem; color: var(--ink-faint); margin-top:6px; }
.gauge-pct { font-family: var(--font-mono); font-weight:700; color: var(--ink); }

/* ===== Notification list ===== */
.notif-item { display:flex; gap:10px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.notif-item:last-child { border-bottom: none; }
.notif-dot { width:8px; height:8px; border-radius:50%; background: var(--accent); margin-top:6px; flex-shrink:0; }
.notif-time { font-size:.74rem; color: var(--ink-faint); }

/* ===== Misc ===== */
.muted { color: var(--ink-faint); font-size:.84rem; }
.empty-state { text-align:center; padding: 40px 10px; color: var(--ink-faint); }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.flash-error { background: var(--danger-soft); color: var(--danger); padding: 10px 14px; border-radius: 8px; font-size:.85rem; margin-bottom:14px; font-weight:600; }
.tabs { display:flex; gap:4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; font-weight:700; font-size:.88rem; color: var(--ink-faint); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); }
.msg-bubble { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.msg-bubble.delivery { background: var(--success-soft); border-color: var(--success); }
.attach-chip { display:inline-flex; align-items:center; gap:6px; background:#fff; border:1px solid var(--border);
  border-radius:7px; padding:5px 10px; font-size:.78rem; margin: 4px 6px 0 0; }

/* ===== Live notification toast ===== */
.notif-toast {
  position: fixed; bottom: 22px; left: 16px; right: 16px; max-width: 380px;
  background: var(--ink); color: #fff; padding: 13px 16px; border-radius: 10px;
  font-size: .88rem; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  opacity: 0; transform: translateY(12px); transition: opacity .25s ease, transform .25s ease;
  z-index: 999;
}
.notif-toast.show { opacity: 1; transform: translateY(0); }

/* ===== Bottom nav bar on mobile (replaces cramped top links) ===== */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  background: var(--ink);
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: env(safe-area-inset-bottom, 0) 0 0;
}
.bottom-nav-inner {
  display: flex;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.bottom-nav-inner::-webkit-scrollbar { display: none; }
.bottom-nav-inner a {
  flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 14px 8px;
  color: rgba(255,255,255,0.6);
  font-size: .68rem; font-weight: 700; text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  min-width: 56px;
}
.bottom-nav-inner a .nav-icon { font-size: 1.3rem; line-height: 1; }
.bottom-nav-inner a.active { color: var(--accent); }
.bottom-nav-inner a:hover { text-decoration: none; color: #fff; }

/* ===== RESPONSIVE BREAKPOINTS ===== */

/* Tablet: 481px–900px */
@media (max-width: 900px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  h1 { font-size: 1.4rem; }
}

/* Mobile: ≤480px */
@media (max-width: 480px) {
  :root { --nav-h: 52px; }

  /* Larger base font so iOS doesn't zoom on input focus */
  input:not([type="checkbox"]):not([type="radio"]), select, textarea { font-size: 16px; }

  .container { padding: 0 12px 90px; } /* bottom padding for bottom-nav */
  .card { padding: 14px; }
  .card-tight { padding: 10px 12px; }

  h1 { font-size: 1.25rem; }
  h2 { font-size: 1.1rem; }
  h3 { font-size: 1rem; }

  /* Grid always single column on mobile */
  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  /* Stack inline-fields vertically on very narrow screens */
  .inline-fields { flex-direction: column; }
  .inline-fields > * { min-width: unset; }

  /* Hide the top nav-links row — replaced by bottom nav */
  .nav-links { display: none; }

  /* Compact nav-right */
  .who .who-name { display: none; } /* show avatar/first letter only */
  .logout-btn { display: none; } /* log out is in the bottom nav */

  /* Show bottom nav */
  .bottom-nav { display: block; }

  /* Full-width primary action buttons */
  .page-head .btn { width: 100%; }

  /* Tables scroll horizontally */
  table { font-size: .82rem; }
  th, td { padding: 8px 6px; }

  /* Countdown timer smaller on mobile */
  .countdown { font-size: 1.4rem !important; }

  /* Stat cards */
  .stat .num { font-size: 1.4rem; }

  /* Gauge label only shows percent on mobile */
  .gauge-labels span:first-child,
  .gauge-labels span:last-child { display: none; }

  /* Toast full width on mobile */
  .notif-toast { left: 10px; right: 10px; max-width: unset; }
}

/* Tall phones — give a bit more padding */
@media (max-width: 480px) and (min-height: 800px) {
  .page-head { padding-top: 16px; }
}

/* iPad / tablet: 481px–768px (two-column stays, some spacing tightening) */
@media (min-width: 481px) and (max-width: 768px) {
  .container { padding: 0 16px 60px; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .inline-fields { flex-wrap: wrap; }
}
