:root {
  --ground: #F4F1EA;
  --surface: #FFFFFF;
  --ink: #17212B;
  --muted: #55606B;
  --line: #E3DED3;
  --field-line: #D9D3C6;
  --field-bg: #FBFAF7;
  --accent: #0E5A52;
  --accent-dark: #08403A;
  --exp-bg: #FCE8E6; --exp: #9F1D12;
  --soon-bg: #FDF0DC; --soon: #8A4B00;
  --ok-bg: #E3F2EA; --ok: #0B5E3A;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: 'IBM Plex Sans Arabic', Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.7;
}
input, select, button { font: inherit; color: inherit; }
button { cursor: pointer; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
p { margin: 0; }
code { background: #EFEBE2; padding: 1px 6px; border-radius: 6px; direction: ltr; display: inline-block; }
[hidden] { display: none !important; }

.wrap { max-width: 1220px; margin: 0 auto; padding: 28px 16px 56px; display: flex; flex-direction: column; gap: 24px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.accent { color: var(--accent); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 20px; border-bottom: 1px solid #DDD7CA; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 52px; height: 52px; border-radius: 14px; background: var(--accent); display: flex; align-items: center; justify-content: center; flex: 0 0 52px; }
.brand h1 { font-size: 30px; font-weight: 700; }
.brand p { font-size: 14px; }
.top-side { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
.today { display: flex; align-items: baseline; justify-content: center; flex-wrap: wrap; gap: 4px 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; font-size: 14px; white-space: nowrap; }
.today .sep { color: #CFC8B9; }
.top-btns { display: flex; gap: 8px; }
.top-btns .btn-ghost { flex: 1; min-height: 40px; font-size: 14px; padding: 0 12px; }
.top-btns:not(:has(button:not([hidden]))) { display: none; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.card h2 { font-size: 22px; font-weight: 700; }
.notice, .auth { max-width: 480px; margin: 0 auto; width: 100%; }
.auth form { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-size: 14px; font-weight: 600; }
.field textarea {
  border: 1px solid var(--field-line); border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 16px;
  background: var(--field-bg); width: 100%; resize: vertical; min-height: 64px; line-height: 1.6; text-align: right;
}
.field textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.note { margin-top: 6px; font-size: 14px; color: #3F4A55; background: #F7F5F0; border-radius: 8px; padding: 6px 10px; white-space: pre-line; overflow-wrap: anywhere; text-align: right; }
.field input, .field select {
  min-height: 46px; border: 1px solid var(--field-line); border-radius: 10px; padding: 0 12px;
  font-size: 16px; background: var(--field-bg); width: 100%;
}
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-size: 14px; font-weight: 600; padding: 0; margin-bottom: 8px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #EFEBE2; border-radius: 12px; padding: 4px; }
.seg button { min-height: 42px; border: 0; border-radius: 9px; font-weight: 600; background: transparent; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: 0 1px 2px rgba(23,33,43,.12); }
.date-row { display: grid; grid-template-columns: 0.9fr 2.1fr 1.3fr; gap: 8px; }
.date-row .field select { padding: 0 4px 0 2px; font-size: 15px; }
.preview { background: #EEF5F3; border-radius: 10px; padding: 10px 12px; font-size: 14px; display: flex; flex-direction: column; gap: 2px; }
.preview strong { color: var(--accent); }
.preview.bad { background: var(--exp-bg); }
.preview.bad strong { color: var(--exp); }

.msg { border-radius: 10px; padding: 10px 12px; font-size: 14px; background: #EEF5F3; color: var(--accent-dark); }
.msg.error { background: var(--exp-bg); color: var(--exp); }

.btn-primary { min-height: 46px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 700; padding: 0 20px; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary.big { min-height: 52px; font-size: 17px; }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn-outline { min-height: 46px; border: 1px solid var(--accent); border-radius: 12px; background: var(--surface); color: var(--accent); font-weight: 600; padding: 0 16px; }
.btn-ghost { min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--muted); padding: 0 14px; }
.pass-wrap { position: relative; }
.pass-wrap input { padding-left: 76px; }
.toggle-pass { position: absolute; left: 6px; top: 50%; transform: translateY(-50%); min-height: 36px; padding: 0 10px; border: 0; border-radius: 8px; background: #EFEBE2; color: var(--ink); font-size: 13px; font-weight: 600; }
.link-btn { align-self: flex-start; min-height: 44px; padding: 0; border: 0; background: none; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 4px; }
.link-btn:hover { color: var(--accent-dark); }
.row-btns { display: flex; flex-wrap: wrap; gap: 10px; }
.row-btns > * { flex: 1 1 140px; }

.alert { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; background: var(--soon-bg); border: 1px solid #F1D3A4; color: #6E3C00; border-radius: 14px; padding: 14px 18px; margin-bottom: 24px; }

.layout { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.form-card { flex: 1 1 340px; min-width: 0; }
.form-card form { display: flex; flex-direction: column; gap: 16px; }
.main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 18px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.num { font-size: 34px; font-weight: 700; line-height: 1.1; }
.c-exp { color: var(--exp); } .c-soon { color: var(--soon); } .c-ok { color: var(--ok); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 44px; padding: 0 16px; border-radius: 999px; font-size: 14px; font-weight: 600; background: var(--surface); color: var(--ink); border: 1px solid var(--field-line); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.search { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--field-line); border-radius: 12px; padding: 0 12px; min-height: 46px; flex: 0 1 280px; }
.search input { border: 0; outline: none; background: transparent; width: 100%; min-height: 44px; }

.list { display: flex; flex-direction: column; gap: 10px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.mono { width: 48px; height: 48px; flex: 0 0 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; background: #E7EAF0; color: #1F3A68; }
.mono.sub { background: #E4F0EE; color: var(--accent); }
.info { flex: 1 1 150px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.info h3 { font-size: 17px; font-weight: 700; text-align: right; overflow-wrap: anywhere; }
.info span { font-size: 13px; }
.dates { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.dates div { display: flex; gap: 8px; align-items: baseline; }
.dates .lbl { font-size: 12px; color: var(--muted); min-width: 44px; }
.dates .v { font-weight: 500; color: #3F4A55; }
.dates .v.primary { font-weight: 700; color: var(--ink); }
.state { flex: 0 0 auto; min-width: 120px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.state .remain { font-size: 14px; font-weight: 600; }
.badge { display: inline-flex; align-items: center; min-height: 26px; padding: 0 10px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.badge.expired { background: var(--exp-bg); color: var(--exp); }
.badge.soon { background: var(--soon-bg); color: var(--soon); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.actions { display: flex; gap: 8px; }
.actions button { min-height: 44px; padding: 0 14px; border-radius: 10px; font-size: 14px; background: var(--surface); }
.actions .renew { border: 1px solid var(--accent); color: var(--accent); font-weight: 600; }
.actions .del { border: 1px solid var(--line); color: var(--muted); }

.empty { background: var(--surface); border: 1px dashed #CFC8B9; border-radius: 16px; padding: 40px 20px; text-align: center; color: var(--muted); }
.foot { text-align: center; }

@media (max-width: 560px) {
  .top { gap: 12px; padding-bottom: 14px; }
  .top-side { width: 100%; }
  .today { font-size: 13px; gap: 4px 6px; padding: 8px 10px; }
  .state { flex: 1 1 auto; flex-direction: row; align-items: center; }
  .actions { flex: 1 1 100%; }
  .actions button { flex: 1; }
}

/* التعديل */
.actions .edit { border: 1px solid var(--field-line); color: var(--ink); font-weight: 600; }
.item.is-editing { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.form-card.editing { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.form-card { scroll-margin-top: 16px; }
.form-actions { display: flex; gap: 10px; }
.form-actions .btn-primary { flex: 2; }
.form-actions .btn-outline { flex: 1; }
.btn-outline.big { min-height: 52px; font-size: 17px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 12px; font-weight: 600; box-shadow: 0 6px 20px rgba(23,33,43,.25); z-index: 10; max-width: calc(100% - 32px); text-align: center; }

/* النسخة الاحتياطية */
.backup { margin-top: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.backup h2 { font-size: 17px; font-weight: 700; }
.backup-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.backup-btns button { min-height: 44px; font-size: 14px; }
@media (max-width: 560px) { .backup-btns { width: 100%; } .backup-btns button { flex: 1; } }

/* القيمة */
.info .price { display: inline-block; margin-top: 4px; font-size: 14px; font-weight: 700; color: var(--accent); }
.totals { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; background: #EEF5F3; border: 1px solid #CFE3DE; border-radius: 14px; padding: 12px 16px; font-size: 15px; }
.totals strong { color: var(--accent-dark); }
.totals .sep { color: #A9C9C1; }
#f-price { text-align: right; }

/* نافذة التنبيه */
.app-dialog { border: 0; padding: 0; border-radius: 18px; width: min(400px, calc(100% - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 20px 50px rgba(23,33,43,.25); font-family: inherit; direction: rtl; }
.app-dialog::backdrop { background: rgba(23,33,43,.45); }
.app-dialog[open] { animation: dlg-in .16s ease-out; }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.dlg-body { padding: 22px 22px 8px; display: flex; flex-direction: column; gap: 8px; text-align: right; }
.dlg-body h2 { font-size: 19px; font-weight: 700; }
.app-dialog.danger .dlg-body h2 { color: var(--exp); }
.dlg-body p { margin: 0; font-size: 16px; color: #3F4A55; white-space: pre-line; overflow-wrap: anywhere; }
.dlg-actions { display: flex; gap: 10px; padding: 16px 22px 22px; }
.dlg-actions button { flex: 1; min-height: 48px; font-size: 16px; }
.btn-danger { min-height: 46px; border: 0; border-radius: 12px; background: var(--exp); color: #fff; font-weight: 700; padding: 0 20px; }
.btn-danger:hover { background: #7E150C; }
@media (prefers-reduced-motion: reduce) { .app-dialog[open] { animation: none; } }

.state .remain-days { font-size: 12px; color: var(--muted); margin-top: -4px; }
.state .remain { white-space: nowrap; }
