/* ============================================================
   Letters — App shell (dashboard, builder, account)
   Sidebar + topbar + app primitives. Loads after letters-v2.css.
   ============================================================ */

body.app { background: var(--bg-2); height: 100vh; overflow: hidden; }
.app-shell { display: grid; grid-template-columns: 244px 1fr; height: 100vh; }

/* ---------- SIDEBAR ---------- */
.side { border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.side-top { padding: 16px 16px 10px; }
.side .brand { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 17px; letter-spacing: -0.03em; }
.workspace { margin-top: 14px; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 1px solid var(--line); border-radius: var(--r-md); cursor: pointer; transition: background .15s, border-color .15s; }
.workspace:hover { background: var(--bg-2); border-color: var(--line-2); }
.workspace .ws-logo { width: 28px; height: 28px; border-radius: 7px; background: linear-gradient(150deg,#3A2A20,#160F0B); color: #E7C9A8; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.workspace > div { text-align: left; }
.workspace .ws-name { font-size: 13.5px; font-weight: 600; line-height: 1.25; }
.workspace .ws-plan { font-family: var(--mono); font-size: 10px; color: var(--muted); line-height: 1.2; }
.workspace .ws-chev { margin-left: auto; color: var(--muted-2); }

.side-nav { flex: 1; overflow-y: auto; padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; }
.side-nav .grp { font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted-2); padding: 14px 9px 6px; }
.side-nav a { display: flex; align-items: center; gap: 11px; padding: 8px 9px; border-radius: var(--r-sm); font-size: 13.5px; font-weight: 500; white-space: nowrap; color: var(--ink-2); transition: background .15s, color .15s; position: relative; }
.side-nav a svg { color: var(--muted); flex-shrink: 0; transition: color .15s; }
.side-nav a:hover { background: var(--bg-2); color: var(--ink); }
.side-nav a:hover svg { color: var(--ink-2); }
.side-nav a.active { background: var(--ink); color: #fff; }
.side-nav a.active svg { color: #fff; }
.side-nav a .count { margin-left: auto; font-family: var(--mono); font-size: 10.5px; color: var(--muted); background: var(--bg-3); padding: 1px 6px; border-radius: 5px; }
.side-nav a.active .count { background: rgba(255,255,255,0.16); color: #fff; }
.side-nav a .new { margin-left: auto; font-family: var(--mono); font-size: 9px; letter-spacing: .04em; color: var(--spark); background: var(--spark-soft); border: 1px solid var(--spark-line); padding: 1px 6px; border-radius: 5px; }

.side-foot { border-top: 1px solid var(--line); padding: 12px; }
.usage { padding: 4px 9px 10px; }
.usage .ur { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-bottom: 7px; }
.usage .ub { height: 5px; background: var(--bg-3); border-radius: 3px; overflow: hidden; }
.usage .ub i { display: block; height: 100%; border-radius: 3px; background: var(--ink); }
.userbar { display: flex; align-items: center; gap: 10px; padding: 8px 9px; border-radius: var(--r-sm); cursor: pointer; transition: background .15s; }
.userbar:hover { background: var(--bg-2); }
.userbar .av { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(150deg,#E7B85A,#C98A22); flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-size: 12px; }
.userbar .un { font-size: 13px; font-weight: 600; line-height: 1.1; }
.userbar .ue { font-size: 11.5px; color: var(--muted); }
.userbar .uchev { margin-left: auto; color: var(--muted-2); }

/* ---------- MAIN ---------- */
.app-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow-x: hidden; }
.topbar { position: relative; z-index: 40; height: 58px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,0.82); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); display: flex; align-items: center; gap: 14px; padding: 0 26px; flex-shrink: 0; }
.topbar .crumb { font-size: 14.5px; font-weight: 600; letter-spacing: -0.01em; display: flex; align-items: center; gap: 9px; }
.topbar .crumb .sub { color: var(--muted-2); font-weight: 500; }
.topbar .search { margin-left: 20px; display: flex; align-items: center; gap: 9px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: 7px 12px; width: 260px; color: var(--muted); font-size: 13px; }
.topbar .search { cursor: pointer; margin-left: 20px; display: flex; align-items: center; gap: 9px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: 7px 12px; width: 260px; transition: background .15s, border-color .15s; font-family: var(--font); color: var(--muted); font-size: 13px; }
.topbar .search:hover { background: var(--surface); border-color: var(--line-strong); color: var(--ink-2); }
.topbar .search .kbd { margin-left: auto; }
.topbar .tb-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.iconbtn { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); display: flex; align-items: center; justify-content: center; color: var(--ink-2); cursor: pointer; transition: background .15s, border-color .15s; position: relative; }
.iconbtn:hover { background: var(--bg-2); border-color: var(--line-2); }
.iconbtn .dot { position: absolute; top: 7px; right: 8px; width: 6px; height: 6px; border-radius: 50%; background: var(--spark); border: 1.5px solid var(--surface); }

.app-scroll { flex: 1; overflow-y: auto; padding: 30px 32px 60px; }
.app-wrap { max-width: 1080px; margin: 0 auto; }

/* ---------- app primitives ---------- */
.acard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--sh-xs); }
.sec-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sec-title h3 { font-size: 16px; letter-spacing: -0.02em; white-space: nowrap; }
.sec-title a { font-size: 13px; color: var(--muted); font-weight: 540; }
.sec-title a:hover { color: var(--ink); }

.pillbtn { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 540; color: var(--ink-2); border: 1px solid var(--line-2); background: var(--surface); padding: 6px 12px; border-radius: 999px; cursor: pointer; transition: all .15s; }
.pillbtn:hover { background: var(--bg-2); border-color: var(--line-strong); }
.pillbtn.on { background: var(--ink); color: #fff; border-color: var(--ink); }

.statusdot { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; }
.statusdot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); }
.statusdot.live { color: var(--pos); }
.statusdot.live::before { background: var(--pos); animation: livePulseA 1.8s ease-in-out infinite; }
.statusdot.draft { color: var(--amber); }
.statusdot.draft::before { background: var(--amber); }
@keyframes livePulseA { 0%,100% { box-shadow: 0 0 0 0 rgba(26,143,92,.5);} 60% { box-shadow: 0 0 0 5px rgba(26,143,92,0);} }

