:root{
  --paper:var(--tds-paper);
  --paper-strong:var(--tds-paper-strong);
  --ink:var(--tds-ink);
  --muted:var(--tds-muted);
  --line:var(--tds-line);
  --accent:var(--tds-accent);
  --accent-soft:var(--tds-accent-soft);
  --open:var(--tds-open);
  --success:var(--tds-success);
  --radius:var(--tds-radius);
  --shadow:var(--tds-shadow);
  --surface:rgba(244,241,234,.88);
  --surface-soft:rgba(255,255,255,.28);
  --frame:var(--tds-ink);
  --control-text:rgba(26,27,31,.75);
}

@media (prefers-color-scheme:dark){
  :root{
    --surface:rgba(29,28,24,.94);
    --surface-soft:rgba(244,241,234,.1);
    --frame:rgba(244,241,234,.46);
    --control-text:rgba(244,241,234,.74);
  }
}

html,
body{
  min-height:100%;
}

button,
input,
textarea{
  border-radius:var(--radius);
}

.app-shell{
  width:min(1680px,calc(100% - 32px));
  margin:0 auto;
  padding:16px 0 48px;
  display:grid;
  gap:16px;
}

.topbar,
.panel{
  border:1px solid var(--frame);
  background:var(--surface);
  box-shadow:var(--shadow);
}

.topbar{
  position:sticky;
  top:12px;
  z-index:20;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:16px;
  padding:12px;
  backdrop-filter:blur(16px);
}

.top-left,
.top-actions,
.source-actions,
.handoff-bar{
  display:flex;
  align-items:center;
  gap:10px;
}

.top-left{
  min-width:0;
  gap:12px;
}

.top-actions,
.source-actions{
  flex-wrap:wrap;
  justify-content:flex-end;
}

.back,
.btn,
.file-btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  min-height:38px;
  border:1px solid var(--line);
  background:var(--surface-soft);
  color:var(--ink);
  padding:9px 13px;
  font-weight:900;
  text-transform:uppercase;
  letter-spacing:.02em;
  cursor:pointer;
  transition:transform .18s ease,border-color .18s ease,background .18s ease,color .18s ease;
}

.back{
  color:var(--muted);
  white-space:nowrap;
}

.btn:hover,
.back:hover,
.file-btn:hover{
  transform:translateY(-1px);
  border-color:rgba(215,25,32,.44);
  background:var(--accent-soft);
  color:var(--accent);
}

.btn.primary{
  border-color:rgba(215,25,32,.2);
  background:var(--accent-soft);
  color:var(--accent);
}

.btn.open{
  border-color:color-mix(in srgb,var(--open) 45%,transparent);
  background:color-mix(in srgb,var(--open) 13%,transparent);
  color:var(--open);
}

.btn.ghost{
  background:transparent;
}

.btn.compact{
  min-height:34px;
  padding:7px 10px;
  font-size:12px;
}

.file-btn input{
  position:absolute;
  inline-size:0;
  block-size:0;
  opacity:0;
  overflow:hidden;
  pointer-events:none;
}

h1,
h2,
p{
  margin:0;
}

h1{
  font-size:clamp(22px,2vw,32px);
  line-height:1;
  letter-spacing:-.06em;
  text-transform:uppercase;
}

.brand-wrap p,
.mini,
.source-actions p{
  color:var(--muted);
  font-size:13px;
  font-weight:750;
}

.eyebrow,
label span{
  color:var(--muted);
  font-size:12px;
  font-weight:900;
  letter-spacing:.08em;
  text-transform:uppercase;
}

.nav-stats{
  display:flex;
  align-items:center;
  gap:8px;
  min-height:38px;
}

.nav-stats span{
  display:inline-flex;
  align-items:center;
  gap:5px;
  min-height:38px;
  border:1px solid var(--line);
  background:var(--surface-soft);
  color:var(--muted);
  padding:8px 10px;
  font-size:12px;
  font-weight:900;
  letter-spacing:.04em;
  text-transform:uppercase;
}

.nav-stats strong{
  color:var(--ink);
  font-size:14px;
}

.workspace{
  display:grid;
  grid-template-columns:minmax(320px,.9fr) minmax(240px,340px);
  gap:16px;
  align-items:start;
}

.panel{
  min-width:0;
}

.source-panel,
.output-panel,
.preview-panel{
  grid-column:1;
}

.control-panel{
  position:sticky;
  top:98px;
  grid-column:2;
  grid-row:1 / span 3;
  max-height:calc(100vh - 116px);
  overflow:hidden;
  display:grid;
  grid-template-rows:auto minmax(0,1fr);
}

.section-head{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
  padding:14px;
  border-bottom:1px solid var(--frame);
}

.section-head h2{
  margin-top:4px;
  font-size:18px;
  line-height:1;
  letter-spacing:-.04em;
  text-transform:uppercase;
}

.format-switch{
  display:flex;
  gap:6px;
  flex-wrap:wrap;
  justify-content:flex-end;
}

