:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #dfe4ea;
  --text: #1f2d3d;
  --muted: #64748b;
  --primary: #2f6fb2;
  --primary-dark: #245a92;
  --accent: #1f9d6b;
  --danger: #d14343;
  --warning: #d99a26;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(31, 45, 61, 0.12);
  --mono: "Consolas", "Menlo", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Tahoma", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

html[dir="rtl"] body { font-family: "Segoe UI", "Tahoma", "Noto Naskh Arabic", sans-serif; }

.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: linear-gradient(90deg, #173f63, #2f6fb2);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand-mark {
  background: #fff; color: #173f63; border-radius: 6px;
  padding: 2px 6px; font-size: 12px; letter-spacing: 1px; font-weight: 800;
}

.tabs { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.tabs button {
  background: transparent; color: #eaf1f8; border: none; padding: 7px 12px;
  border-radius: 6px; cursor: pointer; font-size: 13.5px; white-space: nowrap;
}
.tabs button:hover { background: rgba(255,255,255,0.12); }
.tabs button.active { background: #fff; color: #173f63; font-weight: 600; }

.header-actions { display: flex; align-items: center; gap: 10px; }
.project-chip {
  background: rgba(255,255,255,0.18); padding: 5px 12px; border-radius: 20px;
  font-size: 12.5px; max-width: 260px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.btn.ghost { background: rgba(255,255,255,0.16); border: 1px solid rgba(255,255,255,0.4); color: #fff; }

.app-main { max-width: 1200px; margin: 20px auto; padding: 0 20px; }
.view { display: none; }
.view.active { display: block; }

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px;
}
.panel h2 { margin: 0 0 4px; font-size: 17px; }
.panel h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); font-weight: 600; }
.panel .sub { margin: 0 0 14px; color: var(--muted); font-size: 13px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.row.end { justify-content: flex-end; margin-bottom: 0; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
  background: #fff; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(47,111,178,0.35); border-color: var(--primary);
}
.field input.mono { font-family: var(--mono); }

.btn {
  background: var(--primary); color: #fff; border: none; padding: 8px 16px;
  border-radius: 6px; cursor: pointer; font-size: 13.5px;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #eef2f7; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #e2e8f0; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b33535; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

table.grid { width: 100%; border-collapse: collapse; background: #fff; }
table.grid th, table.grid td {
  border: 1px solid var(--border); padding: 6px 10px; text-align: start; font-size: 13px;
}
table.grid th { background: #f0f4f9; color: #33475b; font-weight: 600; white-space: nowrap; }
table.grid td.num, table.grid th.num { text-align: end; font-family: var(--mono); }
table.grid tr:nth-child(even) td { background: #fafbfd; }
table.grid tbody tr.selected td { background: #e6f0fb; }

.empty { text-align: center; color: var(--muted); padding: 30px; }
.empty .big { font-size: 30px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #1f2d3d; color: #fff; padding: 10px 18px; border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3); z-index: 100; max-width: 90vw;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--accent); }
html[dir="rtl"] .toast { transform: translateX(50%); }

.result-box {
  background: #f6f9ff; border: 1px solid #cfe0f3; border-radius: 8px;
  padding: 12px 16px; margin-top: 12px; font-size: 13.5px;
}
.result-box .kpi { display: flex; gap: 24px; flex-wrap: wrap; }
.result-box .kpi b { display: block; font-size: 18px; color: var(--primary); }
.result-box .kpi span { color: var(--muted); font-size: 12px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,30,45,0.45); display: flex;
  align-items: center; justify-content: center; z-index: 90; padding: 20px;
}
.modal {
  background: #fff; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; padding: 20px;
}
.modal h3 { margin: 0 0 14px; }

.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); background: #fff; border-radius: 16px;
  padding: 4px 12px; cursor: pointer; font-size: 13px;
}
.chip:hover { border-color: var(--primary); }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.notice { background: #fff8e6; border: 1px solid #f2d28a; color: #7a5b12; padding: 8px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }

.dl-list { display: flex; gap: 12px; flex-wrap: wrap; }
