:root {
  --bg: #0f0f0f;
  --bg-gradient: linear-gradient(135deg, #0f0f0f 0%, #1a1a1a 50%, #0f0f0f 100%);
  --surface: #1a1a1a;
  --surface-gradient: linear-gradient(145deg, #222222 0%, #1a1a1a 100%);
  --ink: #ffffff;
  --ink-1: #ffffff;
  --ink-2: #e0e0e0;
  --ink-3: #bfbfbf;
  --muted: #bfbfbf;
  --muted-2: #888888;
  --line: rgba(255,255,255,0.08);
  --line-2: rgba(255,255,255,0.12);
  --brand: #8B0101;
  --brand-2: #a50101;
  --brand-tint: rgba(139,1,1,0.12);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.4);
  --shadow: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.6);
  --shadow-glow: 0 0 15px rgba(139,1,1,0.25);
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --radius: 12px;
  --glass: rgba(255, 255, 255, 0.03);
  --glass-border: rgba(255, 255, 255, 0.08);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-feature-settings: 'ss01', 'cv11';
  background: var(--bg-gradient);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.arabic {
  font-family: 'Noto Sans Arabic', 'Inter', sans-serif;
  direction: rtl;
  unicode-bidi: isolate;
}

/* Layout */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

/* Sidebar */
.sidebar {
  background: rgba(18, 18, 18, 0.98);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--line);
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  z-index: 100;
  box-shadow: 10px 0 30px rgba(0,0,0,0.5);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 14px;
  border-bottom: 1px solid var(--line);
}
.brand img { height: 26px; width: auto; display: block; }
.brand-text {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.brand-text strong { color: var(--ink); display: block; font-size: 12px; letter-spacing: 0.04em; }

.nav { display: flex; flex-direction: column; gap: 1px; flex: 1; }
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 5px;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 450;
  transition: all 120ms ease;
}
.nav a:hover { background: var(--bg); color: var(--ink); }
.nav a.active { background: var(--brand-tint); color: var(--brand); font-weight: 500; }
.nav a .num {
  font-variant-numeric: tabular-nums;
  color: var(--muted-2);
  font-size: 11px;
  min-width: 18px;
}
.nav a.active .num { color: var(--brand); }
.nav a .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--line-2);
  margin-left: auto;
}
.nav a.filled .dot { background: var(--ok); }

/* Main */
.main { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  background: rgba(15,15,15,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 14px 32px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 50;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #fff;
}
.topbar-title .sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}
.save-status {
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}
.save-status .pulse {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 6px var(--ok);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 5px;
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 120ms ease;
  font-family: inherit;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink-2); }
.btn-primary {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}
.btn-primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--ink); background: var(--bg); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Content */
.content {
  max-width: 1100px;
  padding: 32px 40px 120px;
}
@media (max-width: 720px) {
  .content { padding: 20px 18px 120px; }
  .topbar { padding: 12px 16px; }
}

section.sec {
  background: var(--surface-gradient);
  border: 1px solid var(--line);
  border-radius: 18px;
  margin-bottom: 24px;
  overflow: hidden;
  scroll-margin-top: 90px;
  box-shadow: var(--shadow);
  animation: slideUp 0.5s ease-out both;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
section.sec:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}
.sec-head {
  padding: 18px 24px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  background: linear-gradient(135deg, #8B0101, #6b0000);
  color: white;
  position: relative;
  overflow: hidden;
}
.sec-head::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}
section.sec:hover .sec-head::after {
  transform: translateX(100%);
}
.sec-head .num {
  color: rgba(255,255,255,.6);
  font-size: 11px;
  letter-spacing: 0.12em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: rgba(0,0,0,0.2);
  padding: 2px 8px;
  border-radius: 4px;
}
.sec-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: white;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.sec-head .ar {
  font-size: 14px;
  color: rgba(255,255,255,.8);
  margin-left: auto;
}
.sec-body { padding: 24px 24px; background: rgba(0,0,0,0.1); }

