:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16181d;
  --muted: #646b78;
  --border: #dfe2e7;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --danger: #c92a2a;
  --ok-bg: #e6f4ea;
  --ok-text: #1e6b34;
  --err-bg: #fdecec;
  --err-text: #a51d1d;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #20242c;
    --text: #e7e9ee;
    --muted: #9aa1ad;
    --border: #2a2f38;
    --accent: #7c93f5;
    --accent-text: #0f1115;
    --danger: #ff6b6b;
    --ok-bg: #16311f;
    --ok-text: #8fd6a4;
    --err-bg: #3a1618;
    --err-text: #ffa3a3;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .75rem; letter-spacing: -.01em; }
h2 { font-size: 1rem; margin: 1.5rem 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.container { width: 100%; max-width: 1100px; margin: 0 auto; padding: 1.5rem 16px 3rem; flex: 1; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .75rem 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar nav { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; justify-content: flex-end; }
.topbar nav a, .topbar nav .linklike { color: var(--muted); font-size: .92rem; }
.topbar nav form { margin: 0; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 650; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: var(--accent); color: var(--accent-text); font-weight: 700;
}
.logo.big { width: 52px; height: 52px; font-size: 1.5rem; border-radius: 14px; }

footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 1.5rem 16px; }

/* Dashboard */
.hero { margin: .5rem 0 1.5rem; }
.hero-actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }
.search { width: 100%; max-width: 420px; flex: 1 1 240px; }
.group h2 { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .75rem; }
.tile {
  display: flex; align-items: center; gap: .85rem; padding: .9rem 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); box-shadow: var(--shadow); transition: transform .12s ease, border-color .12s ease;
  min-width: 0;
}
.tile:hover, .tile:focus-visible { text-decoration: none; border-color: var(--accent); transform: translateY(-1px); }
.tile-text { display: flex; flex-direction: column; min-width: 0; }
.tile-text strong { font-weight: 600; }
.tile-text small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon {
  flex: none; width: 44px; height: 44px; border-radius: 10px; background: var(--surface-2);
  display: grid; place-items: center; overflow: hidden; position: relative;
}
.icon img { width: 30px; height: 30px; object-fit: contain; }
.icon.fallback::after, .icon:empty::after {
  content: attr(data-letter); font-weight: 700; color: var(--accent); font-size: 1.1rem;
}
.badge {
  display: inline-block; font-size: .68rem; font-weight: 600; padding: 0 .4rem; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); vertical-align: middle; border: 1px solid var(--border);
}

/* Forms & buttons */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: .55rem .7rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: auto; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; font-weight: 500; }
label small { font-weight: 400; }
label.check { flex-direction: row; align-items: center; gap: .45rem; font-weight: 400; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; padding: .55rem 1rem; border-radius: 8px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-text); cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(1.07); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-block { width: 100%; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.linklike.danger { color: var(--danger); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card.highlight { border-color: var(--accent); }
.narrow { max-width: 520px; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash-ok { background: var(--ok-bg); color: var(--ok-text); }
.flash-error { background: var(--err-bg); color: var(--err-text); }

/* Auth pages */
.auth-page { flex: 1; display: grid; place-items: center; padding: 2rem 16px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-head { text-align: center; margin-bottom: 1.25rem; }
.auth-head h1 { margin: .75rem 0 .1rem; }
.auth-head p { margin: 0; }
.auth-card .flash { margin-top: 0; }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .85rem; margin: 1rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* Admin */
.admin { display: grid; grid-template-columns: 190px 1fr; gap: 2rem; }
.admin-nav { display: flex; flex-direction: column; gap: .15rem; }
.admin-nav h2 { margin: 0 0 .5rem; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
.admin-nav a { padding: .45rem .7rem; border-radius: 8px; color: var(--text); }
.admin-nav a:hover { background: var(--surface-2); text-decoration: none; }
.admin-nav a.active { background: var(--surface); border: 1px solid var(--border); font-weight: 600; }
.admin-body { min-width: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.row-between h1 { margin: 0; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-top: 1rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
tr.dim td { opacity: .5; }
td.url { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
td.actions form { display: inline; margin-left: .6rem; }
.card table th, .card table td { padding-left: 0; }
.num { width: 90px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid .wide { grid-column: 1 / -1; }
.checks { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.inline-form { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.inline-form input:not([type=checkbox]), .inline-form select { width: auto; flex: 1 1 180px; }
.inline-form .num { flex: 0 0 90px; }
.card-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.copy-row { display: flex; gap: .5rem; }
code { font-size: .85em; background: var(--surface-2); padding: .1rem .35rem; border-radius: 5px; }

@media (max-width: 760px) {
  .admin { grid-template-columns: 1fr; gap: 1rem; }
  .admin-nav { flex-direction: row; flex-wrap: wrap; }
  .admin-nav h2 { display: none; }
  .form-grid, .card-row { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  td.url { max-width: 140px; }
}
