:root {
  color-scheme: light;
  --bg: #f5efe1;
  --card: #fffdf7;
  --ink: #22301f;
  --muted: #6f6a5c;
  --line: #e4d9bf;
  --green: #0f5f45;
  --green-dark: #0a4632;
  --gold: #b8912f;
  --gold-soft: #f3e6c4;
  --bad: #9a3324;
  --good: #1f6b3b;
  --shadow: 0 1px 3px rgba(40, 30, 10, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 1px 1px, rgba(184, 145, 47, 0.10) 1px, transparent 0) 0 0 / 22px 22px,
    var(--bg);
  color: var(--ink);
  font: 15px/1.6 "Segoe UI", Tahoma, system-ui, -apple-system, sans-serif;
}

body[dir="rtl"] {
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Geeza Pro", system-ui, sans-serif;
}

h1, h2, h3 {
  font-family: "Amiri", "Noto Naskh Arabic", Georgia, "Times New Roman", serif;
  color: var(--green-dark);
}

a { color: var(--green); }

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 22px;
  background: linear-gradient(180deg, var(--green) 0%, var(--green-dark) 100%);
  border-bottom: 3px solid var(--gold);
  color: #f3ead2;
}
.brand {
  font-family: "Amiri", "Noto Naskh Arabic", Georgia, serif;
  font-size: 20px;
  font-weight: 700;
  text-decoration: none;
  color: #fff;
  letter-spacing: 0.02em;
}
.brand::before {
  content: "\262A";           /* star and crescent */
  color: var(--gold-soft);
  margin-inline-end: 8px;
}
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a { color: #eadfbf; text-decoration: none; padding: 4px 2px; }
.topbar nav a:hover { color: #fff; border-bottom: 2px solid var(--gold); }
.topbar .logout { margin: 0; }

/* language switch */
.langswitch { display: flex; gap: 4px; margin-inline-end: 6px; }
.langswitch a {
  padding: 3px 9px;
  border: 1px solid rgba(243, 230, 196, 0.4);
  border-radius: 6px;
  color: #eadfbf;
  text-decoration: none;
  font-size: 13px;
}
.langswitch a.on { background: var(--gold); color: #3a2c07; border-color: var(--gold); font-weight: 600; }

main { max-width: 1040px; margin: 0 auto; padding: 26px 16px 60px; }

h1.doc-title { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 14px; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}

/* -------------------------------------------------------- render progress */
.render-progress {
  margin: 0 0 22px;
  padding: 14px 16px;
  background: #fffdf3;
  border: 1px solid var(--line);
  border-inline-start: 4px solid var(--gold);
  border-radius: 10px;
}
.render-progress.is-ready { border-inline-start-color: var(--green); background: #eef5ee; }
.render-progress.is-error { border-inline-start-color: var(--bad); background: #f8e7e3; }
.rp-track {
  height: 12px;
  background: var(--gold-soft);
  border-radius: 999px;
  overflow: hidden;
}
.rp-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold) 0%, var(--green) 100%);
  transition: width 0.4s ease;
}
.render-progress.is-ready .rp-fill { background: var(--green); }
.render-progress.is-error .rp-fill { background: var(--bad); }
.rp-label { margin-top: 8px; font-size: 13px; color: var(--muted); }
.render-progress.is-ready .rp-label { color: var(--green-dark); font-weight: 600; }
.render-progress.is-error .rp-label { color: var(--bad); font-weight: 600; }
/* Once ready, the bar has served its purpose -- keep it subtle. */
.render-progress.is-ready { padding: 10px 16px; }

.grid { display: grid; gap: 6px; max-width: 520px; }
.grid label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.grid label.checkbox {
  display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px;
}
.grid label.checkbox input { width: auto; margin: 0; }

input, select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffef9;
  color: var(--ink);
}

/* ------------------------------------------------------------- dropzone */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 26px 18px;
  border: 2px dashed var(--gold);
  border-radius: 12px;
  background: #fffdf3;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.dropzone:hover { background: var(--gold-soft); }
.dropzone.drag {
  border-color: var(--green);
  background: #e9f2ea;
  color: var(--green-dark);
}
.dropzone.has-file {
  border-style: solid;
  border-color: var(--green);
  background: #eef5ee;
  color: var(--green-dark);
  font-weight: 600;
}
.dropzone.bad { border-color: var(--bad); background: #f8e7e3; color: var(--bad); }
.dz-icon { font-size: 24px; color: var(--gold); line-height: 1; }
.dropzone.has-file .dz-icon { color: var(--green); }
.dz-text { font-size: 14px; word-break: break-word; }
/* keep the real input reachable/focusable but out of the visual flow */
.dz-input {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px; border: 0;
  overflow: hidden; clip: rect(0 0 0 0);
}
input:focus, select:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold); }

