:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --text-dim: #9aa0ab;
  --accent: #5b8cff;
  --red: #e5484d;
  --yellow: #e8b339;
  --green: #3fb950;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

/* ---------- login ---------- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 280px;
  text-align: center;
}

.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .subtitle { margin: 0 0 24px; color: var(--text-dim); font-size: 13px; }

.login-card input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
}

.login-card button {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: white;
  font-size: 14px;
  cursor: pointer;
}

.login-card .error { color: var(--red); font-size: 13px; margin: 0 0 12px; }

/* ---------- layout ---------- */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

header h1 { margin: 0; font-size: 18px; }

.logout { color: var(--text-dim); font-size: 13px; text-decoration: none; }
.logout:hover { color: var(--text); }

main {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  padding: 24px;
  max-width: 1100px;
  margin: 0 auto;
}

@media (max-width: 800px) {
  main { grid-template-columns: 1fr; }
}

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

.card h2 { margin: 0 0 14px; font-size: 14px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

/* ---------- search ---------- */

#searchForm { display: flex; gap: 8px; margin-bottom: 20px; }

#query {
  flex: 1;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
}

#searchForm button {
  padding: 12px 20px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  font-size: 14px;
}

.result-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color .15s;
}

.result-item:hover { border-color: var(--accent); }

.result-title { font-weight: 600; margin-bottom: 4px; }
.result-meta { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.result-preview { font-size: 13px; color: var(--text-dim); }

.empty-state { color: var(--text-dim); font-size: 14px; padding: 12px 0; }

/* ---------- donut ---------- */

.donut-wrap { position: relative; width: 140px; height: 140px; margin: 0 auto 14px; }

.donut { width: 100%; height: 100%; transform: rotate(-90deg); }

.donut-ring { fill: none; stroke: var(--panel-2); stroke-width: 16; }

.donut-seg {
  fill: none;
  stroke-width: 16;
  transition: stroke-dasharray .4s ease, stroke-dashoffset .4s ease;
}

.seg-other { stroke: var(--red); }
.seg-db { stroke: var(--yellow); }
.seg-free { stroke: var(--green); }

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
}

.legend { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 3px 0; color: var(--text-dim); }
.legend .swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.legend .val { margin-left: auto; color: var(--text); }

/* ---------- upload ---------- */

.hint { font-size: 12.5px; color: var(--text-dim); margin: 0 0 12px; }
#fileInput { font-size: 13px; color: var(--text-dim); }
.upload-status { margin-top: 12px; font-size: 12.5px; }
.upload-row { padding: 4px 0; }
.upload-row.ok { color: var(--green); }
.upload-row.fail { color: var(--red); }

.drop-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(91, 140, 255, .15);
  border: 3px dashed var(--accent);
  z-index: 50;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 600;
  pointer-events: none;
}

body.dragging .drop-overlay { display: flex; }

/* ---------- detail modal ---------- */

.detail-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 100;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
}

body.detail-open .detail-overlay { display: flex; }

.detail-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 700px;
  width: 100%;
  padding: 28px;
  position: relative;
}

.detail-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}

.detail-close:hover { color: var(--text); }

.detail-body { white-space: pre-wrap; font-size: 14px; line-height: 1.6; }