/* mobile/tablet drawer nav (injected hamburger in app.js) */
.app-burger { display: none; background: none; border: none; cursor: pointer; color: var(--ink); padding: 6px; margin-right: 2px; border-radius: 8px; align-items: center; justify-content: center; flex-shrink: 0; }
.app-burger:hover { background: var(--bg-2); }
.side-backdrop { display: none; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .topbar .search { display: none; }
  .app-burger { display: inline-flex; }
  /* sidebar becomes an off-canvas drawer */
  .side { position: fixed; top: 0; left: 0; bottom: 0; width: 270px; max-width: 84vw; z-index: 120; transform: translateX(-100%); transition: transform .26s var(--ease); box-shadow: 0 24px 60px rgba(17,19,23,0.22); will-change: transform; }
  body.nav-open .side { transform: translateX(0); }
  body.nav-open .side-backdrop { display: block; position: fixed; inset: 0; background: rgba(17,19,23,0.42); z-index: 110; -webkit-backdrop-filter: blur(1px); backdrop-filter: blur(1px); }
}


/* ---------- workspace dropdown ---------- */
.ws-wrap { position: relative; margin-top: 14px; }
.workspace { width: 100%; font-family: var(--font); }
.ws-pop { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--sh-pop); padding: 6px; display: none; z-index: 70; }
.ws-pop.open { display: block; }
.ws-pop-lab { font-family: var(--mono); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted-2); padding: 8px 9px 6px; }
.ws-opt { display: flex; align-items: center; gap: 10px; padding: 8px 9px; border-radius: var(--r-sm); font-size: 13.5px; font-weight: 540; color: var(--ink-2); cursor: pointer; }
.ws-opt:hover { background: var(--bg-2); }
.ws-opt .ws-on { flex: 1; }
.ws-opt .ws-logo { width: 26px; height: 26px; border-radius: 7px; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-size: 12px; flex-shrink: 0; background: linear-gradient(150deg,#3A2A20,#160F0B); }
.ws-opt.active svg { color: var(--pos); }
.ws-add { width: 100%; display: flex; align-items: center; gap: 9px; padding: 9px; margin-top: 4px; border-top: 1px solid var(--line); border-left: 0; border-right: 0; border-bottom: 0; background: none; font-family: var(--font); font-size: 13px; font-weight: 540; color: var(--ink); cursor: pointer; }
.ws-add:hover { color: var(--accent); }

/* ---------- sub-page helpers ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; font-weight: 600; letter-spacing: -0.03em; }
.page-head p { font-size: 14px; color: var(--muted); margin-top: 5px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 18px 20px; }
.kpi .k { font-size: 12.5px; color: var(--muted); }
.kpi .v { font-size: 28px; font-weight: 600; letter-spacing: -0.04em; margin-top: 7px; font-variant-numeric: tabular-nums; }
.kpi .d { font-size: 12px; font-weight: 600; margin-top: 6px; }
.kpi .d.up { color: var(--pos); } .kpi .d.down { color: #C0413A; }
.dtable { width: 100%; border-collapse: collapse; }
.dtable th { font-family: var(--mono); font-size: 10px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted-2); text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 500; }
.dtable td { padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 13.5px; color: var(--ink-2); }
.dtable tr:last-child td { border-bottom: none; }
.dtable tbody tr { transition: background .12s; }
.dtable tbody tr:hover { background: var(--bg-2); }
.dtable .num { font-variant-numeric: tabular-nums; text-align: right; }
.tname { font-weight: 600; color: var(--ink); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-size: 11px; flex-shrink: 0; }
.barmini { display: inline-flex; align-items: flex-end; gap: 3px; height: 28px; }
.barmini i { width: 6px; background: var(--ink); border-radius: 2px 2px 0 0; }
.cardgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.icard { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.icard .ico-lg { width: 44px; height: 44px; border-radius: 11px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 17px; color: #fff; }
.icard h3 { font-size: 15px; letter-spacing: -0.01em; }
.icard p { font-size: 13px; color: var(--muted); line-height: 1.5; flex: 1; }
.bigchart { height: 240px; display: flex; align-items: flex-end; gap: 8px; padding-top: 12px; }
.bigchart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; height: 100%; }
.bigchart .b { width: 100%; border-radius: 3px 3px 0 0; }
.bigchart .b.a { background: var(--ink); } .bigchart .b.b2 { background: var(--spark); }
.chartx { display: flex; gap: 8px; margin-top: 10px; }
.chartx span { flex: 1; text-align: center; font-family: var(--mono); font-size: 9.5px; color: var(--muted-2); }
.tmpl-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.tmpl { border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; box-shadow: var(--sh-xs); cursor: pointer; transition: transform .25s var(--ease), box-shadow .25s var(--ease); background: var(--surface); }
.tmpl:hover { transform: translateY(-4px); box-shadow: var(--sh-md); }
.tmpl .tprev { height: 150px; padding: 18px; display: flex; flex-direction: column; justify-content: flex-end; }
.tmpl .tk { font-family: var(--mono); font-size: 8.5px; letter-spacing: .12em; }
.tmpl .th { font-size: 18px; font-weight: 600; line-height: 1.1; margin-top: 5px; }
.tmpl .th.serif { font-family: 'Hoefler Text', Georgia, serif; font-weight: 500; }
.tmpl .tfoot { padding: 12px 15px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); }
.tmpl .tfoot .tn { font-size: 13px; font-weight: 600; }
.tmpl .tfoot .tt { font-size: 11px; color: var(--muted); }
@media (max-width: 900px) { .kpis { grid-template-columns: 1fr 1fr; } .cardgrid, .tmpl-grid { grid-template-columns: 1fr; } .dtable { font-size: 12px; } }
@media (max-width: 700px) {
  .app-scroll { padding: 20px 16px 50px; }
  .topbar { padding: 0 14px; gap: 8px; }
  .topbar .statusdot { display: none; }
  .topbar .crumb { font-size: 14px; }
  .topbar .crumb .sub { display: none; }
  /* secondary topbar nav is redundant on mobile (it's in the drawer); keep the primary action */
  .tb-right .btn-outline { display: none; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .page-head > div:last-child, .page-head .acts { width: 100%; }
  .hello { flex-direction: column; align-items: flex-start; }
  .hello .acts { display: flex; width: 100%; gap: 9px; }
  .hello .acts .btn { flex: 1; justify-content: center; }
  .grid2 { grid-template-columns: 1fr !important; }
  .acard { overflow-x: auto; }
  .dtable { min-width: 480px; }
  .et-head, .erow { grid-template-columns: 1.8fr 1fr 1fr; }
  .et-head span:nth-child(4), .et-head span:nth-child(5), .erow .col4, .erow .more { display: none; }
}
@media (max-width: 440px) { .kpis, .tiles { grid-template-columns: 1fr; } }
