:root {
    --accent: #0f6e5c;
    --page-w: 210mm;
    --page-h: 297mm;
    --bg: #eef0ee;
    --panel: #ffffff;
    --text: #1d2321;
    --muted: #66706c;
    --line: #d9dedb;
    --radius: 8px;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    display: grid;
    grid-template-columns: 380px 1fr;
    min-height: 100vh;
}

.ar { font-family: "Amiri", "Noto Naskh Arabic", "Traditional Arabic", "Arabic Typesetting", serif; }

/* ---------- Settings panel ---------- */

.panel {
    background: var(--panel);
    border-right: 1px solid var(--line);
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    padding: 20px 20px 40px;
}

.panel-head h1 {
    font-size: 1.25rem;
    margin: 0 0 4px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}
.panel-head h1 .ar { color: var(--accent); font-size: 1.2rem; font-weight: 400; }
.panel-head p { margin: 0 0 16px; color: var(--muted); font-size: .9rem; }

fieldset {
    border: 0;
    border-top: 1px solid var(--line);
    padding: 14px 0 6px;
    margin: 0;
}
legend {
    font-weight: 650;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--accent);
    padding: 0 8px 0 0;
}

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: .85rem; min-width: 0; }
.field > span:first-child { color: var(--muted); }
.field small { color: var(--muted); font-size: .75rem; }

input, select, button, .button {
    font: inherit;
    font-size: .9rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 7px 9px;
    background: #fff;
    color: inherit;
    min-width: 0;
    width: 100%;
}
input[type="color"] { padding: 2px; height: 36px; cursor: pointer; }
input:focus-visible, select:focus-visible, button:focus-visible, .button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
button, .button { width: auto; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .button:hover { background: #f4f6f5; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.primary:hover { background: var(--accent); filter: brightness(1.1); }
.link-btn { border: 0; padding: 0; color: var(--accent); background: none; margin: 0 0 12px; font-size: .85rem; }
.link-btn:hover { background: none; text-decoration: underline; }

.row { display: flex; gap: 6px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 8px; }
[hidden] { display: none !important; }

details { margin: 4px 0 10px; font-size: .85rem; }
summary { cursor: pointer; color: var(--accent); margin-bottom: 8px; }

.checks { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: .88rem; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: auto; accent-color: var(--accent); }
.check-inline { display: flex; align-items: center; gap: 8px; }
.check-inline input[type="number"] { width: 60px; padding: 3px 6px; }
.check-inline small { color: var(--muted); }

.search { position: relative; }
.results {
    list-style: none;
    margin: -6px 0 10px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: 0 8px 24px rgb(0 0 0 / .08);
}
.results li { font-size: .85rem; }
.results li.muted { color: var(--muted); padding: 6px 8px; }
.results button { width: 100%; border: 0; text-align: left; padding: 6px 8px; display: block; }
.results button small { color: var(--muted); }

/* ---------- Preview ---------- */

.preview { padding: 20px 24px 60px; overflow-x: auto; min-width: 0; }

.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    max-width: var(--page-w);
    margin: 0 auto 16px;
}
.toolbar small { color: var(--muted); font-size: .78rem; flex: 1 1 220px; }

.sheet {
    width: var(--page-w);
    height: var(--page-h);
    margin: 0 auto 24px;
    padding: 12mm 13mm 10mm;
    background: #fff;
    box-shadow: 0 1px 3px rgb(0 0 0 / .08), 0 12px 32px rgb(0 0 0 / .08);
    display: flex;
    flex-direction: column;
    color: #1a1a1a;
    font-size: 10pt;
    overflow: hidden;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.sheet-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 8mm;
    padding-bottom: 4mm;
    margin-bottom: 4mm;
    border-bottom: 2.5pt solid var(--accent);
}
.sheet-head h2 { margin: 0; font-size: 22pt; line-height: 1.1; letter-spacing: -.01em; }
.sheet-head .subtitle { margin: 1.5mm 0 0; font-size: 11pt; }
.sheet-head .place { margin: 1mm 0 0; color: #555; font-size: 10pt; }
.head-month { text-align: right; flex-shrink: 0; }
.head-month .greg { font-size: 20pt; font-weight: 700; color: var(--accent); line-height: 1.1; }
.head-month .hijri { margin-top: 1mm; font-size: 10pt; color: #444; }
.head-month .hijri .ar { display: block; font-size: 12pt; margin-top: .5mm; }

.table-wrap { flex: 1; min-height: 0; }

.times {
    width: 100%;
    height: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
    table-layout: fixed;
}
.times th {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    font-size: 9pt;
    padding: 1.6mm 1mm;
    line-height: 1.15;
    height: 1px; /* keep header compact while body rows stretch */
}
.times th .ar { display: block; font-weight: 400; font-size: 10pt; opacity: .9; }
.times td {
    text-align: center;
    padding: 0 1mm;
    border-bottom: .5pt solid #e3e3e3;
    white-space: nowrap;
}
.times .c-date { width: 11%; font-weight: 600; }
.times .c-day { width: 8%; }
.times td.c-day, .times td.c-hijri { color: #555; }
.times .c-hijri { width: 15%; text-align: left; padding-left: 2mm; }
.times th.c-hijri { text-align: left; }
.times .c-hijri .hm { font-size: 7.5pt; }
.times td.c-time { font-size: 10.5pt; }
.times td.c-sunrise, .times td.c-imsak { color: #666; }

.times tbody tr:nth-child(even) td { background: #f6f7f6; }
.times tr.week-end td { border-bottom: 1pt solid #bbb; }
.times tbody tr.ramadan td { background: color-mix(in srgb, var(--accent) 9%, #fff); }
.times tr.ramadan td.c-date { box-shadow: inset 2.5pt 0 0 var(--accent); }
.times tbody tr.fri td { background: color-mix(in srgb, var(--accent) 17%, #fff); font-weight: 700; }
.times tbody tr.fri td.c-day { color: var(--accent); }

.sheet-foot { margin-top: 3mm; font-size: 7.5pt; color: #666; }
.sheet-foot p { margin: 0 0 1mm; }
.sheet-foot .note { font-size: 8.5pt; color: #333; }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
    body { grid-template-columns: 1fr; }
    .panel { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 16px; }
    .preview { padding: 16px; }
    .toolbar { max-width: none; }
}

/* ---------- Print ---------- */

@media print {
    body { display: block; background: #fff; }
    .panel, .toolbar { display: none !important; }
    .preview { padding: 0; overflow: visible; }
    .sheet { margin: 0; box-shadow: none; break-after: page; }
    .sheet:last-child { break-after: auto; }
}
