:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --text: #16202e;
  --muted: #5d6b7d;
  --primary: #1565c0;
  --primary-dark: #0d47a1;
  --border: #d9e2ee;
  --danger: #c0392b;
  --accent: #2e7d32;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(10, 30, 60, 0.08);
}
[data-theme="dark"] {
  --bg: #10151d;
  --surface: #1a2230;
  --text: #e6edf6;
  --muted: #93a3b8;
  --primary: #5c9ce6;
  --primary-dark: #3d7dc4;
  --border: #2a3648;
  --danger: #e74c3c;
  --accent: #66bb6a;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, "Noto Kufi Arabic", "Noto Sans Arabic", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--primary-dark); color: #fff;
  position: sticky; top: 0; z-index: 10;
}
.app-header h1 { font-size: 1.15rem; margin: 0; }
.header-actions { display: flex; gap: 8px; }
.container { max-width: 860px; margin: 0 auto; padding: 16px; }
.panel { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.panel h2 { margin: 0 0 12px; font-size: 1.05rem; }
.btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 8px 14px; cursor: pointer; }
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-small { padding: 4px 10px; font-size: 0.85rem; }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.app-header .btn-ghost { color: #fff; }
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; }
.field { flex: 1; min-width: 140px; }
.field label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%; font: inherit; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text);
}
.hint { font-size: 0.8rem; color: var(--muted); margin: 10px 0 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: start; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
tr.cheapest td { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.bar-chart { margin-top: 16px; }
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.bar-label { width: 110px; font-size: 0.8rem; color: var(--muted); text-align: end; flex-shrink: 0; }
.bar-track { flex: 1; height: 18px; background: var(--border); border-radius: 9px; overflow: hidden; }
.bar { height: 100%; background: var(--primary); border-radius: 9px; transition: width 0.3s ease; }
.bar.best { background: var(--accent); }
.bar-val { width: 90px; font-size: 0.78rem; color: var(--muted); flex-shrink: 0; }
.scenario-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.card-meta { font-size: 0.8rem; color: var(--muted); margin: 4px 0; }
.card-actions { display: flex; gap: 8px; margin-top: 6px; }
.empty { color: var(--muted); text-align: center; padding: 16px 8px; }
dialog { border: none; border-radius: var(--radius); padding: 20px; background: var(--surface); color: var(--text); width: min(420px, 92vw); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h3 { margin-top: 0; }
dialog label { display: block; margin-bottom: 4px; font-size: 0.85rem; color: var(--muted); }
dialog input { width: 100%; font: inherit; padding: 8px 10px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 8px 0 0; }
.form-error { color: var(--danger); font-size: 0.85rem; margin: 0 0 8px; }
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 24px;
  opacity: 0; transition: transform 0.25s ease, opacity 0.25s ease; pointer-events: none; z-index: 50;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (max-width: 560px) {
  .app-header h1 { font-size: 1rem; }
  .panel { padding: 12px; }
  .bar-label { width: 70px; }
  .bar-val { width: 70px; }
}
@media print {
  .app-header .header-actions, .panel-head .btn, .card-actions, .toast, dialog { display: none !important; }
  body { background: #fff; color: #000; }
  .panel { box-shadow: none; border: 1px solid #ccc; }
  .app-header { position: static; background: #fff; color: #000; border-bottom: 2px solid #000; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
