:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #16191d;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #1a56db;
  --accent-soft: #e8efff;
  --mark: #ffe58a;
  --sent: #0f766e;
  --sent-bg: #d7f2ee;
  --recv: #4338ca;
  --recv-bg: #e5e4fb;
  --warn: #92400e;
  --warn-bg: #fef3c7;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --line: #2b313a;
    --accent: #7ea6ff;
    --accent-soft: #232c3d;
    --mark: #7a5c00;
    --sent: #7fe3d6;
    --sent-bg: #14332f;
    --recv: #b8b5ff;
    --recv-bg: #262456;
    --warn: #fcd34d;
    --warn-bg: #3a2e0c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}

main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 64px; }

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

code {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 0.9em;
  background: var(--accent-soft);
  padding: 1px 5px;
  border-radius: 4px;
}

mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }

.muted { color: var(--muted); font-weight: 400; }

/* ---------------------------------------------------------------- virsutine juosta */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand-nav { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.brand { font-weight: 650; font-size: 16px; text-decoration: none; color: var(--text); }
.brand-nav nav { display: flex; gap: 14px; }
.brand-nav nav a {
  text-decoration: none; font-size: 14px; color: var(--muted);
  padding: 3px 0; border-bottom: 2px solid transparent;
}
.brand-nav nav a.active { color: var(--text); border-bottom-color: var(--accent); }

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

.chip {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 11px;
  font-size: 13px;
}
.chip.link { text-decoration: none; color: var(--accent); }

.btn-sync {
  background: var(--accent); color: #fff; border: 0;
  border-radius: 999px; padding: 6px 16px;
  font: inherit; font-size: 13px; cursor: pointer;
}
.btn-sync:disabled { opacity: .55; cursor: default; }

/* ---------------------------------------------------------------- korteles */

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

.setup h2 { margin: 0 0 10px; font-size: 16px; }
.setup ol { margin: 0; padding-left: 22px; }
.setup li { margin: 6px 0; }
.setup li.done { color: var(--muted); }
.ok { color: var(--sent); font-weight: 600; margin-left: 6px; }
.todo { color: var(--warn); margin-left: 6px; }

/* ---------------------------------------------------------------- paieska */

.search {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 22px;
  margin-bottom: 22px;
}

.search-main { display: flex; gap: 10px; }

.search-main input {
  flex: 1;
  padding: 12px 14px;
  font: inherit; font-size: 16px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.search-main input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.search-main button {
  padding: 12px 24px;
  font: inherit; font-weight: 600;
  background: var(--accent); color: #fff;
  border: 0; border-radius: 9px; cursor: pointer;
}

.filters { margin-top: 14px; }
.filters summary { cursor: pointer; color: var(--muted); font-size: 14px; }

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.filter-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.filter-grid input, .filter-grid select {
  padding: 8px 10px; font: inherit; font-size: 14px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px;
}

.hint { margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.warn {
  margin: 10px 0 0; padding: 8px 12px; font-size: 13px;
  background: var(--warn-bg); color: var(--warn); border-radius: 7px;
}

/* ---------------------------------------------------------------- rezultatai */

.results-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 10px;
}
.results-head h2 { margin: 0; font-size: 17px; }
.toggle-sort { font-size: 13px; text-decoration: none; }

.grid {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.grid thead th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
}
.grid td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover { background: var(--accent-soft); }

.c-date { width: 108px; white-space: nowrap; }
.c-date .day { display: block; font-variant-numeric: tabular-nums; }
.c-date .time { display: block; font-size: 12px; color: var(--muted); }
.c-dir { width: 96px; }
.c-who { width: 230px; font-size: 13px; word-break: break-word; }

.tag { font-size: 12px; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.tag.sent { background: var(--sent-bg); color: var(--sent); }
.tag.recv { background: var(--recv-bg); color: var(--recv); }

.subject { font-weight: 600; text-decoration: none; }
.subject:hover { text-decoration: underline; }
.snippet { margin-top: 4px; font-size: 13px; color: var(--muted); }
.attach { margin-top: 4px; font-size: 12px; color: var(--muted); }
.gmail { display: inline-block; margin-top: 6px; font-size: 12px; text-decoration: none; }

.pager { display: flex; gap: 16px; align-items: center; justify-content: center; margin: 18px 0; font-size: 14px; }
.empty { color: var(--muted); }

.wrong-page {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; flex-wrap: wrap; font-size: 14px; line-height: 1.6;
  border-left: 4px solid var(--accent);
}
.wrong-page form { margin: 0; }
.wrong-page button {
  padding: 11px 20px; font: inherit; font-weight: 600; white-space: nowrap;
  background: var(--accent); color: #fff; border: 0; border-radius: 8px; cursor: pointer;
}

/* ---------------------------------------------------------------- laisko puslapis */

.message h1 { margin: 0 0 14px; font-size: 20px; }
.message .meta {
  display: grid; grid-template-columns: 110px 1fr; gap: 4px 12px;
  margin: 0 0 18px; padding-bottom: 16px; border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.message .meta dt { color: var(--muted); }
.message .meta dd { margin: 0; word-break: break-word; }
.message .body {
  margin: 0; white-space: pre-wrap; word-wrap: break-word;
  font: inherit; line-height: 1.6;
}

/* ---------------------------------------------------------------- sinchronizacija */

.sync-panel {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  width: min(520px, calc(100vw - 40px));
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 18px;
  box-shadow: 0 8px 28px rgba(0,0,0,.16);
}
.sync-msg { font-size: 14px; margin-bottom: 8px; }
.sync-bar { height: 6px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.sync-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.sync-panel.error .sync-fill { background: #dc2626; }

/* ---------------------------------------------------------------- saskaitos */

.paste-label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 8px; }

.search textarea {
  width: 100%; padding: 12px 14px;
  font: inherit; font-size: 14px; line-height: 1.5;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  resize: vertical;
}
.search textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }

.paste-actions { display: flex; align-items: center; gap: 16px; margin-top: 12px; flex-wrap: wrap; }
.paste-actions button {
  padding: 11px 24px; font: inherit; font-weight: 600;
  background: var(--accent); color: #fff; border: 0; border-radius: 9px; cursor: pointer;
}
.paste-actions .hint { margin: 0; flex: 1; min-width: 240px; }

.notice { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; font-size: 14px; }

.counts { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }

.badge { font-size: 12px; font-weight: 600; padding: 3px 11px; border-radius: 999px; white-space: nowrap; }
.badge.found   { background: var(--sent-bg); color: var(--sent); }
.badge.maybe   { background: var(--warn-bg); color: var(--warn); }
.badge.missing { background: #fee2e2; color: #b91c1c; }
@media (prefers-color-scheme: dark) {
  .badge.missing { background: #451a1a; color: #fca5a5; }
}

.invoice-item { border-left: 4px solid var(--line); }
.invoice-item.found   { border-left-color: var(--sent); }
.invoice-item.maybe   { border-left-color: var(--warn); }
.invoice-item.missing { border-left-color: #dc2626; }

.invoice-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.asked { font-weight: 600; }
.parsed { font-size: 13px; color: var(--muted); margin-top: 2px; }

.matches { list-style: none; margin: 0; padding: 0; }
.matches > li { border-top: 1px solid var(--line); padding: 12px 0; }
.matches > li:last-child { padding-bottom: 0; }

.match-row { display: flex; gap: 12px; align-items: flex-start; }
.match-row > input[type=checkbox] { margin-top: 4px; width: 17px; height: 17px; flex: 0 0 auto; }
.match-body { flex: 1; min-width: 0; }

.match-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.match-top .date { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.match-top .subject { font-weight: 600; text-decoration: none; }
.score {
  margin-left: auto; font-size: 12px; color: var(--muted);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 999px; padding: 1px 8px;
}
.who { font-size: 13px; color: var(--muted); margin-top: 3px; }
.match-body .snippet { margin-top: 4px; }

.why { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.why-tag {
  font-size: 11px; background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 2px 9px;
}

.files { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.file { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 3px 6px; border-radius: 6px; }
.file a { text-decoration: none; }
.file-hit { background: var(--sent-bg); }
.file-hit a { font-weight: 600; }

.files-note { margin-top: 8px; font-size: 12px; color: var(--sent); }
.files-note.muted { color: var(--muted); }

.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.preset {
  padding: 9px 16px; font: inherit; font-size: 14px; cursor: pointer;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  transition: background .15s, border-color .15s;
}
.preset:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.month-pick {
  display: flex; flex-direction: column; gap: 5px;
  max-width: 320px; font-size: 13px; color: var(--muted); margin-bottom: 4px;
}
.month-pick select {
  padding: 10px 12px; font: inherit; font-size: 15px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
}

.check-label { flex-direction: row !important; align-items: center; gap: 8px !important; align-self: end; padding-bottom: 9px; }
.check-label input { width: 17px; height: 17px; }
.toggle-all { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); margin-left: auto; }
.toggle-all input { width: 16px; height: 16px; }

.period-item { padding: 14px 18px; margin-bottom: 12px; }
.period-item .match-top { margin-bottom: 2px; }

.strict-toggle { margin-top: 14px; align-self: start !important; padding-bottom: 0 !important; font-size: 14px; color: var(--text) !important; }

.hidden-matches { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.hidden-matches summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.hidden-matches summary:hover { color: var(--accent); }
.hidden-matches .matches > li { border-top: 0; border-bottom: 1px solid var(--line); }
.hidden-matches .matches > li:last-child { border-bottom: 0; }

.ambiguous {
  margin-bottom: 12px; padding: 10px 13px; font-size: 13px; line-height: 1.5;
  background: var(--warn-bg); color: var(--warn); border-radius: 8px;
}

.collect h2 { margin: 0 0 12px; font-size: 16px; }
.collect-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.collect-row label { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 260px; font-size: 13px; color: var(--muted); }
.collect-row input {
  padding: 9px 11px; font: inherit; font-size: 14px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px;
}
.collect-row button {
  padding: 10px 20px; font: inherit; font-weight: 600;
  background: var(--accent); color: #fff; border: 0; border-radius: 8px; cursor: pointer;
}
.collect-result { margin-top: 14px; padding: 12px 14px; border-radius: 8px; font-size: 13px; }
.collect-result.ok { background: var(--sent-bg); color: var(--sent); }
.collect-result.error { background: var(--warn-bg); color: var(--warn); }
.collect-result ul { margin: 6px 0 0; padding-left: 20px; }

.collect-row button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }

.draft summary { cursor: pointer; font-weight: 600; }
.draft pre {
  margin: 10px 0; padding: 12px 14px; white-space: pre-wrap;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: 13px;
}

/* ---------------------------------------------------------------- prisijungimas */

body.centered {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}

.auth {
  width: 100%; max-width: 400px; margin: 0;
  display: flex; flex-direction: column; gap: 14px;
}
.auth h1 { margin: 0; font-size: 20px; }
.auth .hint { margin: 0; }
.auth label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.auth input {
  padding: 11px 13px; font: inherit; font-size: 15px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
}
.auth input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.auth button {
  padding: 12px; font: inherit; font-weight: 600; font-size: 15px;
  background: var(--accent); color: #fff; border: 0; border-radius: 8px; cursor: pointer;
}
.btn-link {
  display: inline-block; padding: 11px 22px; text-align: center;
  font-weight: 600; text-decoration: none;
  background: var(--accent); color: #fff; border-radius: 8px;
}

.auth-error {
  padding: 10px 13px; font-size: 13px; border-radius: 8px;
  background: var(--warn-bg); color: var(--warn);
}

.userbox { display: flex; align-items: center; gap: 12px; margin: 0; }
.userbox form { margin: 0; }

.auth-card { max-width: 460px; }
.auth-ok {
  padding: 10px 13px; margin-bottom: 14px; font-size: 13px; border-radius: 8px;
  background: var(--sent-bg); color: var(--sent);
}
.pw-form { display: flex; flex-direction: column; gap: 14px; margin-top: 4px; }
.pw-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.pw-form input {
  padding: 11px 13px; font: inherit; font-size: 15px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
}
.pw-form input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.pw-form button {
  padding: 12px; font: inherit; font-weight: 600; font-size: 15px;
  background: var(--accent); color: #fff; border: 0; border-radius: 8px; cursor: pointer;
}
.linkish {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; font-size: 13px; color: var(--accent); text-decoration: underline;
}

.audit-detail { font-size: 12px; color: var(--muted); word-break: break-word; max-width: 380px; }
.audit-fail td { background: var(--warn-bg); }

/* ---------------------------------------------------------------- admin */

.card h2 { margin: 0 0 14px; font-size: 16px; }

.credentials { border-left: 4px solid var(--sent); }
.credentials h2 { color: var(--sent); }
.credentials pre {
  margin: 12px 0; padding: 14px 16px; white-space: pre-wrap; word-break: break-all;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  font-family: "Cascadia Mono", Consolas, monospace; font-size: 14px; line-height: 1.7;
}

.notice-line { font-size: 14px; }
.notice-line.error { border-left: 4px solid #dc2626; color: #b91c1c; }
.notice-line.ok { border-left: 4px solid var(--sent); }
@media (prefers-color-scheme: dark) { .notice-line.error { color: #fca5a5; } }

.admin-form .filter-grid { margin-top: 0; }
.admin-form .paste-actions { margin-top: 16px; }

.row-actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row-actions form { margin: 0; }
.linkish.danger { color: #dc2626; }