.format-switch button{
  border:1px solid var(--line);
  background:transparent;
  color:var(--muted);
  min-height:32px;
  padding:7px 10px;
  font-size:12px;
  font-weight:900;
  text-transform:uppercase;
  cursor:pointer;
}

.format-switch button.active{
  border-color:rgba(215,25,32,.44);
  background:var(--accent-soft);
  color:var(--accent);
}

textarea,
input{
  width:100%;
  border:1px solid var(--line);
  background:var(--surface-soft);
  color:var(--ink);
  padding:12px;
  outline:none;
}

textarea:focus,
input:focus{
  border-color:rgba(215,25,32,.54);
  box-shadow:0 0 0 3px rgba(215,25,32,.1);
}

#sourceInput{
  min-height:clamp(260px,34vh,440px);
  border:0;
  border-bottom:1px solid var(--line);
  border-radius:0;
  resize:vertical;
  font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono",monospace;
  line-height:1.45;
}

.source-actions{
  justify-content:space-between;
  padding:12px 14px;
}

.field-list{
  overflow:auto;
  padding:12px;
  display:grid;
  gap:8px;
}

.field-item{
  display:grid;
  grid-template-columns:auto minmax(0,1fr);
  gap:10px;
  align-items:center;
  border:1px solid var(--line);
  background:var(--surface-soft);
  padding:10px;
}

.field-item input{
  width:auto;
  accent-color:var(--accent);
}

.field-item strong{
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  font-size:13px;
  text-transform:uppercase;
}

.handoff-bar{
  align-items:end;
  padding:14px;
  border-bottom:1px solid var(--line);
}

.handoff-bar label{
  flex:1;
  display:grid;
  gap:7px;
}

pre{
  min-height:220px;
  max-height:380px;
  margin:0;
  overflow:auto;
  padding:16px;
  color:var(--control-text);
  font:13px/1.45 ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono",monospace;
  white-space:pre;
}

.table-wrap{
  overflow:auto;
  max-height:480px;
}

table{
  width:100%;
  border-collapse:collapse;
  min-width:620px;
}

th,
td{
  border-bottom:1px solid var(--line);
  padding:11px 12px;
  text-align:left;
  vertical-align:top;
  max-width:280px;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

th{
  position:sticky;
  top:0;
  z-index:1;
  background:var(--surface);
  color:var(--ink);
  font-size:12px;
  text-transform:uppercase;
  letter-spacing:.06em;
}

td{
  color:var(--control-text);
  font-size:13px;
  font-weight:700;
}

.empty{
  margin:12px;
  padding:18px;
  border:1px dashed var(--line);
  color:var(--muted);
  font-size:13px;
  font-weight:750;
  line-height:1.4;
}

.toast{
  position:fixed;
  right:18px;
  bottom:18px;
  z-index:40;
  background:rgba(17,17,17,.9);
  color:#fff;
  border:1px solid rgba(255,255,255,.14);
  border-radius:var(--radius);
  padding:10px 14px;
  font-size:12px;
  font-weight:800;
  opacity:0;
  transform:translateY(8px);
  pointer-events:none;
  transition:opacity .2s ease,transform .2s ease;
}

.toast.show{
  opacity:1;
  transform:translateY(0);
}

@media (max-width:980px){
  .topbar,
  .top-left{
    align-items:stretch;
    flex-direction:column;
  }

  .top-actions,
  .source-actions{
    justify-content:stretch;
  }

  .top-actions > *,
  .source-actions > *{
    flex:1;
  }

  .workspace{
    grid-template-columns:1fr;
  }

  .control-panel,
  .source-panel,
  .output-panel,
  .preview-panel{
    position:static;
    grid-column:auto;
    grid-row:auto;
    max-height:none;
  }
}

@media (max-width:620px){
  .app-shell{
    width:calc(100% - 20px);
    padding-top:10px;
  }

  .handoff-bar{
    grid-template-columns:1fr;
  }

  .handoff-bar{
    display:grid;
  }

  .nav-stats{
    display:grid;
    grid-template-columns:1fr 1fr;
  }

  .nav-stats span{
    justify-content:center;
  }

  .section-head{
    align-items:flex-start;
    flex-direction:column;
  }

  .format-switch{
    justify-content:flex-start;
  }

  table,
  thead,
  tbody,
  tr,
  td{
    display:block;
  }

  table{
    min-width:0;
  }

  thead{
    display:none;
  }

  tbody{
    display:grid;
    gap:10px;
    padding:10px;
  }

  tr{
    border:1px solid var(--line);
    background:var(--surface-soft);
  }

  td{
    display:flex;
    justify-content:space-between;
    align-items:start;
    gap:14px;
    max-width:none;
    border-bottom:1px solid var(--line);
    padding:11px;
    text-align:right;
    white-space:normal;
  }

  td:last-child{
    border-bottom:0;
  }

  td:before{
    content:attr(data-label);
    flex:0 0 auto;
    max-width:42%;
    color:var(--muted);
    font-size:11px;
    font-weight:900;
    letter-spacing:.08em;
    text-transform:uppercase;
    text-align:left;
    overflow:hidden;
    text-overflow:ellipsis;
  }
}
