:root {
  --bg: #faf6fc; --surface: #ffffff; --text: #2a1533; --muted: #715684;
  --accent: #7a3b9e; --accent-soft: #efdcf5; --border: #e3d5ea;
  --danger: #b3261e; --warn: #a15c00;
  --radius: 12px; --shadow: 0 1px 4px rgba(20,41,27,.08);
}
html[data-theme="dark"] {
  --bg: #1b1122; --surface: #241430; --text: #f2e8f7; --muted: #c2a8d1;
  --accent: #a76bc9; --accent-soft: #33173f; --border: #43265a;
  --shadow: 0 1px 4px rgba(0,0,0,.4);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: "Segoe UI", Tahoma, "Noto Kufi Arabic", sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }
.app-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.header-inner { max-width: 960px; margin: 0 auto; padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.app-title { font-size: 1.4rem; color: var(--accent); }
.app-title .en { font-size: .9rem; margin-inline-start: 8px; color: var(--muted); }
.header-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.container { max-width: 960px; margin: 20px auto; padding: 0 16px; display: grid; gap: 20px; }
.container > * { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card h2 { font-size: 1.1rem; margin-bottom: 14px; color: var(--accent); }
.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-size: .95rem; font-family: inherit; min-height: 44px; }
.btn:hover { background: var(--accent-soft); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); background: var(--accent); }
.btn-ghost { border: none; padding: 8px 10px; font-size: .85rem; font-weight: 600; color: var(--muted); }
.btn-ghost:hover { color: var(--accent); background: none; }
.btn-danger { color: var(--danger); border: none; }
.btn-pay { color: var(--accent); border: 1px solid var(--accent); background: none; font-size: .8rem; padding: 4px 10px; min-height: 36px; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--accent-soft); border-radius: 10px; padding: 14px; text-align: center; }
.stat-label { font-size: .85rem; color: var(--muted); }
.stat-value { font-size: 1.4rem; font-weight: 700; margin-top: 4px; }
.entry-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; align-items: end; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
input, select { padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 1rem; font-family: inherit; min-height: 44px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { padding: 10px 8px; text-align: start; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.table td:nth-child(6) { white-space: normal; min-width: 120px; }
.badge { display: inline-block; font-size: .78rem; padding: 2px 10px; border-radius: 20px; }
.badge-paid { background: var(--accent-soft); color: var(--accent); }
.badge-committed { background: #f7e8cf; color: var(--warn); }
html[data-theme="dark"] .badge-committed { background: #3d2c10; color: #e0b26a; }
.muted { color: var(--muted); font-size: .85rem; margin-top: 8px; }
.empty-state { text-align: center; color: var(--muted); padding: 18px 8px; font-style: italic; }
.app-footer { text-align: center; padding: 20px; }
#month-chart { width: 100%; height: auto; direction: ltr; }
.skip-link { position: absolute; inset-inline-start: 8px; top: -48px; z-index: 100; background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 8px; transition: top .15s ease; text-decoration: none; }
.skip-link:focus { top: 8px; }
.toast { position: fixed; bottom: 18px; inset-inline-start: 50%; transform: translate(50%, 80px); background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 10px; display: flex; gap: 14px; align-items: center; box-shadow: 0 4px 16px rgba(0,0,0,.25); opacity: 0; transition: transform .2s ease, opacity .2s ease; pointer-events: none; z-index: 200; max-width: min(92vw, 480px); }
html[dir="ltr"] .toast { transform: translate(-50%, 80px); }
.toast.show { transform: translate(50%, 0); opacity: 1; pointer-events: auto; }
html[dir="ltr"] .toast.show { transform: translate(-50%, 0); }
.toast-action { background: none; border: none; color: var(--accent); font-weight: 700; cursor: pointer; font-size: .95rem; min-height: 44px; padding: 0 6px; }
.print-header { display: none; }
@media (max-width: 600px) { .card { padding: 14px; } .stat-value { font-size: 1.15rem; } .table { font-size: .85rem; } }
@media (max-width: 420px) { .entry-form, .filters { grid-template-columns: 1fr; } }
@media print {
  @page { margin: 14mm; }
  .app-header, #form-entry, .filters, .btn-pay, .btn-danger, .skip-link { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: 1px solid #999; box-shadow: none; break-inside: avoid; }
  .print-header { display: block; text-align: center; font-weight: 700; font-size: 1.2rem; margin: 0 0 12px; }
}

/* pass 8/10: classification badges */
.badge-low, .badge-high { background: #f6d9d7; color: #b3261e; }
.badge-normal { background: var(--accent-soft); color: var(--accent); }
.badge-prediabetes { background: #f7e8cf; color: #a15c00; }
html[data-theme="dark"] .badge-low, html[data-theme="dark"] .badge-high { background: #3d1414; color: #ef9a94; }
html[data-theme="dark"] .badge-prediabetes { background: #3d2c10; color: #e0b26a; }
/* report box */
.report-controls { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin-bottom: 12px; }
.report-box { border: 1px solid var(--accent); border-radius: 10px; padding: 16px; background: var(--bg); }
.report-box h3 { color: var(--accent); margin-bottom: 8px; }
/* chart band legend via axis only; table meal column wraps */
.table td:nth-child(6) { white-space: normal; min-width: 110px; }
