:root {
  --ink: #0E0D0B;
  --ink-2: #151311;
  --line: #2E2A25;
  --brass: #C8A46A;
  --ivory: #F2EDE4;
  --soft: #CFC8BC;
  --muted: #9A9388;
  --rec: #D1453B;
  --display: "Noto Kufi Arabic", "Segoe UI", Tahoma, sans-serif;
  --body: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ink);
  color: var(--ivory);
  font: 400 16px/1.7 var(--body);
}

a { color: var(--ivory); text-decoration: none; }
a:hover { color: var(--brass); }

:focus-visible { outline: 2px solid var(--brass); outline-offset: 3px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.wordmark { margin: 0; font: 600 24px/1 var(--display); }
.muted { color: var(--muted); }

/* ---------- auth / viewfinder ---------- */
body.auth { display: grid; place-items: center; padding: 24px; }

.auth-frame {
  position: relative;
  width: min(420px, 100%);
  padding: 48px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.auth-frame h1 { margin: 8px 0 16px; font: 500 26px/1.4 var(--display); }

.corner { position: absolute; width: 24px; height: 24px; border: 0 solid var(--brass); }
.corner.tr { top: 0; right: 0; border-top-width: 1px; border-right-width: 1px; }
.corner.tl { top: 0; left: 0; border-top-width: 1px; border-left-width: 1px; }
.corner.br { bottom: 0; right: 0; border-bottom-width: 1px; border-right-width: 1px; }
.corner.bl { bottom: 0; left: 0; border-bottom-width: 1px; border-left-width: 1px; }

form { display: flex; flex-direction: column; gap: 8px; }
label { font-size: 14px; color: var(--soft); margin-top: 8px; }

input {
  height: 48px;
  padding: 0 14px;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ivory);
  font: 400 16px var(--body);
}
input:focus { border-color: var(--brass); outline: none; }

button, .button {
  height: 48px;
  margin-top: 16px;
  padding: 0 24px;
  border: 1px solid var(--brass);
  border-radius: 999px;
  background: var(--brass);
  color: var(--ink);
  font: 500 16px var(--body);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button:hover, .button:hover { background: #D6B67F; color: var(--ink); }

button.ghost { margin: 0; height: 40px; background: transparent; color: var(--ivory); border-color: var(--line); }
button.ghost:hover { border-color: var(--brass); color: var(--brass); background: transparent; }

.alert {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--rec);
  border-radius: 4px;
  color: #F0B4AE;
  font-size: 14px;
}

/* ---------- admin shell ---------- */
.topbar {
  height: 72px;
  padding: 0 clamp(16px, 4vw, 48px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.topbar-end { display: flex; align-items: center; gap: 16px; }
.topbar-end form { flex-direction: row; }

.page { max-width: 960px; margin: 0 auto; padding: 48px clamp(16px, 4vw, 48px); }
.page h1 { margin: 0 0 8px; font: 600 36px/1.3 var(--display); }
.summary { margin: 0 0 32px; color: var(--soft); }
.summary strong { color: var(--brass); font-weight: 500; }
.empty { padding: 20px; border: 1px dashed var(--line); border-radius: 4px; color: var(--soft); }

table { width: 100%; border-collapse: collapse; margin-top: 24px; }
th, td { padding: 14px 8px; text-align: right; border-bottom: 1px solid var(--line); }
th { font-weight: 500; font-size: 14px; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- phase 2: navigation, works, forms ---------- */
.topnav { display: flex; gap: 28px; font-size: 15px; }
form.inline { display: inline-flex; flex-direction: row; gap: 6px; align-items: center; margin: 0; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.page-head .button { margin: 0; }
.page.narrow { max-width: 680px; }
.back { display: inline-block; margin-bottom: 16px; font-size: 14px; color: var(--muted); }

.works { list-style: none; margin: 24px 0 0; padding: 0; }
.work-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto auto;
  gap: 20px;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.work-row:target { background: var(--ink-2); }

.thumb { position: relative; width: 120px; aspect-ratio: 4 / 5; overflow: hidden; border-radius: 2px; background: var(--ink-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge { position: absolute; bottom: 6px; right: 6px; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
.badge.video { background: var(--ink); color: var(--brass); border: 1px solid var(--brass); }

.work-meta { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.work-title { font: 500 18px/1.4 var(--display); }
.caption { margin: 4px 0 0; font-size: 14px; color: var(--soft); }

.status { font-size: 13px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.status.live { color: var(--brass); border-color: var(--brass); }
.status.draft { color: var(--muted); }

.row-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
button.icon {
  margin: 0; width: 40px; height: 40px; padding: 0;
  background: transparent; border: 1px solid var(--line); color: var(--ivory);
}
button.icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
button.icon:hover { border-color: var(--brass); color: var(--brass); background: transparent; }
button:disabled { opacity: .35; cursor: not-allowed; }

.ghost-link { padding: 8px 12px; font-size: 15px; }
.danger-link { padding: 8px 12px; font-size: 15px; color: #E88A82; }
.danger-link:hover { color: var(--rec); }
button.danger { margin: 0; background: var(--rec); border-color: var(--rec); color: var(--ivory); }
button.danger:hover { background: #B83A31; color: var(--ivory); }

form.stack { gap: 6px; }
textarea, select {
  padding: 12px 14px;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ivory);
  font: 400 16px/1.7 var(--body);
}
select { height: 48px; padding-block: 0; }
textarea:focus, select:focus { border-color: var(--brass); outline: none; }
input[type="file"] { height: auto; padding: 12px; }
input[type="radio"], input[type="checkbox"] { height: auto; accent-color: var(--brass); width: 18px; height: 18px; }

fieldset { margin: 12px 0 0; padding: 0; border: 0; display: flex; gap: 24px; align-items: center; }
legend { font-size: 14px; color: var(--soft); margin-bottom: 8px; float: right; width: 100%; }
.choice { display: inline-flex; align-items: center; gap: 8px; color: var(--ivory); font-size: 16px; margin: 0; }
.choice.publish { margin-top: 16px; }
.hint { margin: 0 0 8px; font-size: 13px; color: var(--muted); }

.current { display: flex; gap: 16px; align-items: flex-start; margin: 16px 0; flex-wrap: wrap; }
.current img { width: 200px; height: auto; border-radius: 2px; display: block; }
.current video { width: 320px; max-width: 100%; border-radius: 2px; background: #000; }

.alert ul { margin: 8px 0 0; padding-right: 20px; }
.alert p { margin: 0; }
.actions { display: flex; gap: 12px; align-items: center; margin-top: 24px; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; padding-block: 12px; gap: 12px; }
  .work-row { grid-template-columns: 88px minmax(0, 1fr); }
  .thumb { width: 88px; }
  .status, .row-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

/* ---------- phase 4: clients & documents ---------- */
.page.wide { max-width: 1180px; }
.topnav { flex-wrap: wrap; gap: 20px; }
.table-wrap { overflow-x: auto; }
td.num, .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.due { color: var(--brass); }
tr.voided td { color: var(--muted); text-decoration: line-through; }
tr.voided td.row-actions { text-decoration: none; }
.small { font-size: 13px; }
.muted { color: var(--muted); }
td.row-actions { justify-content: flex-end; }
.sub { margin: 28px 0 8px; font: 500 20px/1.4 var(--display); }

.grid-2, .grid-3 { display: grid; gap: 4px 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field input, .field select { width: 100%; }

.items { display: flex; flex-direction: column; gap: 8px; }
.item-head, .item-row {
  display: grid; gap: 8px; align-items: center;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 2fr) 90px 130px 120px 40px;
}
.item-head { font-size: 13px; color: var(--muted); padding: 0 2px; }
.item-row input { min-width: 0; }
.item-row output { color: var(--soft); text-align: left; }
.add-row { align-self: flex-start; margin-top: 8px; height: 40px; }

.totals-row { margin-top: 20px; align-items: end; }
.total-box { grid-column: 3; padding: 14px 18px; border: 1px solid var(--brass); border-radius: 4px; }
.total-box span { font-size: 13px; color: var(--muted); }
.total-box output { font: 600 24px/1.2 var(--display); color: var(--brass); }

select.compact { height: 38px; padding: 0 10px; font-size: 14px; }
.button.ghost-btn { margin: 0; background: transparent; color: var(--ivory); border-color: var(--line); }
.button.ghost-btn:hover { border-color: var(--brass); color: var(--brass); background: transparent; }
button.ghost.danger-text, .danger-text { color: #E88A82; }
button.ghost.danger-text:hover { border-color: var(--rec); color: var(--rec); }
.danger-zone { margin-top: 40px; }

@media (max-width: 860px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .total-box { grid-column: auto; }
  .item-head { display: none; }
  .item-row {
    grid-template-columns: 1fr 1fr; padding: 12px; border: 1px solid var(--line); border-radius: 4px;
  }
  .item-row input[name="item"], .item-row input[name="description"] { grid-column: 1 / -1; }
}
