:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f2f8;
  --text: #171a2b;
  --muted: #646a85;
  --border: #e3e5ef;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;
  --on-primary: #ffffff;
  --success: #0f9d6b;
  --danger: #d93a3a;
  --danger-soft: #fdeeee;
  --shadow: 0 1px 2px rgba(20, 24, 50, .05), 0 8px 24px rgba(20, 24, 50, .06);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1120;
    --surface: #181b2e;
    --surface-2: #20243a;
    --text: #eceefa;
    --muted: #9da3c0;
    --border: #2b3050;
    --primary: #7c74ff;
    --primary-hover: #918aff;
    --primary-soft: #262a52;
    --on-primary: #ffffff;
    --success: #34c48f;
    --danger: #ff6b6b;
    --danger-soft: #3a2026;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1120; --surface: #181b2e; --surface-2: #20243a; --text: #eceefa; --muted: #9da3c0;
  --border: #2b3050; --primary: #7c74ff; --primary-hover: #918aff; --primary-soft: #262a52;
  --on-primary: #fff; --success: #34c48f; --danger: #ff6b6b; --danger-soft: #3a2026;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Heebo', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}
[hidden] { display: none !important; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { line-height: 1.25; margin: 0 0 12px; }
h2 { font-size: 1.15rem; }
.wrap { max-width: 880px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.2rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo { width: 32px; height: 32px; border-radius: 9px; background: var(--primary); display: grid; place-items: center; }
.logo svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; }
.topnav { display: flex; align-items: center; gap: 16px; min-width: 0; }
.auth-area, .user-menu { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-name { font-weight: 500; color: var(--text); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* buttons */
.btn {
  font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 10px;
  padding: 10px 18px; cursor: pointer; transition: background .15s, border-color .15s, opacity .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:not(:disabled):hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:not(:disabled):hover { border-color: var(--primary); }
.btn-sm { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
.btn-lg { padding: 13px 24px; font-size: 1.05rem; }
.btn-block { width: 100%; margin-top: 8px; }
.link-btn { background: none; border: none; color: var(--muted); text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }
.link-btn:hover { color: var(--danger); }

/* hero */
.hero { text-align: center; padding: 48px 0 28px; }
.hero h1 { font-size: clamp(1.8rem, 6vw, 2.8rem); font-weight: 800; letter-spacing: -.5px; }
.accent { color: var(--primary); }
.lead { color: var(--muted); font-size: 1.1rem; max-width: 620px; margin: 0 auto 24px; }
.hero-cta { display: flex; flex-direction: column; align-items: center; gap: 10px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-bottom: 18px; }
.card h2 { margin-top: 6px; }
.card h2:not(:first-child) { margin-top: 22px; }

.quota-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.plan-name { font-size: 1.3rem; font-weight: 700; }
.quota-num b { font-size: 1.6rem; }
.quota-foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.bar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 12px; }
.bar-fill { height: 100%; width: 0; background: var(--primary); border-radius: 99px; transition: width .3s; }

/* upload */
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  border: 2px dashed var(--border); border-radius: 14px; padding: 30px 16px; cursor: pointer;
  background: var(--surface-2); transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--primary); background: var(--primary-soft); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop svg { width: 40px; height: 40px; fill: none; stroke: var(--primary); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.drop-title { font-weight: 600; }
.file-info { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--primary-soft); overflow-wrap: anywhere; }

.models { border: 0; padding: 0; margin: 0 0 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.model { display: block; cursor: pointer; }
.model input { position: absolute; opacity: 0; }
.model-body { display: flex; flex-direction: column; gap: 2px; height: 100%; padding: 12px 14px; border: 2px solid var(--border); border-radius: 12px; transition: border-color .15s, background .15s; }
.model input:checked + .model-body { border-color: var(--primary); background: var(--primary-soft); }
.model input:focus-visible + .model-body { outline: 2px solid var(--primary); outline-offset: 2px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; font-weight: 500; min-width: 0; }
.field.grow { flex: 1 1 260px; }
input[type="text"], input[type="number"], input[type="date"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
select { min-width: 150px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; line-height: 1.7; }

.progress { margin-top: 14px; }
.progress .bar { margin: 0 0 6px; }

.notice { padding: 10px 14px; border-radius: 10px; background: var(--primary-soft); margin: 14px 0 0; }
.notice-error { background: var(--danger-soft); color: var(--danger); }

.result-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

.history { list-style: none; margin: 0; padding: 0; }
.history li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.history li:first-child { border-top: 0; }
.history .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.history .btns { display: flex; gap: 6px; flex-shrink: 0; }

/* plans */
.plans-section { padding: 36px 0 10px; }
.section-title { text-align: center; font-size: 1.6rem; font-weight: 800; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin: 22px 0 12px; }
.plan { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow); position: relative; }
.plan.featured { border: 2px solid var(--primary); }
.plan.current { outline: 3px solid var(--success); outline-offset: -1px; }
.plan-badge { position: absolute; top: -11px; inset-inline-start: 16px; background: var(--primary); color: var(--on-primary); font-size: .75rem; font-weight: 700; padding: 2px 10px; border-radius: 99px; }
.plan h3 { margin: 0; font-size: 1.1rem; }
.price { font-size: 2rem; font-weight: 800; }
.price small { font-size: .9rem; font-weight: 500; color: var(--muted); }
.plan ul { list-style: none; padding: 0; margin: 6px 0 12px; flex: 1; }
.plan li { padding: 3px 0; padding-inline-start: 22px; position: relative; font-size: .93rem; }
.plan li::before { content: '✓'; position: absolute; inset-inline-start: 0; color: var(--success); font-weight: 700; }
.plan .pp { min-height: 44px; }
.plan .state { font-weight: 600; color: var(--success); text-align: center; padding: 10px 0; }

.coupon { display: flex; gap: 8px; max-width: 380px; margin: 18px auto 0; }
.coupon input { text-transform: uppercase; }
.old-price { display: block; font-size: .95rem; font-weight: 500; color: var(--muted); line-height: 1.2; }
.offer { font-size: .85rem; font-weight: 600; color: var(--success); }
.model.locked { opacity: .55; cursor: not-allowed; }
#couponMsg { max-width: 560px; margin-inline: auto; }

.faq { padding: 30px 0 20px; }
.faq details { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; margin-bottom: 10px; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq p { margin: 8px 0 0; color: var(--muted); }

.footer { padding: 24px 0 40px; text-align: center; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
}

/* admin */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kv div { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.kv b { display: block; font-size: 1.4rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: start; padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.ok { color: var(--success); font-weight: 600; }
.bad { color: var(--danger); font-weight: 600; }

@media (max-width: 560px) {
  .topnav > a { display: none; }
  .user-name { max-width: 90px; }
  .card { padding: 16px; }
  .models { grid-template-columns: 1fr; }
  .actions .btn { flex: 1 1 100%; }
  .hero { padding-top: 32px; }
}