/* Fields */
.field-grid {
  display: grid;
  gap: 14px 18px;
}
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-6 { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 720px) {
  .cols-2, .cols-3, .cols-4, .cols-6 { grid-template-columns: 1fr 1fr; }
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field.span-2 { grid-column: span 2; }
.field label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-2);
  display: flex;
  align-items: baseline;
  gap: 8px;
  line-height: 1.2;
}
.field label .ar {
  font-size: 11px;
  color: var(--muted-2);
  font-weight: 400;
}
.field input, .field select, .field textarea {
  font-family: inherit;
  font-size: 13.5px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.2);
  color: var(--ink);
  border-radius: 8px;
  outline: none;
  transition: all 0.2s ease;
  width: 100%;
}
.field input:hover, .field select:hover, .field textarea:hover {
  border-color: rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.25);
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(139,1,1,0.15);
}
.field textarea { resize: vertical; min-height: 70px; line-height: 1.5; }
.field input[type="number"] { font-variant-numeric: tabular-nums; }

/* Tables */
.tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
}
.tbl th {
  text-align: left;
  font-weight: 600;
  color: var(--ink-2);
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--gray-block);
  white-space: nowrap;
}
.tbl th .ar { display: block; text-transform: none; color: var(--muted-2); font-size: 10.5px; font-weight: 400; letter-spacing: 0; }
.tbl td {
  padding: 4px 4px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.tbl td:first-child { padding-left: 10px; }
.tbl td:last-child { padding-right: 10px; }
.tbl td input, .tbl td select {
  border: 1px solid rgba(255,255,255,0.07);
  background: rgba(255,255,255,0.04);
  padding: 6px 7px;
  font-size: 13px;
  width: 100%;
  font-family: inherit;
  color: var(--ink);
  border-radius: 4px;
}
.tbl td input:hover, .tbl td select:hover {
  background: rgba(255,255,255,0.09);
  border-color: rgba(255,255,255,0.13);
}
.tbl td input:focus, .tbl td select:focus {
  border-color: var(--brand);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 0 0 2px rgba(139,26,26,.14);
  outline: none;
}
/* Native dropdown options — dark bg so text is readable in OS popup */
.tbl td select option,
.field select option {
  background: #1a1a1a;
  color: #ffffff;
}
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.total-row td {
  background: var(--bg);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border-top: 1px solid var(--line-2);
}
.tbl .rowlabel {
  font-size: 12px;
  color: var(--ink-2);
  padding: 6px 8px;
  white-space: nowrap;
}
.tbl .rowlabel .ar { color: var(--muted); font-size: 11px; display: block; }
.tbl .idx { color: var(--muted-2); width: 28px; text-align: center; font-variant-numeric: tabular-nums; font-size: 11.5px; }
.tbl .num-cell input { text-align: right; font-variant-numeric: tabular-nums; }

.tbl-wrap { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }

/* Checkbox list */
.check-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 16px;
}
@media (max-width: 720px) { .check-grid { grid-template-columns: 1fr; } }
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  transition: all 120ms ease;
  user-select: none;
}
.check:hover { border-color: var(--line-2); background: var(--bg); }
.check input { margin: 0; accent-color: var(--brand); width: 15px; height: 15px; }
.check input:checked + .check-label { color: var(--ink); font-weight: 500; }
.check-label { color: var(--ink-2); flex: 1; }
.check-label .ar { color: var(--muted); font-size: 12px; margin-left: 4px; }
.check.on { border-color: var(--brand); background: var(--brand-tint); }

/* Weather buttons */
.weather-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
@media (max-width: 720px) { .weather-grid { grid-template-columns: repeat(2, 1fr); } }
.weather-opt {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
  font-size: 12.5px;
  background: var(--surface);
  transition: all 120ms ease;
  text-align: left;
  font-family: inherit;
  color: var(--ink-2);
}
.weather-opt:hover { border-color: var(--line-2); background: var(--bg); }
.weather-opt.on {
  border-color: var(--brand);
  background: var(--brand-tint);
  color: var(--brand);
  font-weight: 500;
}
.weather-opt .icon { font-size: 16px; }
.weather-opt .ar { color: var(--muted); font-size: 11px; }
.weather-opt.on .ar { color: var(--brand); opacity: .75; }

