/* ============================================================
   TOKENS
============================================================ */
:root {
  color-scheme: dark;
  --bg:           #060a12;
  --panel:        rgba(12, 18, 30, 0.88);
  --panel-strong: #0c1220;
  --line:         rgba(148, 163, 184, 0.14);
  --line-bright:  rgba(148, 163, 184, 0.28);
  --text:         #f0f4fc;
  --muted:        #8a9ab5;
  --green:        #22c55e;
  --green-dim:    rgba(34, 197, 94, 0.12);
  --green-glow:   rgba(34, 197, 94, 0.35);
  --blue:         #38bdf8;
  --blue-dim:     rgba(56, 189, 248, 0.1);
  --indigo:       #6366f1;
  --warning:      #fb7185;
  --gold:         #f4c95d;
  --shadow-lg:    0 28px 80px rgba(0, 0, 0, 0.45);
  --radius:       10px;
  --radius-sm:    7px;
}

/* ============================================================
   RESET / BASE
============================================================ */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Tajawal", system-ui, sans-serif;
  overflow-x: hidden;
}

/* Animated grid background */
.bg-grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(34,197,94,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34,197,94,0.035) 1px, transparent 1px);
  background-size: 52px 52px;
  mask-image: radial-gradient(ellipse 80% 80% at 50% 0%, black 30%, transparent 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 40% at 90% 0%, rgba(34,197,94,0.13) 0%, transparent 60%),
    radial-gradient(ellipse 50% 35% at 0% 50%, rgba(56,189,248,0.09) 0%, transparent 60%),
    radial-gradient(ellipse 40% 30% at 50% 100%, rgba(99,102,241,0.07) 0%, transparent 60%);
}

button, input { font: inherit; }

h1, h2, h3, p { margin-top: 0; }

/* ============================================================
   LAYOUT
============================================================ */
.app-shell {
  position: relative;
  z-index: 1;
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 28px;
}

/* ============================================================
   HEADER
============================================================ */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 36px;
  margin-bottom: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(12,18,30,0.95) 0%, rgba(8,12,22,0.85) 100%);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.05);
  backdrop-filter: blur(20px);
  position: relative;
  overflow: hidden;
}

.site-header::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(180deg, var(--green), var(--blue));
  border-radius: 4px 0 0 4px;
}

.site-header::after {
  content: "";
  position: absolute;
  inset: auto 36px 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--green-glow), transparent);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand-icon {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  border-radius: var(--radius);
  border: 1px solid rgba(34,197,94,0.3);
  background: var(--green-dim);
  flex-shrink: 0;
}

.site-header h1 {
  margin: 0 0 4px;
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff 30%, var(--green) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
}

.brand-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 500;
}

.header-badge {
  min-width: 160px;
  padding: 18px 22px;
  border: 1px solid rgba(34,197,94,0.25);
  border-radius: var(--radius);
  background: rgba(3,7,18,0.6);
  backdrop-filter: blur(12px);
  text-align: center;
  flex-shrink: 0;
}
.badge-label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge-value {
  display: block;
  color: var(--green);
  font-size: 2.1rem;
  font-weight: 900;
  line-height: 1;
}

/* ============================================================
   WORKSPACE (two columns)
============================================================ */
.workspace {
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

/* ============================================================
   PANEL
============================================================ */
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 8px 32px rgba(0,0,0,0.28);
  backdrop-filter: blur(20px);
}

.calculator, .results, .table-section, .milestones-section {
  padding: 24px;
}

.panel__header {
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.panel__header h2 {
  margin-bottom: 4px;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text);
}
.panel__header p, .chart-card p, .charts-toolbar p {
  color: var(--muted);
  margin-bottom: 0;
  font-size: 0.9rem;
}

/* ============================================================
   FORM FIELDS
============================================================ */
.field-grid { display: grid; gap: 14px; }

.field > span,
.field-label {
  display: block;
  margin-bottom: 7px;
  color: #c8d8f0;
  font-weight: 700;
  font-size: 0.92rem;
}

.input-wrap {
  display: flex;
  align-items: center;
  min-height: 50px;
  border: 1px solid var(--line-bright);
  border-radius: var(--radius-sm);
  background: rgba(2, 6, 23, 0.55);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrap:focus-within {
  border-color: rgba(56,189,248,0.7);
  box-shadow: 0 0 0 3px rgba(56,189,248,0.1);
}
.input-wrap input {
  width: 100%;
  min-width: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
  padding: 13px 15px;
  direction: ltr;
  text-align: left;
  font-size: 1rem;
}
.input-wrap b {
  min-width: 52px;
  color: var(--muted);
  text-align: center;
  border-right: 1px solid var(--line);
  font-size: 0.88rem;
}

.field-error {
  display: block;
  min-height: 18px;
  margin-top: 5px;
  color: var(--warning);
  font-size: 0.82rem;
  font-weight: 700;
}

/* ============================================================
   PRESET BUTTONS
============================================================ */
.preset-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-top: 9px;
}

