:root {
  --bg: #ffffff;
  --text: #152f4e;
  --accent: #009ee0;
  --muted: #e8eff7;
  --subtle: #e0d5bb;
  --border: #f0f0f0;
  --surface: #f8f8f8;
  --danger: #c0392b;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0e14;
    --text: #d4dae0;
    --accent: #48abf7;
    --muted: #151b23;
    --subtle: #1a2028;
    --border: #1e2630;
    --surface: #11171f;
  }
}

[data-theme="dark"] {
  --bg: #0a0e14;
  --text: #d4dae0;
  --accent: #48abf7;
  --muted: #151b23;
  --subtle: #1a2028;
  --border: #1e2630;
  --surface: #11171f;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ---- login ---- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-box {
  text-align: center;
  width: 340px;
  max-width: 90vw;
}

.login-box h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}

.login-box .subtitle {
  font-size: 0.85rem;
  color: #999;
  margin-bottom: 36px;
}

.login-box input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 16px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
}

.login-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  display: inline-block;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn-primary:hover { opacity: 0.85; }

.btn-beige {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-beige:hover { background: var(--surface); }

.btn-small { padding: 6px 14px; font-size: 0.8rem; }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--border);
}

.btn-danger:hover { background: #fef2f2; }

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 12px;
  min-height: 20px;
}

/* ---- dashboard ---- */
#dashboard { display: none; }

.topbar {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.topbar-actions { display: flex; gap: 8px; align-items: center; }

.container { max-width: 720px; margin: 0 auto; padding: 32px 16px; }

/* ---- groups ---- */
.group-card {
  border-bottom: 1px solid var(--border);
}

.group-header {
  padding: 14px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s;
}

.group-header:hover { opacity: 0.7; }

.group-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.group-header .arrow {
  color: #ccc;
  font-size: 0.9rem;
  transition: transform 0.2s;
}

.group-header.open .arrow { transform: rotate(90deg); }

.group-body { display: none; overflow: hidden; }
.group-body.open { display: block; }

/* ---- file list ---- */
.file-list { padding-bottom: 8px; }

.file-item {
  display: flex;
  align-items: center;
  padding: 10px 0;
  gap: 12px;
}

.file-icon { font-size: 1.1rem; width: 24px; text-align: center; flex-shrink: 0; }

.file-info { flex: 1; min-width: 0; }
.file-name { font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.9rem; }
.file-meta { font-size: 0.78rem; color: #aaa; margin-top: 2px; }

.file-actions { display: flex; gap: 4px; flex-shrink: 0; }

.icon-btn {
  width: 30px; height: 30px;
  border: none; background: transparent;
  border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.95rem; color: #bbb;
  transition: all 0.15s;
}

.icon-btn:hover { background: var(--surface); color: var(--accent); }
.icon-btn.danger:hover { color: var(--danger); }

.cat-header {
  padding: 12px 0 6px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  opacity: 0.6;
}

.more-btn-wrap { padding: 8px 0 12px; text-align: center; }

/* ---- upload zone ---- */
.upload-zone {
  border: 1px dashed var(--border);
  border-radius: 8px;
  margin-top: 12px;
  padding: 20px;
  text-align: center;
}

.upload-zone label {
  display: inline-block;
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
}

.upload-zone label:hover { opacity: 0.85; }
.upload-zone input[type="file"] { display: none; }

.cat-select {
  margin-top: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.8rem;
}

/* ---- modal ---- */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 200;
  align-items: center; justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
  width: 360px; max-width: 90vw;
}

.modal-box h3 { margin-bottom: 12px; font-size: 1rem; }
.modal-box p { font-size: 0.82rem; color: #999; margin-bottom: 16px; }

.modal-box input {
  width: 100%; padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px; font-size: 0.9rem;
  margin-bottom: 14px; background: var(--surface); color: var(--text);
}

.modal-box input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ---- admin ---- */
#admin-panel { display: none; }

.admin-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 24px; }

.admin-tab {
  padding: 10px 18px; border: none; background: transparent;
  font-size: 0.85rem; font-weight: 600; color: #999;
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}

.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display: none; }
.tab-content.active { display: block; }

.cred-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; background: var(--surface);
  border-radius: 6px; margin-bottom: 6px;
}

.cred-label { font-weight: 600; min-width: 70px; font-size: 0.85rem; }
.cred-value { flex: 1; font-family: monospace; font-size: 0.82rem; padding: 4px 8px; color: #999; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.admin-table th { text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--border); color: var(--text); font-weight: 700; font-size: 0.8rem; }
.admin-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); }

pre#keys-output { margin-top: 14px; padding: 14px; background: var(--surface); border-radius: 6px; font-size: 0.8rem; white-space: pre-wrap; word-break: break-all; color: #666; }

/* ---- responsive ---- */
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .container { padding: 24px 12px; }
  .admin-tabs { flex-wrap: wrap; gap: 4px; }
}