/* Small helpers */
.row-gap { display: flex; gap: 10px; align-items: center; }
.subhead {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--gray-block);
  padding: 8px 12px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 10px;
  margin-top: 22px;
}
.subhead:first-of-type { margin-top: 0; }
.subhead .ar {
  color: var(--ink-2);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  margin-left: auto;
}
.subhead .count {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  background: white;
  padding: 1px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.remove-btn {
  background: transparent;
  border: 0;
  color: var(--muted-2);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 14px;
  line-height: 1;
  border-radius: 3px;
}
.remove-btn:hover { color: var(--brand); background: var(--brand-tint); }

.add-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 12px;
  border: 1px dashed var(--brand);
  border-radius: 5px;
  cursor: pointer;
  background: var(--brand-tint);
  font-family: inherit;
  margin-top: 10px;
}
.add-row:hover { background: var(--brand); color: white; }

.muted-note {
  color: var(--muted);
  font-size: 11.5px;
  margin-top: 8px;
}

.hint {
  font-size: 11.5px;
  color: var(--muted);
}

.kbd {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10.5px;
  padding: 1px 5px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 3px;
  color: var(--muted);
}

/* Cover strip at top */
.cover {
  background: linear-gradient(180deg, #fff 0%, var(--bg) 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px 32px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: relative;
  overflow: hidden;
}
.cover::before {
  content: '';
  position: absolute;
  right: -40px; top: -40px;
  width: 240px; height: 240px;
  background: url('/static/images/meraas-mark.png') center/contain no-repeat;
  opacity: 0.04;
  transform: rotate(-8deg);
}
.cover-logo { height: 44px; width: auto; position: relative; }
.cover-text { position: relative; flex: 1; }
.cover h2 {
  margin: 0 0 2px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.cover .sub { color: var(--muted); font-size: 13px; }
.cover .sub .ar { margin-right: 4px; }

/* Toast */
.toast-wrap {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--ink);
  color: white;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: toast-in 200ms ease;
  display: flex;
  gap: 10px;
  align-items: center;
}
.toast.success { background: #15803d; }
.toast.error { background: var(--err); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Footer summary bar */
.actionbar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26, 26, 26, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  border-radius: 999px;
  padding: 8px 10px 8px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  z-index: 40;
  font-size: 13px;
}
.actionbar .progress {
  font-variant-numeric: tabular-nums;
  color: #d4d4d8;
}
.actionbar .btn-primary { background: var(--red); color: white; border-color: var(--red); border-radius: 999px; padding: 7px 16px; }
.actionbar .btn-primary:hover { background: var(--red-ink); border-color: var(--red-ink); }
/* ---------- Responsive & Fixes ---------- */
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

@media (max-width: 720px) {
  .content { padding: 16px 16px 120px; }
  .topbar { padding: 8px 16px; }
  .sec-head { padding: 14px 18px; }
  .sec-body { padding: 16px 14px; }
  
  .field-grid.cols-2, .field-grid.cols-3, .field-grid.cols-4, .field-grid.cols-6 {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .weather-grid { grid-template-columns: repeat(2, 1fr); }
  
  .actionbar {
    left: 10px; right: 10px; transform: none;
    padding: 8px 12px;
    justify-content: space-between;
    border-radius: 12px;
  }
}

@media (max-width: 480px) {
  .field-grid.cols-2, .field-grid.cols-3, .field-grid.cols-4, .field-grid.cols-6 {
    grid-template-columns: 1fr;
  }
  .field.span-2 { grid-column: span 1; }
  
  .weather-grid { grid-template-columns: 1fr; }
  
  .topbar-title h1 { font-size: 14px; }
  .topbar-title .sub { font-size: 10px; }
  
  .tbl-wrap { margin: 0 -14px; padding: 0 14px; }
  
  .sec-head h2 { font-size: 14px; }
  .sec-head .num { font-size: 10px; }
}

/* Fix for Weather Impact / Inputs contrast */
.weather-row input, .field input, .field textarea, .tbl td input {
  color: #ffffff !important;
  background: rgba(255, 255, 255, 0.05);
}
.weather-row input::placeholder, .field input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

/* Ensure tables are scrollable and have a hint */
.tbl-wrap {
  position: relative;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.tbl-wrap::after {
  content: 'Swipe for more →';
  position: absolute;
  bottom: 4px; right: 8px;
  font-size: 9px;
  color: var(--muted-2);
  pointer-events: none;
  opacity: 0.6;
}
@media (min-width: 769px) { .tbl-wrap::after { display: none; } }

/* Signature pad mobile fix */
.sig-box { min-height: 60px; }
.sig-box input { font-size: 24px; }
