:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e6e8ec;
  --soft: #f1f3f6;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #e8efff;
  --ok: #0f9d6b;
  --err: #d93025;
  --err-soft: #fdecea;
  --info-soft: #e8f1fd;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --card: #161a20;
    --text: #e8eaee;
    --muted: #9aa3b2;
    --line: #262b34;
    --soft: #1d222a;
    --accent: #4f8cff;
    --accent-soft: #1b2a47;
    --err-soft: #3a1714;
    --info-soft: #14243b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h2 { font-size: 20px; }
h3 { font-size: 16px; font-weight: 600; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
code { background: var(--soft); padding: 1px 6px; border-radius: 6px; font-size: 13px; }
.muted { color: var(--muted); }
.sm { font-size: 13px; }
.center { text-align: center; }

.wrap { max-width: 1000px; margin: 0 auto; padding: 24px 20px 60px; }
.wrap.wide { max-width: 1400px; }

/* Top bar */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-in { display: flex; align-items: center; justify-content: space-between; padding-top: 12px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); font-size: 16px; }
.brand:hover { text-decoration: none; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #7c3aed); display: inline-block; position: relative; }
.logo::after { content: ""; position: absolute; inset: 8px 7px; border: 2px solid #fff; border-top-width: 5px; border-radius: 2px; }
.logo.lg { width: 48px; height: 48px; border-radius: 13px; }
.logo.lg::after { inset: 13px 12px; border-top-width: 7px; }
.user { display: flex; align-items: center; gap: 10px; }
.user form { margin: 0; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.uname { font-weight: 500; }
@media (max-width: 560px) { .uname { display: none; } }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--soft); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; height: 44px; }
.btn:focus-visible, input:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 1px; border-color: var(--accent); }

/* Inputs */
input[type=text], input[type=password], input[type=search], input:not([type]) {
  height: 42px; width: 100%; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit;
}
.search { max-width: 320px; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.empty { padding: 40px 20px; text-align: center; }
.empty h2, .empty h3 { margin-bottom: 8px; }
.empty .btn { margin-top: 12px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 32px 28px; box-shadow: var(--shadow); }
.login-head { text-align: center; margin-bottom: 22px; }
.login-head h1 { font-size: 22px; margin: 14px 0 4px; }
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; }
.pw { position: relative; display: block; }
.pw input { padding-right: 64px; }
.pw-toggle { position: absolute; right: 6px; top: 6px; height: 30px; padding: 0 10px; border: 0; border-radius: 7px; background: var(--soft); color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; }
.alert { padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; }
.alert.err { background: var(--err-soft); color: var(--err); }
.alert.info { background: var(--info-soft); color: var(--accent); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 28px; }
@media (max-width: 760px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 4px; box-shadow: var(--shadow); }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Toolbar */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }

/* Day groups */
.day { margin-bottom: 14px; overflow: hidden; }
.day-head { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.day-title { flex: 1; min-width: 0; display: grid; gap: 2px; }
.day-title .muted { font-size: 13px; }
.date-chip { width: 48px; height: 52px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; align-content: center; line-height: 1.05; flex: none; }
.dc-day { font-size: 19px; font-weight: 800; }
.dc-mon { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: #dcfce7; color: #166534; vertical-align: 2px; margin-left: 6px; }
@media (prefers-color-scheme: dark) { .badge { background: #12341f; color: #6ee7a0; } }

.files { list-style: none; margin: 0; padding: 0; }
.file { display: flex; align-items: center; gap: 14px; padding: 12px 16px; }
.file + .file { border-top: 1px solid var(--line); }
.file:hover { background: var(--soft); }
.ficon { width: 40px; height: 40px; border-radius: 9px; background: #e7f6ee; color: var(--ok); font-size: 11px; font-weight: 800; display: grid; place-items: center; flex: none; }
@media (prefers-color-scheme: dark) { .ficon { background: #0f2a1f; } }
.fmeta { flex: 1; min-width: 0; display: grid; }
.fname { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.factions { display: flex; gap: 8px; flex: none; }
@media (max-width: 560px) {
  .file { flex-wrap: wrap; }
  .factions { width: 100%; padding-left: 54px; }
  .factions .btn { flex: 1; }
  .day-head .btn { display: none; }
}

/* Viewer */
.crumbs { margin-bottom: 10px; font-size: 14px; }
.view-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.view-head h2 { font-size: 18px; word-break: break-all; }
.view-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.searchform { display: flex; gap: 8px; margin: 0; }
.searchform .search { width: 300px; height: 38px; }
@media (max-width: 640px) { .searchform, .searchform .search { width: 100%; max-width: none; } .view-actions { width: 100%; } }

.table-card { overflow: hidden; }
.table-scroll { overflow: auto; max-height: calc(100vh - 230px); }
.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13.5px; }
.grid th, .grid td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.grid th { position: sticky; top: 0; background: var(--soft); font-weight: 600; font-size: 12.5px; cursor: pointer; user-select: none; z-index: 1; }
.grid th:hover { color: var(--accent); }
.grid th.asc::after { content: " ▲"; font-size: 9px; }
.grid th.desc::after { content: " ▼"; font-size: 9px; }
.grid tbody tr:hover td { background: var(--accent-soft); }
.grid td.num, .grid th.num { color: var(--muted); font-variant-numeric: tabular-nums; width: 1%; cursor: default; }
.grid td { cursor: copy; }
.pager { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 10px; font-size: 13px; opacity: 0; transition: .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%); }
