/* Karatasi — D2D light skin (one skin only, per brand guidelines) */

/* Raleway, self-hosted (variable weight) so the brand font renders on any machine,
   including offline and on shared hosting with no external requests. */
@font-face {
  font-family: Raleway;
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(raleway-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: Raleway;
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(raleway-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308,
    U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113,
    U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --magenta: #CE65B0;
  --magenta-dark: #B55A9D;
  --magenta-text: #A94F92;
  --navy: #2D2A45;
  --navy-light: #3D3959;
  --lavender: #D4CFE0;
  --surface: #F4F5F7;
  --muted: #6B6B7B;
  --success: #25D366;
  --card-shadow: 0 1px 3px rgba(45,42,69,.08), 0 8px 24px rgba(45,42,69,.08);
  --card-shadow-hover: 0 2px 6px rgba(45,42,69,.1), 0 16px 40px rgba(45,42,69,.14);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
/* The hidden attribute has to win over classes like .btn that set their own
   display, or JS-toggled controls (the Install app buttons) show when they
   should not. */
[hidden] { display: none !important; }
html { touch-action: manipulation; } /* kill the ~300ms tap delay on links/buttons */
body {
  font-family: Raleway, Helvetica, Arial, sans-serif;
  background: var(--surface);
  color: var(--navy);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
}

a { color: var(--magenta-text); font-weight: 700; text-decoration: none; }
a:hover { color: var(--magenta-dark); text-decoration: underline; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: linear-gradient(135deg, var(--magenta), var(--navy));
  color: #fff;
  padding: env(safe-area-inset-top, 0px) max(20px, env(safe-area-inset-right, 0px)) 0 max(20px, env(safe-area-inset-left, 0px));
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 56px;
  flex-wrap: wrap;
  box-shadow: 0 1px 0 rgba(0,0,0,.06), 0 6px 18px rgba(45,42,69,.14);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; color: #fff; }
.topbar .brand:hover { text-decoration: none; }
.topbar .brand img { height: 30px; display: block; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a {
  color: rgba(255,255,255,.92); font-weight: 600; padding: 7px 12px; border-radius: 8px; font-size: 14px;
  touch-action: manipulation; transition: background-color .12s, transform .08s ease-out;
}
.topbar nav a:hover { background: rgba(255,255,255,.14); text-decoration: none; color: #fff; }
.topbar nav a:active { transform: scale(.96); }
.topbar nav a.active { background: rgba(255,255,255,.22); color: #fff; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; opacity: .9; }
.topbar form { margin: 0; }

/* Hamburger toggle — hidden on desktop, shown only under the mobile nav breakpoint below */
.nav-toggle {
  display: none; background: rgba(255,255,255,.14); border: 0; border-radius: 8px;
  width: 40px; height: 40px; padding: 0; cursor: pointer; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.nav-toggle:active { background: rgba(255,255,255,.26); }
.nav-toggle-bars { position: relative; display: block; width: 18px; height: 2px; background: #fff; border-radius: 2px; }
.nav-toggle-bars::before, .nav-toggle-bars::after { content: ""; position: absolute; left: 0; width: 18px; height: 2px; background: #fff; border-radius: 2px; }
.nav-toggle-bars::before { top: -6px; }
.nav-toggle-bars::after { top: 6px; }

.wrap {
  max-width: 1180px; margin: 0 auto;
  padding: 24px max(20px, env(safe-area-inset-right, 0px)) max(60px, env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
}

/* ---------- cards & layout ---------- */
.card {
  background: #fff; border-radius: 16px; box-shadow: var(--card-shadow);
  padding: 20px 22px; margin-bottom: 18px;
}
.card h1, .card h2 { margin-top: 0; }
h1 { font-size: clamp(19px, 5vw, 22px); letter-spacing: -.01em; } h2 { font-size: 17px; }
.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.stat { text-align: left; }
.stat .num { font-size: 30px; font-weight: 800; background: linear-gradient(120deg, var(--magenta), var(--navy)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat .lbl { color: var(--muted); font-size: 13px; font-weight: 600; }

/* ---------- forms & buttons ---------- */
label { font-weight: 700; font-size: 13px; display: block; margin: 10px 0 4px; }
input[type=text], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--lavender); border-radius: 8px;
  font: inherit; color: var(--navy); background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--magenta); outline-offset: 0; border-color: var(--magenta); }
textarea { min-height: 120px; resize: vertical; }

.btn {
  display: inline-block; background: var(--magenta); color: #fff; border: 0; border-radius: 8px;
  font: inherit; font-weight: 700; padding: 9px 18px; cursor: pointer; text-decoration: none;
  touch-action: manipulation; transition: transform .08s ease-out, background-color .15s;
}
.btn:hover { background: var(--magenta-dark); color: #fff; text-decoration: none; }
.btn:active { transform: scale(.96); }
.btn.secondary { background: #fff; color: var(--navy); border: 1px solid var(--lavender); }
.btn.secondary:hover { background: var(--surface); }
.btn.danger { background: #fff; color: #B3261E; border: 1px solid #E7B8B5; }
.btn.danger:hover { background: #FBEDEC; }
.btn.small { padding: 5px 12px; font-size: 13px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- flashes ---------- */
.flash { border-radius: 8px; padding: 10px 14px; margin-bottom: 10px; font-weight: 600; font-size: 14px; }
.flash.ok { background: #E7F8EE; color: #14532D; border: 1px solid #A7E3C0; }
.flash.error { background: #FBEDEC; color: #7F1D1D; border: 1px solid #E7B8B5; }
.flash.install-prompt { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; }
.flash.install-prompt span { flex: 1 1 220px; }

/* ---------- tables & doc list ---------- */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid #ECEDF1; vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tr:hover td { background: #FAFAFC; }

.doc-title { font-weight: 700; }
.doc-sub { color: var(--muted); font-size: 12.5px; }
.doc-row-actions { white-space: nowrap; }
.bulk-select { width: auto; }
.snip { color: var(--navy-light); font-size: 13px; margin-top: 3px; }
.snip mark { background: #F6DFEF; color: var(--navy); border-radius: 3px; padding: 0 2px; }

.tag {
  display: inline-block; border-radius: 999px; font-size: 11.5px; font-weight: 700;
  padding: 2px 9px; color: #fff; margin: 1px 3px 1px 0; white-space: nowrap;
}
.pill {
  display: inline-block; border: 1px solid var(--lavender); border-radius: 999px;
  font-size: 12px; font-weight: 600; padding: 2px 9px; color: var(--navy-light); margin: 1px 3px 1px 0;
}
.badge-status { font-size: 11.5px; font-weight: 700; border-radius: 6px; padding: 2px 7px; }
.badge-status.ok { background: #E7F8EE; color: #14532D; }
.badge-status.needs_text, .badge-status.encrypted, .badge-status.error { background: #FFF4E0; color: #7A4E00; }
.badge-status.none { background: #EFEFF3; color: var(--muted); }

/* ---------- filter bar ---------- */
.filterbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.filterbar .f { min-width: 150px; flex: 0 1 auto; }
.filterbar .f.grow { flex: 1 1 240px; }
.filterbar label { margin-top: 0; }

/* ---------- upload ---------- */
.dropzone {
  border: 2px dashed var(--lavender); border-radius: 16px; background: #fff;
  padding: 44px 20px; text-align: center; color: var(--muted); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--magenta); background: #FDF6FB; }
.dropzone strong { color: var(--navy); }

/* ---------- viewer ---------- */
.viewer { width: 100%; height: 75vh; border: 1px solid var(--lavender); border-radius: 8px; background: #fff; }
img.viewer-img { max-width: 100%; border: 1px solid var(--lavender); border-radius: 8px; }
pre.textview {
  white-space: pre-wrap; background: var(--surface); border-radius: 8px; padding: 14px;
  max-height: 420px; overflow: auto; font-size: 13px;
}

/* ---------- misc ---------- */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
code.k { background: var(--surface); border: 1px solid var(--lavender); border-radius: 6px; padding: 1px 6px; font-size: 13px; }
.auth-wrap { max-width: 420px; margin: 8vh auto 0; padding: 0 16px; }
.auth-logo { text-align: center; margin-bottom: 18px; }
.auth-logo img { height: 54px; }
.checkline { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; margin: 6px 0; }
.checkline input { width: auto; }
details.editor { border: 1px solid var(--lavender); border-radius: 8px; padding: 10px 14px; margin-bottom: 10px; background: #fff; }
details.editor summary { cursor: pointer; font-weight: 700; }

/* ---------- settings: grouped collapsible rows (iOS Settings-style) ---------- */
.settings-group-label {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin: 22px 4px 8px;
}
.settings-group-label:first-of-type { margin-top: 0; }
.card.settings-card { padding: 0; overflow: hidden; }
.settings-row { border-top: 1px solid #ECEDF1; }
.settings-row:first-of-type { border-top: 0; }
.settings-row summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; cursor: pointer; list-style: none; touch-action: manipulation;
}
.settings-row summary::-webkit-details-marker, .settings-row summary::marker { display: none; content: ""; }
.settings-row summary:hover { background: var(--surface); }
.settings-row summary:active { background: #EFEFF3; }
.settings-row summary h2 { margin: 0; font-size: 15.5px; }
.settings-row summary .settings-meta { display: flex; align-items: center; gap: 10px; flex-shrink: 0; min-width: 0; }
.settings-row summary .settings-status {
  color: var(--muted); font-size: 12.5px; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 220px;
}
.settings-row summary .chevron {
  width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform .15s; flex-shrink: 0; margin-right: 2px;
}
.settings-row[open] summary .chevron { transform: rotate(45deg); }
.settings-row .settings-body { padding: 2px 20px 20px; }

/* Document scanner modal */
.scan-modal {
  position: fixed; inset: 0; background: rgba(45,42,69,.55); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.scan-dialog {
  background: #fff; border-radius: 16px; box-shadow: var(--card-shadow-hover);
  max-width: 640px; width: 100%; max-height: 92vh; overflow-y: auto; padding: 20px 22px;
}
.scan-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.scan-head h2 { margin: 0; }
.scan-x {
  background: none; border: 0; font-size: 18px; line-height: 1; cursor: pointer;
  color: var(--navy-light); padding: 4px 8px; border-radius: 6px;
  min-width: 40px; min-height: 40px; touch-action: manipulation;
}
.scan-x:hover { background: var(--surface); }
.scan-adjust-wrap { position: relative; display: inline-block; max-width: 100%; touch-action: none; }
/* max-height caps a PORTRAIT photo's rendered height so all 4 corner handles
   (and the Crop/Retake buttons below) stay inside the dialog's visible area
   without scrolling — max-width alone left a tall photo's bottom two handles
   rendered below the fold, unreachable (confirmed 2026-08-22: a 1200x1600
   photo rendered 774px tall against a 662px-visible dialog on a common
   720px-tall viewport, hiding both bottom handles ~200px past the edge).
   Both max-width and max-height apply together; the browser's replaced-
   element sizing picks whichever is tighter and keeps aspect ratio, and
   positionHandles() (scan.js) already reads the actual rendered rect rather
   than assuming a fixed size, so this needs no JS change to take effect. */
.scan-adjust-wrap canvas { max-width: 100%; max-height: 55vh; height: auto; display: block; border-radius: 8px; border: 1px solid var(--lavender); }
.scan-handle {
  position: absolute; width: 22px; height: 22px; margin-left: -11px; margin-top: -11px;
  border-radius: 50%; background: var(--magenta); border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(45,42,69,.4); cursor: grab; touch-action: none;
}
.scan-handle:active { cursor: grabbing; }
/* Same reasoning as .scan-adjust-wrap canvas above - keeps the corrected
   preview (and the "Use this photo" button below it) fully visible without
   scrolling for a portrait photo. */
.scan-result-canvas { max-width: 100%; max-height: 55vh; height: auto; display: block; border-radius: 8px; border: 1px solid var(--lavender); margin: 0 auto; }

/* ---------- client upload link (public/submit.php) ---------- */
.sub-groups { display: flex; flex-wrap: wrap; gap: 8px; }
.sub-group {
  display: inline-flex; align-items: center; gap: 6px; margin: 0;
  border: 1px solid var(--lavender); border-radius: 999px; padding: 8px 14px;
  font-size: 14px; font-weight: 600; color: var(--navy); background: #fff; cursor: pointer;
  touch-action: manipulation;
}
.sub-group input { width: auto; margin: 0; accent-color: var(--magenta); }
.sub-group:has(input:checked) { border-color: var(--magenta); background: #FDF6FB; }
.sub-add { display: flex; flex-wrap: wrap; gap: 8px; }
.sub-add .btn { flex: 1 1 160px; min-height: 48px; font-size: 15px; }
.sub-batch, .sub-history { list-style: none; padding: 0; margin: 12px 0 0; }
.sub-batch-item, .sub-hist-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 8px; border-radius: 10px; border: 1px solid #ECEDF1; margin-bottom: 8px;
  background: #fff; text-align: left; font: inherit; color: inherit;
}
button.sub-hist-item { cursor: pointer; touch-action: manipulation; }
button.sub-hist-item:hover { background: var(--surface); }
.sub-batch-item.is-sending { opacity: .7; }
.sub-batch-item.is-failed { border-color: #E7B8B5; background: #FBEDEC; }
.sub-batch-item.is-ok { border-color: #BFE3CC; }
.sub-thumb {
  flex: 0 0 48px; width: 48px; height: 48px; border-radius: 6px; overflow: hidden;
  background: var(--surface); display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.sub-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sub-hist-text { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.sub-hist-name { font-weight: 600; font-size: 14px; color: var(--navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-tick { color: #1E7A45; font-weight: 700; padding: 0 8px; }
.sub-viewer-dialog { max-width: 900px; }
.sub-viewer-title { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 8px; }
img.sub-viewer-img { display: block; margin: 0 auto; max-height: 78vh; }
.sub-viewer-frame { height: 78vh; }

/* ---------- mobile nav (collapses .topbar nav into a dropdown under the hamburger) ---------- */
@media (max-width: 760px) {
  .nav-toggle { display: inline-flex; }
  .topbar nav {
    display: none; width: 100%; order: 5;
    flex-direction: column; gap: 2px;
    background: linear-gradient(160deg, var(--magenta-dark), var(--navy));
    margin: 0 max(-20px, calc(-1 * env(safe-area-inset-right, 0px) - 20px)) 0 max(-20px, calc(-1 * env(safe-area-inset-left, 0px) - 20px));
    padding: 8px 20px 12px;
    box-shadow: 0 12px 24px rgba(45,42,69,.28);
  }
  .topbar nav.open { display: flex; animation: navDropIn .16s ease-out; }
  .topbar nav a { padding: 12px 14px; font-size: 15px; }
  .topbar .who { display: none; }
}
@keyframes navDropIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- general mobile pass: touch targets, spacing, iOS zoom fix, stacked tables ---------- */
@media (max-width: 640px) {
  .wrap { padding-top: 16px; }
  .card { padding: 16px; border-radius: 14px; }

  /* 16px stops iOS Safari auto-zooming the page when a field is focused */
  input[type=text], input[type=password], input[type=date], input[type=number], select, textarea {
    font-size: 16px; padding: 11px 12px; min-height: 44px;
  }
  textarea { min-height: 100px; }

  .btn { padding: 12px 18px; min-height: 44px; }
  .btn.small { padding: 9px 14px; min-height: 40px; font-size: 13.5px; }

  .filterbar { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
  .filterbar .f, .filterbar .f.grow { width: 100%; min-width: 0; flex: 0 0 auto; }
  .filterbar .f .btn { width: 100%; }

  .bulk-actions { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
  .bulk-actions .bulk-select, .bulk-actions .btn { width: 100%; }

  /* Document/Recently-added tables become stacked cards instead of a horizontally-scrolled grid */
  .stacked, .stacked tr, .stacked td { display: block; width: 100%; }
  .stacked tr:first-child { display: none; } /* the header row (plain <th>s, no <thead>) */
  .stacked tr {
    background: #fff; border: 1px solid #ECEDF1; border-radius: 12px;
    padding: 12px 14px; margin-bottom: 10px;
  }
  .stacked tr:hover td { background: transparent; }
  .stacked td { border-bottom: 0; padding: 4px 0; }
  .stacked td[data-label]::before {
    content: attr(data-label); display: block; margin-bottom: 2px;
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  }
  .stacked .doc-row-actions { white-space: normal; margin-top: 6px; }
  .stacked .doc-row-actions .btn { display: block; width: 100%; margin-bottom: 6px; text-align: center; }
  .stacked .doc-row-actions .btn:last-child { margin-bottom: 0; }

  .settings-row summary { padding: 13px 16px; flex-wrap: wrap; row-gap: 4px; }
  .settings-row summary .settings-status { max-width: none; white-space: normal; }
  .settings-row .settings-body { padding: 2px 16px 18px; }
}