.withdrawal-months-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.preset-btn {
  min-height: 36px;
  border: 1px solid var(--line-bright);
  border-radius: var(--radius-sm);
  color: #c4d4ec;
  background: rgba(15,23,42,0.7);
  cursor: pointer;
  font-weight: 800;
  font-size: 0.88rem;
  transition: border-color 0.17s, background 0.17s, color 0.17s, transform 0.17s;
}
.preset-btn:hover   { border-color: rgba(34,197,94,0.6); color: #dcfce7; background: rgba(34,197,94,0.12); transform: translateY(-1px); }
.preset-btn.is-active { border-color: var(--green); color: #dcfce7; background: rgba(34,197,94,0.2); box-shadow: 0 0 10px rgba(34,197,94,0.2); }

/* ============================================================
   TOGGLE GROUPS
============================================================ */
.toggle-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  border: 0;
  padding: 0;
  margin: 6px 0 16px;
}
.toggle-group legend {
  grid-column: 1 / -1;
  margin-bottom: 9px;
  color: #c8d8f0;
  font-weight: 700;
  font-size: 0.92rem;
}
.toggle-group label { cursor: pointer; }
.toggle-group input { position: absolute; opacity: 0; }
.toggle-group span {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  border: 1px solid var(--line-bright);
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: rgba(2,6,23,0.4);
  font-weight: 800;
  transition: border-color 0.17s, background 0.17s, color 0.17s;
}
.toggle-group input:checked + span {
  border-color: var(--green);
  color: #dcfce7;
  background: rgba(34,197,94,0.15);
  box-shadow: 0 0 10px rgba(34,197,94,0.15);
}

/* ============================================================
   WITHDRAWAL OPTIONS
============================================================ */
.withdrawal-options {
  padding: 16px;
  border: 1px solid rgba(56,189,248,0.25);
  border-radius: var(--radius-sm);
  background: var(--blue-dim);
  margin-bottom: 16px;
  display: grid;
  gap: 14px;
  animation: fadeIn 0.22s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   FORM ACTIONS
============================================================ */
.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.btn {
  min-height: 48px;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 800;
  font-size: 1rem;
  transition: transform 0.17s, filter 0.17s, box-shadow 0.17s;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.07); }
.btn:active { transform: translateY(0); }

.btn-primary {
  color: #021304;
  background: linear-gradient(135deg, #22c55e, #86efac);
  box-shadow: 0 4px 20px rgba(34,197,94,0.3);
}
.btn-secondary {
  color: var(--text);
  background: #1a2540;
  border: 1px solid var(--line-bright);
}

/* ============================================================
   NOTICES
============================================================ */
.notice-stack { margin-top: 18px; display: grid; gap: 8px; }

.notice {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  line-height: 1.7;
  font-size: 0.86rem;
}
.notice-risk-med  { border: 1px solid rgba(251,146,60,0.5);  color: #fed7aa; background: rgba(251,146,60,0.1);  }
.notice-risk-high { border: 1px solid rgba(251,113,133,0.6);  color: #fecdd3; background: rgba(251,113,133,0.12); animation: pulse-border 1.8s ease-in-out infinite; }

/* Inline field warnings */
.inline-warning {
  margin-top: 8px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  line-height: 1.65;
  animation: fadeIn 0.22s ease;
}
.inline-warning--warn {
  border: 1px solid rgba(251,146,60,0.45);
  color: #fed7aa;
  background: rgba(251,146,60,0.09);
}
.inline-warning--orange {
  border: 1px solid rgba(249,115,22,0.55);
  color: #fdba74;
  background: rgba(249,115,22,0.11);
}
.inline-warning--safe {
  border: 1px solid rgba(34,197,94,0.35);
  color: #bbf7d0;
  background: rgba(34,197,94,0.08);
}
.inline-warning--safe-dim {
  border: 1px solid rgba(34,197,94,0.22);
  color: #86efac;
  background: rgba(34,197,94,0.05);
}
.inline-warning--danger {
  border: 1px solid rgba(251,113,133,0.55);
  color: #fecdd3;
  background: rgba(251,113,133,0.1);
  animation: pulse-border 1.8s ease-in-out infinite;
}
.inline-warning strong { font-weight: 900; }

  color: #fde68a; background: rgba(244,201,93,0.07); }
.notice-reinvest { border: 1px solid rgba(56,189,248,0.3);   color: #bae6fd; background: rgba(56,189,248,0.07); }
.notice-currency { border: 1px solid rgba(34,197,94,0.3);    color: #bbf7d0; background: rgba(34,197,94,0.07); }

/* ============================================================
   SUMMARY CARDS
============================================================ */
.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  min-height: 110px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: linear-gradient(160deg, rgba(15,23,42,0.9) 0%, rgba(10,16,30,0.7) 100%);
  transition: border-color 0.2s, transform 0.2s;
}
.stat-card:hover { border-color: var(--line-bright); transform: translateY(-1px); }
.stat-card span  { color: var(--muted); font-weight: 700; font-size: 0.83rem; display: block; }
.stat-card strong {
  display: block;
  margin-top: 10px;
  font-size: 1.15rem;
  line-height: 1.4;
  direction: ltr;
  text-align: right;
  color: var(--text);
  font-weight: 800;
}
.stat-card.is-accent strong { color: var(--green); }
.stat-card small {
  display: block;
  margin-top: 5px;
  color: var(--blue);
  direction: ltr;
  text-align: right;
  font-size: 0.82rem;
  font-weight: 700;
}

/* ============================================================
   CHARTS
============================================================ */
.charts-panel { margin-top: 18px; }

.charts-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.charts-toolbar h2 { margin-bottom: 4px; font-size: 1.1rem; font-weight: 800; }
.chart-toggle { min-width: 130px; padding: 0 14px; min-height: 42px; font-size: 0.9rem; }

.charts-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }

.chart-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(56,189,248,0.06) 0%, transparent 50%), rgba(2,6,23,0.3);
}
.chart-card h3 { margin-bottom: 3px; font-size: 1rem; }
.chart-frame { height: 270px; margin-top: 14px; }

canvas { display: block; width: 100%; height: 100%; }

/* ============================================================
   TABLE
============================================================ */
.table-section { margin-top: 20px; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

table { width: 100%; min-width: 700px; border-collapse: collapse; }

th, td {
  padding: 13px 15px;
  text-align: right;
  border-bottom: 1px solid rgba(148,163,184,0.09);
}

th {
  color: #c4d4ec;
  background: rgba(15,23,42,0.95);
  font-weight: 800;
  font-size: 0.88rem;
  letter-spacing: 0.02em;
  position: sticky;
  top: 0;
}

td { color: #d8e6f8; font-size: 0.9rem; }

td:not(:first-child) { direction: ltr; text-align: right; }

.month-num {
  color: var(--muted);
  font-weight: 800;
  font-size: 0.85rem;
  text-align: center !important;
  direction: ltr !important;
}

.sar-col { color: var(--blue) !important; }

.growth-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  background: rgba(34,197,94,0.13);
  border: 1px solid rgba(34,197,94,0.25);
  color: var(--green);
  font-weight: 800;
  font-size: 0.85rem;
}

tbody tr:hover { background: rgba(56,189,248,0.05); }

/* ============================================================
   MILESTONES
============================================================ */
.milestones-section { margin-top: 20px; }

.milestones-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.milestone-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: linear-gradient(160deg, rgba(15,23,42,0.9) 0%, rgba(10,16,30,0.6) 100%);
  overflow: hidden;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}
.milestone-card:hover {
  border-color: rgba(34,197,94,0.35);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(34,197,94,0.1);
}

.milestone-header {
  padding: 10px 14px;
  background: linear-gradient(135deg, rgba(34,197,94,0.13), rgba(34,197,94,0.05));
  border-bottom: 1px solid rgba(34,197,94,0.2);
  color: #86efac;
  font-weight: 800;
  font-size: 0.9rem;
  text-align: center;
}

.milestone-row {
  padding: 9px 14px;
  border-bottom: 1px solid rgba(148,163,184,0.07);
}
.milestone-row:last-child { border-bottom: 0; }
.milestone-row span  { color: var(--muted); font-size: 0.78rem; font-weight: 700; display: block; margin-bottom: 2px; }
.milestone-row strong {
  direction: ltr;
  text-align: right;
  display: block;
  font-size: 0.95rem;
  color: var(--text);
  font-weight: 800;
}
.milestone-row small  { direction: ltr; text-align: right; display: block; color: var(--muted); font-size: 0.78rem; margin-top: 1px; }
.milestone-row .c-green { color: var(--green); }
.milestone-row .c-blue  { color: var(--blue); }


footer {
  position: relative;
  z-index: 1;
  margin-top: 24px;
  padding: 0 16px 32px;
}
.footer-inner {
  text-align: center;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(12,18,30,0.6);
}
footer p { margin: 0 0 6px; color: var(--muted); font-size: 0.9rem; }
.footer-copy {
  font-size: 0.82rem !important;
  color: rgba(138,154,181,0.7) !important;
}

/* ============================================================
   RESPONSIVE
============================================================ */
@media (max-width: 1024px) {
  .workspace { grid-template-columns: 1fr; }
  .milestones-grid { grid-template-columns: repeat(3, 1fr); }
  .cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  .site-header { flex-direction: column; align-items: flex-start; padding: 20px; }
  .header-badge { width: 100%; }
  .milestones-grid { grid-template-columns: repeat(2, 1fr); }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .preset-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 500px) {
  .app-shell { width: calc(100% - 20px); }
  .calculator, .results, .table-section, .milestones-section { padding: 16px; }
  .site-header { padding: 16px; }
  .milestones-grid { grid-template-columns: 1fr 1fr; }
  .cards { grid-template-columns: 1fr; }
  .form-actions { grid-template-columns: 1fr; }
  .charts-toolbar { flex-direction: column; align-items: flex-start; }
  .chart-toggle { width: 100%; }
  .chart-frame { height: 230px; }
  .site-header h1 { font-size: 1.5rem; }
}
