:root {
  --bg: #0f1220;
  --bg-2: #161a2e;
  --card: #1b2039;
  --card-2: #222848;
  --line: #2c3358;
  --text: #e7e9f3;
  --muted: #a7abc3;
  --muted-2: #7c81a3;
  --accent: #6d5efc;
  --accent-2: #8b7bff;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1c2140 0%, var(--bg) 55%) fixed;
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent-2); }

/* ---------- login ---------- */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; }
.brand-icon { font-size: 26px; }
.brand-name strong { color: var(--accent-2); }
.login-brand { margin-bottom: 18px; }
.login-card h1 { font-size: 22px; margin: 4px 0 6px; }
.login-hint { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted-2); font-size: 12px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input, textarea, select {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 14px;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 76px; }

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  padding: 11px 16px;
  transition: transform .05s, background .15s, opacity .15s;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; width: 100%; }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }
.btn-sm { padding: 6px 10px; font-size: 12px; font-weight: 500; }
.btn-danger { background: transparent; color: var(--red); border: 1px solid #46304a; }
.btn-danger:hover { background: #3a2231; }

.login-error { color: var(--red); font-size: 13px; margin: 10px 0 0; }
.login-note { color: var(--green); font-size: 13px; margin: 10px 0 0; }

/* ---------- app shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  padding: 12px 20px;
  background: rgba(15, 18, 32, 0.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { font-size: 17px; }
.nav { display: flex; gap: 4px; margin-left: 10px; }
.nav a {
  color: var(--muted); text-decoration: none; font-weight: 500; font-size: 14px;
  padding: 8px 14px; border-radius: 9px;
}
.nav a:hover { color: var(--text); background: var(--card); }
.nav a.active { color: #fff; background: var(--accent); }
.topbar .spacer { flex: 1; }
.who { color: var(--muted); font-size: 13px; }
.who .role { color: var(--accent-2); font-weight: 600; text-transform: uppercase; font-size: 11px; margin-left: 6px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 20px 80px; }
.view { display: none; }
.view.active { display: block; }

h2.title { font-size: 20px; margin: 0 0 4px; }
.subtitle { color: var(--muted); font-size: 14px; margin: 0 0 22px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.hint { color: var(--muted-2); font-size: 12px; margin-top: 5px; }

/* ---------- generate ---------- */
.gen-layout { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 20px; align-items: start; }
.cost-preview { color: var(--muted); font-size: 13px; }
.cost-preview b { color: var(--amber); }
.result-empty {
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  min-height: 320px; display: grid; place-items: center; text-align: center;
  color: var(--muted-2); padding: 30px;
}
.result-img { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); display: block; }
.cost-badge {
  display: inline-flex; align-items: center; gap: 8px;
  background: #14351f; color: var(--green); border: 1px solid #1e5233;
  padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: 14px;
}
.cost-badge.est { background: #3a3210; color: var(--amber); border-color: #5a4d15; }
.meta-list { list-style: none; padding: 0; margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.meta-list li { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--line); }
.meta-list li span:last-child { color: var(--text); }

/* ---------- library ---------- */
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.stat {
  flex: 1; min-width: 150px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat .n { font-size: 24px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .n.spend { color: var(--amber); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  background: var(--card); border: 1px solid var(--line); color: var(--muted);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip .c { opacity: .7; margin-left: 5px; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tile .thumb { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; background: var(--bg-2); display: block; cursor: pointer; }
.tile .body { padding: 12px; }
.tile .post { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.tile .prompt { color: var(--muted); font-size: 12px; max-height: 48px; overflow: hidden; }
.tile .tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 8px; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: var(--card-2); color: var(--muted); }
.tag.cost { color: var(--amber); }
.tag.owner { color: var(--accent-2); }
.tile .acts { display: flex; gap: 6px; }
.tile .acts a, .tile .acts button { flex: 1; text-align: center; text-decoration: none; }

.empty { text-align: center; color: var(--muted-2); padding: 60px 20px; }

/* ---------- tables (settings) ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.pill.admin { background: #2a2350; color: var(--accent-2); }
.pill.member { background: var(--card-2); color: var(--muted); }
.section-gap { margin-top: 24px; }
.keys-status span { display: inline-flex; align-items: center; gap: 6px; margin-right: 16px; font-size: 13px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--green); } .dot.off { background: var(--red); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6, 8, 16, .8); z-index: 50;
  display: none; place-items: center; padding: 24px;
}
.modal-backdrop.open { display: grid; }
.modal { max-width: 90vw; max-height: 90vh; }
.modal img { max-width: 100%; max-height: 78vh; border-radius: var(--radius); display: block; }
.modal .cap { text-align: center; color: var(--muted); font-size: 13px; margin-top: 10px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 60;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }
.toast.err { border-color: #5a2a2a; color: #ffd5d5; }

.spinner {
  width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff; border-radius: 50%; display: inline-block;
  animation: spin .7s linear infinite; vertical-align: -3px; margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- brand + dashboard ---------- */
.brand-sub { color: var(--muted); font-weight: 500; font-size: 12px; }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 8px; }
.dash-card {
  display: block; text-decoration: none; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 24px; box-shadow: var(--shadow); transition: transform .08s, border-color .15s;
}
.dash-card:hover { border-color: var(--accent); }
.dash-icon { font-size: 34px; margin-bottom: 10px; }
.dash-card h3 { margin: 0 0 6px; font-size: 18px; }
.dash-card p { color: var(--muted); font-size: 14px; margin: 0 0 16px; min-height: 40px; }
.dash-tiles { display: flex; gap: 12px; margin: 0 0 18px; }
.dash-tile { flex: 1; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.dash-n { font-size: 22px; font-weight: 700; }
.dash-n.spend { color: var(--amber); }
.dash-l { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }
.dash-btn { display: block; text-align: center; text-decoration: none; }

/* ---------- model search ---------- */
.search-results { margin-top: 8px; max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.search-results:empty { display: none; }
.search-item { display: flex; justify-content: space-between; gap: 10px; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); font-size: 13px; }
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--card-2); }
.search-item .air { color: var(--muted-2); font-family: monospace; font-size: 12px; white-space: nowrap; }

.linkish { color: var(--accent-2); cursor: pointer; font-size: 12px; font-weight: 500; }
.linkish:hover { text-decoration: underline; }

/* ---------- progress ---------- */
.progress-wrap { padding: 26px 6px; }
.progress { height: 10px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.progress-bar {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  background-size: 200% 100%; animation: shimmer 1.4s linear infinite; transition: width .4s ease;
}
.progress-bar.err { background: var(--red); animation: none; }
@keyframes shimmer { to { background-position: 200% 0; } }
.progress-label { color: var(--muted); font-size: 13px; margin-top: 10px; text-align: center; }

/* ---------- article (markdown) ---------- */
.article { font-size: 15px; line-height: 1.65; color: var(--text); overflow-wrap: anywhere; }
.article h1 { font-size: 24px; margin: 4px 0 12px; }
.article h2 { font-size: 20px; margin: 22px 0 8px; }
.article h3 { font-size: 16px; margin: 18px 0 6px; }
.article p { margin: 0 0 12px; }
.article ul, .article ol { margin: 0 0 12px; padding-left: 22px; }
.article li { margin: 4px 0; }
.article a { color: var(--accent-2); }
.article code { background: var(--card-2); padding: 1px 6px; border-radius: 5px; font-size: 13px; }
.modal .article { max-height: 74vh; overflow-y: auto; background: var(--card); padding: 24px; border-radius: var(--radius); text-align: left; }

/* ---------- content library rows ---------- */
.content-row { margin-bottom: 12px; }
.content-row .post { font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.content-row .excerpt { color: var(--muted); font-size: 13px; }

@media (max-width: 820px) {
  .gen-layout, .grid-2, .dash-grid { grid-template-columns: 1fr; }
  .nav a { padding: 8px 10px; }
}
