:root {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --text: #1c2333;
  --muted: #66708a;
  --border: #dde2ec;
  --accent: #3b5bdb;
  --accent-dark: #2f4ab8;
  --danger: #d6455b;
  --ok: #2f9e63;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 60, 0.08), 0 4px 16px rgba(20, 30, 60, 0.06);
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top nav ---------- */
.topnav {
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0 22px;
  height: 54px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topnav .brand { font-weight: 700; font-size: 16px; color: var(--text); }
.topnav .brand span { color: var(--accent); }
.topnav nav { display: flex; gap: 4px; }
.topnav nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
}
.topnav nav a:hover { background: var(--bg); text-decoration: none; }
.topnav nav a.active { background: var(--accent); color: #fff; }
.topnav .spacer { flex: 1; }
.quota-badge {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 13px;
  color: var(--muted);
}
.quota-badge b { color: var(--text); }
.quota-badge.low b { color: var(--danger); }
.topnav .user-menu { position: relative; }
.topnav .user-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
}
.topnav .dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 180px;
  display: none;
  flex-direction: column;
  padding: 6px;
}
.topnav .dropdown.open { display: flex; }
.topnav .dropdown button {
  background: none;
  border: 0;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
}
.topnav .dropdown button:hover { background: var(--bg); }

/* ---------- layout ---------- */
.page { max-width: 1200px; margin: 26px auto; padding: 0 22px; }
.page h1 { font-size: 22px; margin: 0 0 18px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- forms ---------- */
label { display: block; font-weight: 600; font-size: 13px; margin: 12px 0 4px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
input[type="text"], input[type="password"], input[type="number"], input[type="url"], select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-weight: 500; font-size: 14px; }
.check input { width: 16px; height: 16px; }

details.opts {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 12px;
  padding: 0 14px;
  background: #fafbfe;
}
details.opts summary {
  cursor: pointer;
  font-weight: 600;
  padding: 10px 0;
  color: var(--text);
  user-select: none;
}
details.opts > div { padding-bottom: 14px; }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--accent-dark); }
.btn:disabled { background: #aab3cc; cursor: not-allowed; }
.btn.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #e8ecf4; }
.btn.small { padding: 5px 10px; font-size: 13px; font-weight: 500; }
.btn.danger { background: var(--danger); }

.msg { border-radius: 8px; padding: 10px 14px; margin: 12px 0; font-size: 14px; display: none; }
.msg.error { display: block; background: #fdecef; color: #9c2338; border: 1px solid #f5c6cf; }
.msg.ok { display: block; background: #e8f7ef; color: #1d6b43; border: 1px solid #bfe6d1; }

/* ---------- dropzone ---------- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.drag { border-color: var(--accent); background: #eef2ff; }
.dropzone img { max-width: 100%; max-height: 240px; border-radius: 6px; }
.dropzone .dz-note { margin-top: 8px; font-size: 13px; }

/* ---------- result ---------- */
.checkerboard {
  background-image: conic-gradient(#e3e6ee 25%, #fff 0 50%, #e3e6ee 0 75%, #fff 0);
  background-size: 20px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.checkerboard img { max-width: 100%; max-height: 480px; display: block; }
.result-meta { display: flex; align-items: center; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
.result-meta .credits { font-size: 14px; color: var(--muted); }
.result-meta .credits b { color: var(--text); }

.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
td img.thumb { width: 54px; height: 54px; object-fit: contain; border-radius: 6px; background: #eee; }
.status-ok { color: var(--ok); font-weight: 600; }
.status-error { color: var(--danger); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.usagebar { background: var(--bg); border-radius: 999px; height: 8px; width: 120px; overflow: hidden; }
.usagebar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.usagebar i.over { background: var(--danger); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 360px; }
.login-card h1 { text-align: center; font-size: 20px; margin-bottom: 6px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 12px; }

/* ---------- stat cards ---------- */
.stats { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.stat {
  flex: 1;
  min-width: 160px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  width: 340px;
}
dialog::backdrop { background: rgba(20, 30, 60, 0.35); }
dialog h2 { margin: 0 0 8px; font-size: 17px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.section-title { font-size: 17px; font-weight: 700; margin: 26px 0 12px; }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar label { margin: 0; }
.toolbar select { width: auto; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 16px; }
