/* Weave Links — vanilla CSS */
:root {
  --bg: #0f1220;
  --surface: #181c2f;
  --surface-2: #1f2438;
  --border: #2b3150;
  --text: #e8eaf3;
  --muted: #9aa0be;
  --primary: #5b7cfa;
  --primary-dark: #4762d8;
  --danger: #e5484d;
  --ok: #37b679;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .3rem; }
h2 { font-size: 1.1rem; }
em { font-style: normal; color: var(--danger); }
small { color: var(--muted); font-weight: 400; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.num { text-align: right; }
.big { font-size: 1.25rem; font-weight: 600; }

/* ---- Layout ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-admin { border-bottom-color: var(--primary); }
.topbar nav { display: flex; align-items: center; gap: 16px; }
.brand { font-weight: 800; font-size: 1.2rem; color: var(--text); }
.brand span { color: var(--primary); }
.brand-lg { font-size: 1.8rem; display: block; text-align: center; margin-bottom: .4rem; }
.navlink { color: var(--muted); font-weight: 500; }
.navlink:hover { color: var(--text); text-decoration: none; }
.who { color: var(--muted); font-size: .85rem; }
.container { max-width: 1080px; margin: 0 auto; padding: 28px 24px 60px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 24px; }

.page-head { margin-bottom: 20px; }
.back { display: inline-block; margin-bottom: 8px; color: var(--muted); }

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 20px;
}
.card-title { margin: 0 0 16px; font-size: 1rem; color: var(--text); }

/* ---- Forms ---- */
.form label { display: block; margin-bottom: 14px; }
.form label > span { display: block; font-size: .85rem; margin-bottom: 6px; color: var(--muted); }
input, select {
  width: 100%; padding: 11px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: .95rem; outline: none;
}
input:focus, select:focus { border-color: var(--primary); }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.grid-form .col-2 { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; gap: 14px; margin-top: 6px; }
.prefixed { display: flex; align-items: stretch; }
.prefixed .prefix {
  display: flex; align-items: center; padding: 0 10px; background: var(--surface);
  border: 1px solid var(--border); border-right: 0; border-radius: 9px 0 0 9px;
  color: var(--muted); font-family: ui-monospace, monospace; font-size: .9rem;
}
.prefixed input { border-radius: 0 9px 9px 0; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 15px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: .9rem; font-weight: 500;
  cursor: pointer; text-decoration: none; transition: .12s;
}
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; }
.btn-danger { color: #fff; background: transparent; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: .8rem; }
.btn-block { width: 100%; }

/* ---- Alerts ---- */
.alert { padding: 12px 16px; border-radius: 9px; margin-bottom: 18px; font-size: .9rem; word-break: break-word; }
.alert-error { background: rgba(229,72,77,.12); border: 1px solid var(--danger); color: #ffb4b6; }
.alert-success { background: rgba(55,182,121,.12); border: 1px solid var(--ok); color: #9be9c2; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.table tr:last-child td { border-bottom: 0; }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions-col { width: 1%; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions form { margin: 0; }
.log-table .is-bot { opacity: .55; }

/* ---- Tags / chips ---- */
.tag { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: .72rem; background: var(--surface-2); border: 1px solid var(--border); }
.tag-admin { color: #ffd27a; border-color: #6b5a2a; }
.tag-user { color: #9db4ff; }
.tag-ok { color: #9be9c2; border-color: #2e6b4e; }
.tag-off { color: #ffb4b6; border-color: #6b2e30; }
.notes { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 5px; }
.note-chip { font-size: .72rem; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }

/* ---- Stat grid ---- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-num { font-size: 1.9rem; font-weight: 800; }
.stat-lbl { color: var(--muted); font-size: .82rem; }

.breakdown-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ---- Bars ---- */
.bars { list-style: none; margin: 0; padding: 0; }
.bars li { margin-bottom: 12px; }
.bar-row { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: 4px; }
.bar-label { color: var(--text); }
.bar-val { color: var(--muted); }
.bar-val em { font-size: .78rem; }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 6px; }

/* ---- Day chart ---- */
.daychart { display: flex; align-items: flex-end; gap: 6px; height: 160px; overflow-x: auto; padding-top: 10px; }
.daybar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; min-width: 28px; }
.daybar-fill { width: 18px; background: var(--primary); border-radius: 4px 4px 0 0; }
.daybar-lbl { font-size: .62rem; color: var(--muted); margin-top: 5px; transform: rotate(-45deg); white-space: nowrap; }

.link-summary { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.report-actions { margin-top: 12px; display: flex; gap: 8px; }

/* ---- Chart boxes ---- */
.chart-box { position: relative; height: 240px; }
.chart-box.chart-tall { height: 300px; }
.breakdown-wide { grid-column: 1 / -1; }

/* ---- Auth screens ---- */
.auth-body { display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); }
.auth-head { text-align: center; margin-bottom: 22px; }
.error-card { text-align: center; }
.error-code { font-size: 3.5rem; font-weight: 800; color: var(--primary); }

/* ---- Search ---- */
.searchbar { display: flex; gap: 10px; margin-bottom: 18px; }
.searchbar input { max-width: 480px; }

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.modal-box { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 26px; width: 340px; max-width: 92vw; box-shadow: var(--shadow); text-align: center; }
.modal-box h3 { margin: 0 0 16px; }
.modal-close { position: absolute; top: 10px; right: 14px; background: none; border: 0; color: var(--muted); font-size: 1.6rem; cursor: pointer; line-height: 1; }
.qr-canvas { display: flex; justify-content: center; padding: 14px; background: #fff; border-radius: 10px; margin-bottom: 12px; }
.qr-canvas img, .qr-canvas canvas { display: block; }
#qr-url { word-break: break-all; margin: 0 0 14px; }
.modal-box label { text-align: left; }

/* ---- Responsive ---- */
@media (max-width: 720px) {
  .grid-form, .breakdown-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .topbar { padding: 12px 16px; }
  .topbar nav { gap: 10px; }
  .container { padding: 20px 14px 50px; }
}
