/*
 * Spokly studio (/app) layout and views. Uses the tokens and components from spokly.css.
 */

/* ============================================================ Shell */
.studio { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--bg-subtle); border-right: 1px solid var(--border);
}
.sidebar-head { height: 56px; flex: none; display: flex; align-items: center; padding: 0 20px; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 4px 12px 16px; display: flex; flex-direction: column; }
.nav-group + .nav-group { margin-top: 14px; }
.nav-group-label { display: block; padding: 0 10px 4px; font-size: 12px; font-weight: 500; color: var(--text-2); }
.nav-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.nav-group-foot { margin-top: 18px; }

.side-item {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px;
  border: 1px solid transparent; border-radius: 10px; background: transparent;
  font: 500 14px/1 var(--font); color: var(--text-2); text-align: left; text-decoration: none;
  transition: background-color .15s, color .15s;
}
.side-item:hover { background: var(--hover); color: var(--text); }
.side-item[aria-current="page"] { background: var(--surface); border-color: var(--border); box-shadow: var(--shadow-sm); color: var(--text); }
.side-item > span:not(.badge) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item > .badge { flex: none; }
.side-item .badge { height: 18px; padding: 0 7px; font-size: 11px; }
.side-star { color: var(--text-2); font-size: 12px; }

.studio-main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 50; height: 56px; flex: none;
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  background: var(--nav-bg); backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 6px; flex: none; }
.tools-btn { display: none; max-width: 52vw; }
.tools-btn span { overflow: hidden; text-overflow: ellipsis; }
.credits-wrap { display: inline-flex; align-items: center; gap: 2px; }
.credits-pill {
  display: inline-flex; align-items: center; height: 30px; padding: 0 12px; border-radius: var(--r-pill);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 13px; font-weight: 500; text-decoration: none; white-space: nowrap;
}
.credits-pill:hover { border-color: var(--border-strong); }
.icon-btn-sm { width: 30px; height: 30px; }
.icon-btn-sm .icon { width: 16px; height: 16px; }
.gsi-slot:empty { display: none; }
.account { position: relative; }
.avatar-btn { display: block; padding: 0; border: 0; border-radius: 50%; background: none; }
.avatar { display: block; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border); background: var(--field); }
.avatar-initial { display: grid; place-items: center; background: var(--grad-source); color: var(--tile-ink); font-size: 14px; font-weight: 600; }
.popover {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 60; min-width: 220px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg);
  animation: pop-in .16s var(--ease);
}
.popover-head { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.popover-head strong { font-size: 14px; font-weight: 600; }
.popover-head span { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; }
.popover-item { display: block; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px; background: none; color: var(--text); font: 400 14px/1.3 var(--font); text-align: left; text-decoration: none; }
.popover-item:hover { background: var(--hover); }

.workspace { width: 100%; max-width: 1120px; margin: 0 auto; padding: 32px; }
.view { display: flex; flex-direction: column; gap: 20px; }
.view-head { display: flex; align-items: center; gap: 16px; }
.view-head > div { flex: 1; min-width: 0; }
.view-head p { margin-top: 2px; font-size: 14px; }
.view-head h2:focus { outline: none; }

@media (max-width: 900px) {
  .studio { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .tools-btn { display: inline-flex; }
  .topbar { padding: 0 12px 0 16px; gap: 8px; }
  .topbar-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .topbar-right { margin-left: auto; }
  .plan-badge { display: none; }
  .workspace { padding: 20px 16px 40px; }
}
@media (max-width: 420px) {
  .credits-pill { padding: 0 10px; }
  #creditsInfo { display: none; }
}

/* ============================================================ Shared bits */
.note { font-size: 14px; color: var(--text-2); background: var(--bg-subtle); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.small-link { font-size: 13px; }
a.chip { text-decoration: none; }
.section-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Ads */
.ad-side { min-height: 120px; }

/* ============================================================ Home */
.home-hero { position: relative; isolation: isolate; padding: 12px 0 0; }
.home-hero .orb { --orb-size: 380px; top: -240px; left: -120px; z-index: -1; }
.home-greet { font-size: 28px; font-weight: 600; letter-spacing: -0.025em; }
.home-greet:focus { outline: none; }
.start-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.start-card {
  display: flex; align-items: center; gap: 14px; padding: 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
  font: inherit; color: var(--text); text-align: left; text-decoration: none;
  transition: transform .2s var(--ease), border-color .2s, box-shadow .2s;
}
.start-card:hover, .start-card[aria-expanded="true"] { transform: translateY(-2px); border-color: var(--border-strong); box-shadow: var(--shadow); }
.start-text strong { display: block; font-size: 15px; font-weight: 600; }
.start-text small { display: block; margin-top: 2px; font-size: 13px; color: var(--text-2); }
@media (max-width: 780px) { .start-grid { grid-template-columns: 1fr; } }
.paste-panel { display: flex; flex-direction: column; gap: 14px; }
.home-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.home-section { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.tool-groups { display: flex; flex-direction: column; gap: 22px; }
.tool-group h4 { margin-bottom: 10px; font-size: 13px; font-weight: 500; color: var(--text-2); letter-spacing: 0; }
.tool-group .grid-cards { grid-template-columns: repeat(auto-fill, minmax(min(230px, 100%), 1fr)); gap: 10px; }
.tool-group .tool-card { flex-direction: row; align-items: center; gap: 12px; padding: 14px; }
.tool-group .tool-card strong { display: block; font-size: 14px; font-weight: 600; }
.tool-group .tool-card p { font-size: 13px; }

/* Recent & history */
.recent-list, .history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.hist-item { display: flex; align-items: flex-start; gap: 14px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.hist-main { flex: 1; min-width: 0; }
.hist-title { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; }
.hist-meta { font-size: 12px; color: var(--text-2); }
.hist-preview { margin-top: 4px; font-size: 13px; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.hist-actions { display: flex; flex-wrap: wrap; gap: 2px; }
@media (max-width: 640px) { .hist-item { flex-wrap: wrap; } .hist-actions { width: 100%; padding-left: 46px; } }

/* ============================================================ Source card */
.source-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-sm); }
.source-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 10px 10px 14px; }
.source-toggle { display: inline-flex; align-items: center; gap: 8px; padding: 4px 6px 4px 2px; border: 0; border-radius: 8px; background: none; color: var(--text); font: 600 14px/1 var(--font); }
.source-toggle .icon { transition: transform .2s var(--ease); }
.source-toggle[aria-expanded="false"] .icon { transform: rotate(-90deg); }
.source-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.source-actions { display: flex; flex-wrap: wrap; gap: 2px; }
.source-body { padding: 0 16px 16px; }
.source-preview { margin: 0; font-size: 14px; line-height: 1.6; color: var(--text-2); white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.source-body .textarea { min-height: 240px; }
.source-empty { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 16px; }
.source-empty p { flex: 1 1 220px; color: var(--text-2); font-size: 14px; }

/* ============================================================ Speech to text */
.seg-rich { border-radius: 18px; }
.seg-rich > [role="radio"] { height: auto; padding: 10px 16px; border-radius: 14px; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left; }
.seg-rich > [role="radio"] small { font-size: 12px; font-weight: 400; color: var(--text-2); }
.seg-rich .segmented-thumb { border-radius: 14px; }
.after-tx { display: flex; flex-direction: column; gap: 16px; }
.next-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }

/* ============================================================ Dictation */
.dictate-card { position: relative; overflow: hidden; isolation: isolate; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 44px 20px 28px; text-align: center; }
.dictate-card .orb { --orb-size: 340px; top: -90px; left: 50%; translate: -50% 0; z-index: -1; }
.dictate-lang { width: min(300px, 100%); text-align: left; }

/* ============================================================ Writing tool */
.tool-grid { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; align-items: start; }
.tool-controls { position: sticky; top: 72px; display: flex; flex-direction: column; gap: 18px; }
.tool-opts { display: flex; flex-direction: column; gap: 14px; }
.tool-opts .segmented { display: flex; }
.tool-opts .segmented > [role="radio"] { padding: 0 10px; font-size: 13px; }
.tool-opts .textarea { min-height: 96px; }
.gen { display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 1100px) {
  .tool-grid { grid-template-columns: minmax(0, 1fr); }
  .tool-controls { position: static; }
}
.out-card { display: flex; flex-direction: column; min-width: 0; min-height: 360px; }
.out-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-height: 52px; padding: 8px 10px 8px 18px; border-bottom: 1px solid var(--border); }
.out-actions { display: flex; flex-wrap: wrap; gap: 2px; margin-left: auto; }
#output, #packOut { flex: 1; padding: 18px 20px 24px; }
.retry-box {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 12px 18px;
  border-bottom: 1px solid color-mix(in srgb, var(--danger) 25%, var(--border));
  background: color-mix(in srgb, var(--danger) 6%, var(--surface));
}
.retry-box p { flex: 1 1 260px; font-size: 14px; color: var(--text); }
.out-empty { margin: auto; padding: 48px 16px; text-align: center; color: var(--text-2); }

.md { font-size: 15px; line-height: 1.75; overflow-wrap: anywhere; min-width: 0; }
.md > :first-child { margin-top: 0; }
.md h1 { margin: 0 0 12px; font-size: 22px; font-weight: 600; line-height: 1.3; }
.md h2 { margin: 22px 0 8px; font-size: 18px; font-weight: 600; }
.md h3 { margin: 18px 0 6px; font-size: 16px; font-weight: 600; }
.md p { margin: 0 0 12px; }
.md ul, .md ol { margin: 0 0 12px; padding-inline-start: 22px; }
.md li { margin: 3px 0; }
.md blockquote { margin: 0 0 12px; padding-inline-start: 12px; border-inline-start: 3px solid var(--border-strong); color: var(--text-2); }
.md code { font-family: var(--mono); font-size: .88em; background: var(--field); padding: 2px 5px; border-radius: 4px; }
.md pre { overflow-x: auto; margin: 0 0 12px; padding: 14px; background: var(--field); border-radius: 10px; }
.md pre code { background: none; padding: 0; }
.md.text { white-space: pre-wrap; }
.md.pre { white-space: pre-wrap; font: 13px/1.6 var(--mono); }

/* ============================================================ Voice-over */
.vo-preview { max-height: 140px; overflow: auto; padding: 12px 14px; border-radius: 12px; background: var(--bg-subtle); font-size: 14px; color: var(--text-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.vo-preview:empty { display: none; }
.voice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(190px, 100%), 1fr)); gap: 8px; }
.voice-card { position: relative; display: flex; align-items: center; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.voice-card:hover { border-color: var(--border-strong); }
.voice-card:has([aria-checked="true"]) { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.voice-pick { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 12px; border: 0; border-radius: 14px; background: none; color: var(--text); font: inherit; text-align: left; }
.voice-pick strong { display: block; font-size: 14px; font-weight: 500; }
.voice-pick small { display: block; font-size: 12px; color: var(--text-2); }
.voice-avatar { flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--grad-source); }
.voice-card .icon-btn { margin-right: 6px; }
.player { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.play-btn { flex: none; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--primary); color: var(--primary-ink); }
.play-btn .icon { width: 18px; height: 18px; }
.play-btn .i-pause, .play-btn.is-playing .i-play { display: none; }
.play-btn.is-playing .i-pause { display: block; }
.wave { flex: 1 1 220px; min-width: 0; height: 48px; display: flex; align-items: center; gap: 2px; cursor: pointer; border-radius: 6px; }
.wave i { flex: 1; min-width: 2px; height: var(--h, 20%); border-radius: 2px; background: var(--border-strong); transition: background-color .1s; }
.wave i.on { background: var(--text); }

/* ============================================================ Content pack */
.pack-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; }
.pack-controls .field { flex: 1 1 220px; }
.checklist { list-style: none; margin: 18px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(230px, 100%), 1fr)); gap: 8px; }
.check-item { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 8px 10px 8px 12px; border: 1px solid var(--border); border-radius: 12px; font-size: 14px; }
.check-item > span:nth-child(2) { flex: 1; min-width: 0; }
.check-ico { flex: none; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--border-strong); color: var(--text-2); font-size: 11px; }
.check-ico .icon { width: 12px; height: 12px; }
.check-item.is-done .check-ico { background: var(--success); border-color: var(--success); color: #FFFFFF; }
.check-item.is-failed .check-ico { background: var(--danger); border-color: var(--danger); color: #FFFFFF; }
.check-item.is-run .check-ico { border: 0; }
.check-state { font-size: 12px; color: var(--text-2); }

/* ============================================================ Plans & credits */
.plan-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 16px 40px; }
.plan-name { display: block; margin-top: 2px; font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.plan-summary-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.plan-info { flex-basis: 100%; margin: 0; }
.billing-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.plan-note { font-size: 13px; color: var(--success-ink); }
.modal .segmented { align-self: flex-start; }

/* ============================================================ Overlays */
.modal { display: flex; flex-direction: column; gap: 14px; }
.modal-wide { width: min(880px, 100%); }
.overlay-drawer { display: block; padding: 0; }
.drawer-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.sheet-backdrop { position: fixed; inset: 0; z-index: 900; display: flex; align-items: flex-end; background: var(--overlay); animation: fade-in .18s var(--ease); }
.sheet { width: 100%; max-height: 86dvh; display: flex; flex-direction: column; background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: var(--shadow-lg); animation: sheet-up .26s var(--ease); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 20px; border-bottom: 1px solid var(--border); }
.sheet-body { overflow-y: auto; padding: 8px 12px max(20px, env(safe-area-inset-bottom)); }
@keyframes sheet-up { from { transform: translateY(100%); } }

/* ============================================================ PAID_FEATURES off */
/* AI tools stay listed but greyed with a "Soon" pill; they open the "Coming soon" view. */
.side-item.is-soon { color: var(--text-3); }
.side-item.is-soon .icon { opacity: .55; }
.side-item.is-soon[aria-current="page"] { color: var(--text-2); }
.tool-card.is-soon { background: var(--bg-subtle); }
.tool-card.is-soon .tile { opacity: .55; }
.tool-card.is-soon strong { color: var(--text-2); }
.tool-card .badge-soon { margin-left: 6px; }
.soon-card { align-self: start; }
.soon-card > .badge { align-self: flex-start; }
.soon-card .notify { max-width: none; }
.soon-free a { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