button, .button {
  font: inherit;
  display: inline-block;
  padding: 8px 15px;
  margin-top: 10px;
  border: 1px solid var(--green);
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
}
button:hover, .button:hover { background: var(--green-dark); }
.button-primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.button-primary:hover { background: var(--green-dark); }
/* secondary (outline) buttons for low-emphasis actions */
.button[href*="/log"], a.button[href^="/admin/documents/"] {
  background: transparent; color: var(--green);
}
.button[href*="/log"]:hover, a.button[href^="/admin/documents/"]:hover {
  background: var(--gold-soft);
}
button.danger, .danger {
  background: #fff; border-color: #d8b3ab; color: var(--bad);
}
button.danger:hover { background: #f7e7e3; }
button.copy {
  margin: 0; padding: 4px 10px; font-size: 12px;
  background: var(--gold-soft); color: #6b520f; border-color: #e2cd94;
}
button.copy:hover { background: #ecdcae; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: start; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--green-dark); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; background: var(--gold-soft); }
body[dir="rtl"] th { letter-spacing: 0; }
td form { margin: 0; }
td form button { margin: 0; }
.nowrap { white-space: nowrap; }
.ua { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--muted); }

.hint { color: var(--muted); font-size: 13px; }

.flash { padding: 11px 14px; border-radius: 8px; margin: 0 0 16px; border: 1px solid transparent; }
.flash.error { background: #f8e7e3; color: var(--bad); border-color: #e6c4bc; }
.flash.ok { background: #e6f1e6; color: var(--good); border-color: #c3ddc3; }

/* modal (key / link reveal) */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 30, 18, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100;
}
.modal-card {
  background: var(--card); border-radius: 14px; padding: 26px;
  max-width: 560px; width: 100%;
  border-top: 4px solid var(--gold);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.modal-card h2 { margin-top: 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions button, .modal-actions .button { margin: 0; }

.reveal-value {
  display: inline-block; margin-top: 6px; padding: 6px 10px;
  background: #fffef9; border: 1px solid var(--line); border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px; word-break: break-all;
}
.reveal-value.big {
  display: block; text-align: center; font-size: 26px; letter-spacing: 0.14em;
  padding: 18px; margin: 4px 0 0; color: var(--green-dark);
  background: var(--gold-soft); border-color: #e2cd94;
}
body[dir="rtl"] .reveal-value.big { letter-spacing: 0.06em; }

.link-card { border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; background: #fffef9; }
.link-card header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.recipient { font-weight: 700; color: var(--green-dark); }
.link-card dl { display: grid; gap: 4px; margin: 0 0 8px; font-size: 14px; }
.link-card dl > div { display: flex; gap: 10px; flex-wrap: wrap; }
.link-card dt { color: var(--muted); min-width: 70px; font-size: 13px; }
.link-card dd { margin: 0; }
.link-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.link-actions form { margin: 0; }

.key-create { margin-top: 12px; }
.key-create > summary {
  display: inline-block; margin-top: 0; color: #fff; list-style: none; cursor: pointer;
}
.key-create > summary::-webkit-details-marker { display: none; }
.key-create[open] > summary { margin-bottom: 12px; }
.key-cell { white-space: nowrap; }
.key-cell code { font-size: 14px; letter-spacing: 0.04em; }
.key-cell button.copy { margin-inline-start: 8px; }

.tag { font-size: 12px; padding: 2px 9px; border-radius: 999px; }
.tag-good { background: #e2efe2; color: var(--good); }
.tag-bad { background: #f6e3df; color: var(--bad); }
.tag-warn { background: var(--gold-soft); color: #7a5c10; }
.status { font-size: 12px; padding: 2px 9px; border-radius: 999px; background: #eee; }
.status-ready { background: #e2efe2; color: var(--good); }
.status-error { background: #f6e3df; color: var(--bad); }
.status-rendering, .status-pending { background: var(--gold-soft); color: #7a5c10; }

.danger-zone { border-color: #e0c3bc; }
.danger-zone h2 { color: var(--bad); }
.row-actions { display: flex; gap: 8px; align-items: center; }
.row-actions form { margin: 0; }
.row-actions .button, .row-actions button { margin: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.filters button { margin: 0; }
.pager { display: flex; gap: 10px; margin-top: 12px; }

tr.ev-key_attempt td, tr.ev-link_denied td, tr.ev-page_denied td,
tr.ev-key_rate_limited td, tr.ev-admin_login_failed td, tr.ev-download_denied td { background: #fbf1ef; }
tr.ev-key_success td, tr.ev-download td { background: #eef5ee; }

.foot { max-width: 1040px; margin: 0 auto; padding: 0 16px 40px; color: var(--muted); font-size: 12px; text-align: center; }

/* login */
.login-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background:
    radial-gradient(circle at 1px 1px, rgba(184, 145, 47, 0.12) 1px, transparent 0) 0 0 / 22px 22px,
    var(--bg);
}
.login-card {
  width: 340px; background: var(--card); border: 1px solid var(--line);
  border-top: 4px solid var(--gold); border-radius: 14px; padding: 30px;
  box-shadow: 0 10px 40px rgba(30, 40, 20, 0.12);
}
.login-card h1 { margin: 0 0 6px; font-size: 24px; text-align: center; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.login-card form { display: grid; gap: 6px; }
.login-card label { font-size: 13px; color: var(--muted); }
.login-langs { display: flex; justify-content: center; gap: 6px; margin-top: 16px; }
.login-langs a { font-size: 13px; color: var(--green); text-decoration: none; padding: 2px 8px; border-radius: 6px; }
.login-langs a.on { background: var(--gold-soft); font-weight: 600; }

/* "Open" preview button sits on the same line as Copy */
.inline-form { display: inline; margin: 0; }
.inline-form button.copy { margin-inline-start: 6px; }
