/* ===== Themes ===== */
:root {
  --radius: 14px;
  --accent: #6c5ce7; --accent-2: #8b7cf6; --on-accent: #fff;
  --danger: #ef4444; --ok: #10b981;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Gujarati", "Noto Sans", sans-serif;
  --top-h: 60px;
}
[data-theme="light"]    { --bg:#f4f5fa; --surface:#ffffff; --surface2:#eceef6; --text:#1a1d2b; --muted:#6a7090; --border:#e0e3ee; --shadow:0 8px 30px rgba(24,28,60,.09); color-scheme: light; }
[data-theme="dark"]     { --bg:#0e1016; --surface:#161922; --surface2:#1e222e; --text:#e9ebf3; --muted:#8b91a9; --border:#2a2f3f; --shadow:0 10px 40px rgba(0,0,0,.45); color-scheme: dark; }
[data-theme="midnight"] { --bg:#000000; --surface:#0b0c10; --surface2:#15161d; --text:#eceef6; --muted:#7f869e; --border:#1f212b; --shadow:0 10px 40px rgba(0,0,0,.7); color-scheme: dark; }
[data-theme="ocean"]    { --bg:#0a1620; --surface:#10212e; --surface2:#17303f; --text:#e3f0f8; --muted:#82a3b8; --border:#1f3b4d; --shadow:0 10px 40px rgba(0,10,20,.55); color-scheme: dark; }
[data-theme="forest"]   { --bg:#0c1511; --surface:#121f19; --surface2:#1a2c23; --text:#e4f2ea; --muted:#84a592; --border:#24392f; --shadow:0 10px 40px rgba(0,10,5,.55); color-scheme: dark; }
[data-theme="rose"]     { --bg:#fff3f6; --surface:#ffffff; --surface2:#ffe6ec; --text:#3a1a24; --muted:#9a6b79; --border:#f6d3dc; --shadow:0 8px 30px rgba(190,60,100,.12); color-scheme: light; }
[data-theme="sand"]     { --bg:#f6f1e7; --surface:#fffdf8; --surface2:#efe7d6; --text:#2c261b; --muted:#8a7e66; --border:#e4dac3; --shadow:0 8px 30px rgba(90,70,20,.1); color-scheme: light; }

[data-accent="violet"] { --accent:#6c5ce7; --accent-2:#8b7cf6; --on-accent:#fff; }
[data-accent="blue"]   { --accent:#2f7df6; --accent-2:#5b9bff; --on-accent:#fff; }
[data-accent="green"]  { --accent:#0fae7e; --accent-2:#34d3a0; --on-accent:#fff; }
[data-accent="rose"]   { --accent:#e8457a; --accent-2:#ff7aa3; --on-accent:#fff; }
[data-accent="amber"]  { --accent:#f59e0b; --accent-2:#fbbf24; --on-accent:#1b1300; }
[data-accent="teal"]   { --accent:#0ea5b7; --accent-2:#3cc9da; --on-accent:#fff; }

/* ===== Base ===== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.45; transition: background .25s, color .25s; overflow-x: hidden; }
.hidden { display: none !important; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h2 { font-size: 22px; } h3 { font-size: 15px; margin-bottom: 4px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

/* ===== Buttons / fields ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; transition: transform .08s, background .15s, border-color .15s, opacity .15s; }
.btn:hover { background: var(--surface2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: var(--on-accent); box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; pointer-events: none; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; border: 1px solid transparent; background: transparent; }
.icon-btn:hover { background: var(--surface2); }
.link { background: none; border: none; color: var(--muted); font-size: 13px; text-decoration: underline; margin-top: 10px; }
.mini { background: var(--surface2); border: 1px solid var(--border); border-radius: 9px; padding: 3px 10px; font-size: 12px; font-weight: 600; }
.field { display: block; margin-bottom: 14px; text-align: left; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--muted); }
.field input, .field textarea, .field select, .input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface2); outline: none; transition: border-color .15s, box-shadow .15s; }
.field input:focus, .field textarea:focus, .field select:focus, .input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.err { color: var(--danger); min-height: 20px; margin: 10px 0 0; font-size: 13px; }

/* ===== Login ===== */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: radial-gradient(900px 500px at 15% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent), radial-gradient(700px 500px at 100% 110%, color-mix(in srgb, var(--accent-2) 18%, transparent), transparent), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; padding: 30px 26px; box-shadow: var(--shadow); text-align: center; }
.login-card h1 { margin: 12px 0 4px; font-size: 26px; }
.login-card .muted { margin: 0 0 22px; }
.logo-badge { width: 60px; height: 60px; border-radius: 18px; display: grid; place-items: center; margin: 0 auto; color: var(--on-accent); background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 10px 26px color-mix(in srgb, var(--accent) 40%, transparent); }

/* ===== App shell ===== */
.topbar { position: sticky; top: 0; z-index: 30; height: var(--top-h); display: flex; align-items: center; gap: 10px; padding: 0 16px; padding-top: env(safe-area-inset-top); background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(14px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 9px; font-size: 16px; margin-right: 6px; white-space: nowrap; }
.brand-dot { width: 14px; height: 14px; border-radius: 5px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.search { flex: 1; max-width: 520px; display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--surface2); border: 1px solid var(--border); border-radius: 12px; color: var(--muted); }
.search input { flex: 1; min-width: 0; border: none; background: none; outline: none; padding: 10px 0; color: var(--text); }
.search:focus-within { border-color: var(--accent); }
.topbar .btn.primary { margin-left: auto; }
.layout { display: grid; grid-template-columns: 270px 1fr; min-height: calc(100vh - var(--top-h)); }
.sidebar { position: sticky; top: var(--top-h); align-self: start; height: calc(100vh - var(--top-h)); overflow-y: auto; padding: 16px 12px; border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; gap: 8px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 10px 12px; border: none; background: transparent; border-radius: 11px; text-align: left; font-weight: 600; transition: background .15s; }
.nav-item:hover { background: var(--surface2); }
.nav-item.active { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.nav-item em { font-style: normal; font-size: 12px; color: var(--muted); background: var(--surface2); padding: 2px 8px; border-radius: 99px; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 4px; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.plist { display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 40px; }
.plist .nav-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot { border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.side-foot .small { padding: 0 12px; }
.main { padding: 22px; min-width: 0; padding-bottom: 110px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.scrim { display: none; }

/* ===== Grid ===== */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.tile { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--surface); border: 1px solid var(--border); cursor: pointer; transition: transform .15s, box-shadow .15s, border-color .15s; animation: pop .3s both; }
.tile:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.tile .ph { aspect-ratio: 1/1; background: var(--surface2); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; aspect-ratio: 1/1; opacity: 0; transition: opacity .3s; }
.tile img.ok { opacity: 1; }
.tile .cap { padding: 9px 11px 10px; }
.tile .cap b { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .cap span { font-size: 12px; color: var(--muted); }
.tile .badge { position: absolute; top: 8px; left: 8px; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: rgba(0,0,0,.6); color: #fff; backdrop-filter: blur(6px); }
.tile .dl { position: absolute; top: 8px; right: 8px; width: 34px; height: 34px; border-radius: 10px; border: none; background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; opacity: 0; transition: opacity .15s; backdrop-filter: blur(6px); }
.tile:hover .dl { opacity: 1; }
@media (hover: none) { .tile .dl { opacity: 1; } }
.tile .chk { position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border-radius: 9px; border: 2px solid #fff; background: rgba(0,0,0,.35); display: none; place-items: center; color: transparent; font-weight: 800; }
.select-mode .tile .chk { display: grid; }
.select-mode .tile .dl { display: none; }
.tile.sel { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent); }
.tile.sel .chk { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.skeleton { background: linear-gradient(90deg, var(--surface2), var(--surface), var(--surface2)); background-size: 200% 100%; animation: sh 1.2s infinite; border-radius: var(--radius); aspect-ratio: 1/1.2; }
@keyframes sh { to { background-position: -200% 0; } }
.more { text-align: center; margin-top: 20px; }
.empty { text-align: center; padding: 60px 20px; }
.empty-ico { font-size: 48px; margin-bottom: 8px; }
.empty .btn { margin-top: 14px; }

.bulk { position: sticky; top: calc(var(--top-h) + 8px); z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 14px; margin-bottom: 14px; background: var(--surface); border: 1px solid var(--accent); border-radius: 14px; box-shadow: var(--shadow); }
.bulk-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ===== Cards (connect page) ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.copyrow { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.copyrow code { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; background: var(--surface2); border: 1px solid var(--border); overflow-x: auto; white-space: nowrap; font-size: 13px; }
.pre { white-space: pre-wrap; background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; font-size: 12.5px; margin: 10px 0; max-height: 280px; overflow: auto; }
.steps { padding-left: 18px; margin: 8px 0 0; } .steps li { margin-bottom: 6px; }

/* ===== FAB / progress / toasts ===== */
.fab { position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 20px; border: none; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent); display: grid; place-items: center; box-shadow: 0 12px 30px color-mix(in srgb, var(--accent) 45%, transparent); z-index: 25; }
.progress { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom)); width: min(420px, calc(100vw - 28px)); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow); z-index: 90; }
.progress-top { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 14px; }
.bar { height: 8px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .15s; }
.toasts { position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; width: calc(100vw - 24px); pointer-events: none; }
.toast { pointer-events: auto; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow); animation: pop .25s both; max-width: 460px; }
.toast.err { background: var(--danger); color: #fff; }
.drop { position: fixed; inset: 0; z-index: 150; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 22%, rgba(0,0,0,.55)); backdrop-filter: blur(4px); }
.drop div { padding: 30px 50px; border: 3px dashed #fff; border-radius: 24px; color: #fff; font-size: 22px; font-weight: 700; }

/* ===== Lightbox ===== */
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(5,6,10,.94); display: flex; flex-direction: column; animation: fade .2s both; }
@keyframes fade { from { opacity: 0; } }
.lb-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 56px 56px 8px; }
.lb-stage img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.6); touch-action: pan-y; }
.lb-close { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 12px; color: #fff; font-size: 20px; z-index: 3; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; border: none; background: rgba(255,255,255,.1); color: #fff; font-size: 34px; border-radius: 14px; z-index: 3; }
.lb-nav.prev { left: 8px; } .lb-nav.next { right: 8px; }
.lb-nav:hover { background: rgba(255,255,255,.2); }
.lb-panel { background: var(--surface); border-top: 1px solid var(--border); padding: 14px 18px calc(14px + env(safe-area-inset-bottom)); display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.lb-meta { flex: 1; min-width: 220px; }
.lb-name { width: 100%; max-width: 420px; background: transparent; border: 1px solid transparent; border-radius: 8px; font-weight: 700; font-size: 16px; padding: 4px 8px; margin-left: -8px; outline: none; }
.lb-name:hover, .lb-name:focus { border-color: var(--border); background: var(--surface2); }
.lb-prompt { max-height: 40px; overflow: hidden; text-overflow: ellipsis; }
.lb-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== Modal / popover ===== */
.modal { position: fixed; inset: 0; z-index: 120; background: rgba(0,0,0,.55); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 16px; animation: fade .15s both; }
.modal-card { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 22px; box-shadow: var(--shadow); max-height: 92vh; overflow: auto; }
.modal-card h3 { font-size: 18px; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.pick { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow: auto; margin-bottom: 12px; }
.pick button { text-align: left; padding: 11px 13px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface2); font-weight: 600; }
.pick button:hover { border-color: var(--accent); }
.pop { position: fixed; top: calc(var(--top-h) + 8px); right: 12px; z-index: 110; width: 290px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; animation: pop .2s both; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw { width: 54px; height: 40px; border-radius: 11px; border: 2px solid var(--border); font-size: 10px; font-weight: 700; display: grid; place-items: center; cursor: pointer; }
.sw.on { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent); }
.sw.round { width: 34px; height: 34px; border-radius: 50%; }

.only-mobile { display: none; }

/* ===== Mobile ===== */
@media (max-width: 860px) {
  .only-mobile { display: grid; }
  .hide-mobile { display: none !important; }
  .layout { display: block; }
  .main { padding: 14px; padding-bottom: 120px; }
  .brand b { display: none; }
  .search { max-width: none; }
  .sidebar { position: fixed; z-index: 60; top: 0; left: 0; bottom: 0; height: 100%; width: 285px; padding-top: calc(18px + env(safe-area-inset-top)); transform: translateX(-102%); transition: transform .25s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.5); display: block; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .lb-stage { padding: 52px 8px 6px; }
  .lb-nav { width: 36px; height: 52px; font-size: 28px; }
  .lb-actions .btn { flex: 1; padding: 10px 8px; font-size: 14px; }
  .lb-actions { width: 100%; }
  .topbar { padding-left: 10px; padding-right: 10px; gap: 6px; }
  .topbar .btn.primary { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
