/* PDF Crawler - shared look of the dashboard, the PDF tree and the login page.
   Colours come from CSS variables; the dark theme follows the system setting. */
:root {
  color-scheme: light dark;
  --bg: #f3f5f9; --surface: #ffffff; --surface-2: #f7f8fb;
  --text: #1b2330; --muted: #667085; --border: #e3e7ee; --border-strong: #cfd5df;
  --primary: #2f6fed; --primary-hover: #2459c9; --primary-soft: #e7efff; --on-primary: #ffffff;
  --danger: #d92d20; --danger-soft: #fdecea;
  --success: #16794c; --success-soft: #e4f6ec; --success-line: #4caf7d;
  --warn: #f59e0b;
  --radius: 12px; --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 12px rgba(16, 24, 40, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1319; --surface: #161c25; --surface-2: #1b222d;
    --text: #e7eaf0; --muted: #98a2b3; --border: #273040; --border-strong: #364154;
    --primary: #5b97ff; --primary-hover: #79aaff; --primary-soft: #1c2c4a; --on-primary: #0b1220;
    --danger: #ff7b72; --danger-soft: #3a1c1a;
    --success: #5fd39b; --success-soft: #14301f; --success-line: #2f8f5c;
    --warn: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .35);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; font: 15px/1.5 var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h2, h3 { line-height: 1.25; }
small, .muted { color: var(--muted); }
.note { font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---- header and page frame ---- */
.app-header { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.app-header .inner { max-width: 1320px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #3b82f6, #7c3aed); color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 800; letter-spacing: .04em; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { padding: 7px 14px; border-radius: 999px; color: var(--muted); font-size: 14px; font-weight: 500; transition: background .15s, color .15s; }
nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
nav a.active { background: var(--primary-soft); color: var(--primary); }
.container { max-width: 1320px; margin: 0 auto; padding: 22px 20px 40px; }

/* ---- cards ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card h2 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.app-footer { margin: 4px 0 0; text-align: center; color: var(--muted); font-size: 12px; }
.count { display: inline-block; min-width: 24px; text-align: center; padding: 1px 9px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 700; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; transition: opacity .2s; }
fieldset:disabled { opacity: .6; }

/* ---- messages ---- */
.msg { display: flex; gap: 8px; align-items: center; padding: 10px 14px; margin: 0 0 14px; border-radius: var(--radius-sm); background: var(--primary-soft); border-left: 4px solid var(--primary); animation: slide-in .25s ease-out; }
.msg.err { background: var(--danger-soft); border-left-color: var(--danger); }
.api-key-row { margin-bottom: 18px; }
input[type=text].api-key-value { flex: 1 1 340px; min-width: 0; font: 12.5px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }  /* the whole key fits, on its own line on a phone */
@keyframes slide-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---- buttons ---- */
button, .btn {
  font: inherit; font-size: 14px; line-height: 1.2; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
button:hover:not(:disabled), .btn:hover { background: var(--surface-2); border-color: var(--primary); text-decoration: none; }
button:active:not(:disabled), .btn:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
button.sm { padding: 4px 10px; font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---- form controls ---- */
input[type=text], input[type=number], input[type=time], input[type=search], input[type=password], select {
  font: inherit; font-size: 14px; padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); outline: none; }
input::placeholder { color: var(--muted); opacity: .8; }
input[type=checkbox], input[type=radio] { accent-color: var(--primary); width: 16px; height: 16px; cursor: pointer; }
input[type=file] { font: inherit; font-size: 13px; color: var(--muted); max-width: 100%; }
input[type=file]::file-selector-button { font: inherit; font-size: 13px; margin-right: 10px; padding: 6px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; transition: background .15s, border-color .15s; }
input[type=file]::file-selector-button:hover { background: var(--surface-2); border-color: var(--primary); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input { width: 100%; }
.field.wide { grid-column: 1 / -1; }
.switch-row { display: flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 500; }
input.switch { appearance: none; -webkit-appearance: none; width: 42px; height: 24px; border-radius: 12px; background: var(--border-strong); position: relative; cursor: pointer; transition: background .2s; flex: none; margin: 0; }
input.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .35); }
input.switch:checked { background: var(--primary); }
input.switch:checked::after { transform: translateX(18px); }

/* ---- tables ---- */
.scroll-box { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); margin-bottom: 14px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); text-align: left; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); padding: 9px 10px; box-shadow: 0 1px 0 var(--border); white-space: nowrap; user-select: none; }
th[data-sort] { cursor: pointer; transition: color .15s, background .15s; }
th[data-sort]:hover { color: var(--text); background: var(--border); }
td { padding: 7px 10px; border-bottom: 1px solid var(--border); word-break: break-all; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .12s; }
tbody tr:hover td { background: var(--surface-2); }
.num { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
#url-table th:nth-child(1), #url-table td:nth-child(1), #url-table th:nth-child(n+3), #url-table td:nth-child(n+3) { width: 1%; white-space: nowrap; }
#url-table td input[type=text] { width: 100%; min-width: 200px; }
#files-table th:not(:nth-child(2)):not(:nth-child(3)), #files-table td:not(:nth-child(2)):not(:nth-child(3)) { width: 1%; white-space: nowrap; }
#files-table td:nth-child(2), #files-table td:nth-child(3) { min-width: 200px; }  /* on narrow screens the table scrolls sideways instead of squeezing the title and the URL */
#files-table td:nth-child(2) { word-break: normal; overflow-wrap: anywhere; }  /* the title wraps between words, the URL anywhere */

/* ---- status, log ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; }
.stat .k { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat .v { font-size: 15px; font-weight: 600; margin-top: 3px; min-height: 1.5em; }
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 2px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--border); color: var(--muted); }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.run { background: var(--primary-soft); color: var(--primary); }
.pill.run::before { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.7); } }
pre { font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; overflow: auto; max-height: 260px; margin: 14px 0 0; white-space: pre-wrap; word-break: break-all; }

/* ---- segmented control (radio buttons as pills) ---- */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px; font-size: 13px; font-weight: 500; }
.seg label { margin: 0; cursor: pointer; }
.seg input { display: none; }
.seg span { display: inline-block; padding: 4px 16px; border-radius: 999px; color: var(--muted); transition: background .15s, color .15s; }
.seg input:checked + span { background: var(--primary); color: var(--on-primary); }
.seg input:disabled + span { opacity: .4; cursor: not-allowed; }

/* ---- badges ---- */
.badge { display: inline-block; border-radius: 999px; padding: 0 8px; font-size: 11px; font-weight: 700; line-height: 18px; }
.badge.new { background: var(--warn); color: #1b1300; }
.badge.stored { background: var(--border); color: var(--muted); font-weight: 500; }
.badge.gone { background: var(--danger-soft); color: var(--danger); }

/* ---- login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; padding: 28px; }
.login-card .brand { justify-content: center; margin-bottom: 20px; font-size: 20px; }
.login-card button { width: 100%; margin-top: 14px; padding: 10px; }

@media (max-width: 640px) {
  .container { padding: 14px 12px 30px; }
  .card { padding: 14px; }
  .app-header .inner { padding: 8px 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
