/* Masr — style */
.skip-link {
  position: absolute; inset-inline-start: 12px; top: -48px;
  background: var(--accent); color: #fff; padding: 8px 16px;
  border-radius: 0 0 10px 10px; z-index: 100; font-weight: 700;
  transition: top .15s ease;
}
.skip-link:focus { top: 0; }

:root {
  --accent: #0e7a4f;
  --accent-2: #16a066;
  --bg: #f7f3ee;
  --card: #ffffff;
  --text: #24211d;
  --muted: #655c53;
  --line: #e4dcd2;
  --danger: #b3261e;
  --ok: #1e7a3c;
  --warn-bg: #fff4d6;
  --warn-text: #7a5200;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(30, 20, 10, .08), 0 6px 24px rgba(30, 20, 10, .06);
}
[data-theme="dark"] {
  --bg: #171412;
  --card: #211d19;
  --text: #f0ebe4;
  --muted: #a89e92;
  --line: #38312b;
  --warn-bg: #3a2f14;
  --warn-text: #ffd479;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 6px 24px rgba(0, 0, 0, .3);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, "Noto Kufi Arabic", "Cairo", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 1.35rem; margin: 0; color: var(--accent); }
.logo { width: 30px; height: 30px; border-radius: 8px; }
.card { animation: rise .25s ease; }
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.tabs { display: flex; gap: 6px; flex: 1; }
.tab {
  border: 0; background: transparent; color: var(--muted);
  padding: 8px 16px; border-radius: 999px; cursor: pointer;
  font: inherit; font-weight: 600;
}
.tab.active { background: var(--accent); color: #fff; }
.tab:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent-2); outline-offset: 2px;
}
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 10px; padding: 6px 12px; cursor: pointer; font: inherit; font-weight: 700;
}
main { max-width: 1150px; margin: 0 auto; padding: 20px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
h2 { margin-top: 0; font-size: 1.15rem; }
form label { display: block; margin-bottom: 14px; }
form label span { display: block; font-weight: 600; margin-bottom: 4px; }
.req { color: var(--danger); }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--bg); color: var(--text);
  font: inherit;
}
textarea { resize: vertical; }
input.invalid, select.invalid, textarea.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px rgba(179, 38, 30, .18);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn {
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  padding: 10px 20px; border-radius: 10px; cursor: pointer;
  font: inherit; font-weight: 700;
}
.btn:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { padding: 6px 14px; font-size: .9rem; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.errors {
  background: #fdecea; color: var(--danger); border: 1px solid var(--danger);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 12px;
}
[data-theme="dark"] .errors { background: #3d1a17; }
.hint { color: var(--muted); font-size: .92rem; margin: 10px 0 0; }
.letter-card { position: sticky; top: 76px; }
.letter-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.letter {
  white-space: pre-wrap; word-wrap: break-word;
  background: var(--bg); border: 1px dashed var(--line);
  border-radius: 10px; padding: 18px; font: inherit; line-height: 2;
  min-height: 300px; margin: 0;
}
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input[type="search"] { flex: 1; min-width: 200px; }
.toolbar select { width: auto; }
.banner {
  background: var(--warn-bg); color: var(--warn-text);
  border-radius: 10px; padding: 10px 16px; margin-bottom: 16px; font-weight: 600;
}
.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.item { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.item-main { flex: 1; min-width: 250px; }
.item-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.item-subject { font-size: 1.05rem; }
.badge {
  background: var(--accent); color: #fff; border-radius: 999px;
  padding: 2px 12px; font-size: .8rem; font-weight: 700;
}
.badge.st-resolved { background: var(--ok); }
.badge.st-rejected { background: var(--danger); }
.badge.st-draft { background: var(--muted); }
.badge.st-followup { background: #b07a00; }
.item-meta { color: var(--muted); font-size: .92rem; margin-top: 4px; }
.item-ref { color: var(--muted); font-size: .88rem; }
.item.overdue { border-inline-start: 4px solid var(--danger); }
mark { background: var(--warn-bg); color: inherit; border-radius: 3px; padding: 0 2px; }
.status-hint { color: var(--muted); font-size: .88rem; margin-top: 6px; font-style: italic; }
.followups { margin-top: 10px; font-size: .92rem; }
.followups li { margin-bottom: 4px; }
.followup-form { display: flex; gap: 8px; margin-top: 8px; }
.followup-form input { flex: 1; }
.item-actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.status-select { width: auto; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.stat-card { text-align: center; }
.stat-card .num { font-size: 2.2rem; font-weight: 800; color: var(--accent); }
.stat-card .lbl { color: var(--muted); font-weight: 600; }
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 40px; gap: 10px; align-items: center; }
.bar-lbl { font-weight: 600; }
.bar-track { background: var(--bg); border-radius: 999px; height: 14px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 999px; min-width: 2px; transition: width .3s ease; }
.bar-num { text-align: center; font-weight: 700; color: var(--muted); }
.footer { text-align: center; color: var(--muted); padding: 24px; font-size: .9rem; }
.toast-action {
  background: transparent; border: 0; color: var(--accent-2);
  font: inherit; font-weight: 800; cursor: pointer; margin-inline-start: 12px;
  text-decoration: underline;
}
[data-theme="dark"] .toast-action { color: #7fe0b6; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 22px;
  border-radius: 999px; box-shadow: var(--shadow); z-index: 50; font-weight: 600;
}
.file-btn { display: inline-flex; align-items: center; cursor: pointer; }
.file-btn input { display: none; }

@media (pointer: coarse) {
  .tab, .btn, .icon-btn, input, select { min-height: 44px; }
}
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .letter-card { position: static; }
}
@media (max-width: 560px) {
  .grid-2 { grid-template-columns: 1fr; }
  main { padding: 12px; }
  .topbar { padding: 10px 12px; gap: 8px; }
  .tabs { overflow-x: auto; scrollbar-width: none; flex: 1 1 100%; order: 3; }
  .tab { padding: 8px 12px; font-size: .92rem; white-space: nowrap; }
  .item-actions { flex-direction: row; flex-wrap: wrap; }
  .form-card .btn-row { position: sticky; bottom: 8px; z-index: 5; }
  .form-card .btn.primary { flex: 1; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar select { width: 100%; }
  .entry { flex-wrap: wrap; }
  .entry-num { font-size: 1.1rem; }
  .entry-actions { width: 100%; }
  .entry-actions .call-btn { flex: 1; justify-content: center; min-height: 44px; }
}
mark { background: var(--warn-bg); color: inherit; border-radius: 3px; padding: 0 2px; }
.print-only { display: none; }
@page { margin: 2cm; }
@media print {
  body * { visibility: hidden; }
  #letterPreview, #letterPreview *, #printHeader, #printHeader * { visibility: visible; }
  #letterPreview {
    position: absolute; inset-inline: 0; top: 40px; border: 0; background: #fff; color: #000;
    font-size: 13pt; padding: 0; line-height: 1.9;
  }
  #printHeader {
    display: block; position: absolute; top: 0; inset-inline: 0;
    color: #000; font-weight: 700; border-bottom: 1px solid #000; padding-bottom: 6px;
  }
  .topbar, .footer { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Masr-specific */
.search-wrap { flex: 1; min-width: 180px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
  border-radius: 999px; padding: 6px 16px; cursor: pointer; font: inherit; font-weight: 600;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.entry { display: flex; align-items: center; gap: 14px; padding: 14px 18px; }
.entry-info { flex: 1; min-width: 160px; }
.entry-name { font-weight: 700; font-size: 1.05rem; }
.entry-note { color: var(--muted); font-size: .9rem; }
.entry-num {
  font-size: 1.3rem; font-weight: 800; color: var(--accent); direction: ltr; white-space: nowrap;
  background: none; border: none; cursor: pointer; font-family: inherit; padding: 4px 8px; border-radius: 8px;
}
.entry-num:hover { background: var(--bg); }
.entry-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.call-btn { text-decoration: none; display: inline-flex; align-items: center; }
.fav-btn { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--muted); padding: 4px 8px; }
.fav-btn.on { color: #e0a500; }
.modified-tag { font-size: .72rem; background: var(--warn-bg); color: var(--warn-text); border-radius: 6px; padding: 1px 8px; margin-inline-start: 6px; }
.list.compact .entry { padding: 8px 14px; }
dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
  color: var(--text); padding: 24px; max-width: 420px; width: calc(100vw - 40px);
}
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog label { display: block; margin-bottom: 12px; }
dialog label span { display: block; font-weight: 600; }
.disclaimer { text-align: center; margin-top: 20px; }
#printSheet { display: none; }
@media print {
  body * { visibility: hidden; }
  #printSheet, #printSheet * { visibility: visible; }
  #printSheet { display: block; position: absolute; inset: 0; color: #000; }
  #printSheet h1 { font-size: 18pt; }
  #printSheet table { width: 100%; border-collapse: collapse; }
  #printSheet td, #printSheet th { border: 1px solid #000; padding: 6px 10px; text-align: start; }
  .topbar, .footer { display: none; }
}
