/* ============================================================
   TABLE // FORMULA — AppSheet HTML Table Formula Generator
   Theme: white ground, hairline rule, one red accent, mono/grotesk
   type system. Formula output reads like a dark terminal pane.
   ============================================================ */

:root{
  --bg: #FFFFFF;
  --panel: #FFFFFF;
  --panel-2: #F7F7F7;
  --line: rgba(0,0,0,0.14);
  --text: #111111;
  --muted: rgba(0,0,0,0.55);
  --red: #E4002B;
  --red-dim: #FCE1E5;
  --ink: #111111;
  --radius: 4px;
}

*{ box-sizing: border-box; }
html{ scroll-behavior: smooth; }
body{
  margin:0;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', sans-serif;
  line-height:1.5;
  -webkit-font-smoothing: antialiased;
}

/* background module texture */
body::before{
  content:"";
  position: fixed;
  inset:0;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(20,22,26,0.06) 1px, transparent 1px);
  background-size: 22px 22px;
  pointer-events:none;
  z-index:0;
}

.wrap{ max-width: 1180px; margin:0 auto; padding: 0 32px; position:relative; z-index:1; }

h1,h2,h3{ font-family:'Space Grotesk', sans-serif; margin:0; letter-spacing:-0.01em; }
code, .mono{ font-family:'IBM Plex Mono', monospace; }
a{ color:inherit; }

::selection{ background: var(--red); color:#fff; }

:focus-visible{ outline: 2px solid var(--red); outline-offset: 3px; }

/* ---------- NAV ---------- */
header.top{
  position: sticky; top:0; z-index:50;
  background: rgba(255,255,255,0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar{
  display:flex; align-items:center; justify-content:space-between;
  padding: 18px 0;
  gap: 16px;
}
.topbar-right{ display:flex; align-items:center; gap:14px; }
.logo{
  display:flex; align-items:center; gap:10px;
  font-family:'Space Grotesk', sans-serif;
  font-weight:600; font-size:17px;
  letter-spacing: 0.02em;
}
.logo .finder{
  width:16px; height:16px;
  border: 2.5px solid var(--red);
  border-radius:2px;
  position:relative;
  flex-shrink:0;
}
.logo .finder::after{
  content:"";
  position:absolute; inset:4px;
  background: var(--red);
}
.logo .slash{ color: var(--muted); font-weight:400; }
/* YouTube button — outlined by default, fills with brand red on hover
   so it reads as a secondary action next to the primary red accent. */
.youtube-btn{
  display:inline-flex; align-items:center; gap:8px;
  text-decoration:none;
  background: var(--panel);
  color: #FF0000;
  font-family:'IBM Plex Mono', monospace;
  font-size: 13px; font-weight:500; letter-spacing:0.02em;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid #FF0000;
  transition: background .15s, color .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
}
.youtube-btn svg{ width:16px; height:16px; flex-shrink:0; transition: transform .15s; }
.youtube-btn:hover{ background:#FF0000; color:#fff; box-shadow: 0 4px 14px rgba(255,0,0,0.25); }
.youtube-btn:hover svg{ transform: scale(1.08); }
.youtube-btn:active{ transform: scale(0.97); }
@media (max-width: 480px){
  .youtube-btn span.label{ display:none; }
  .youtube-btn{ padding:10px 12px; }
}

/* Buy me a coffee */
.coffee-wrap{ margin-top: 18px; display:flex; align-items:center; gap:12px; flex-wrap:wrap; }
.donate-btn{
  display:inline-flex; align-items:center; gap:8px;
  text-decoration:none;
  background: var(--panel);
  color: var(--red);
  font-family:'IBM Plex Mono', monospace;
  font-size: 13px; font-weight:500; letter-spacing:0.02em;
  padding: 10px 18px;
  border: 1px solid var(--red);
  border-radius: 999px;
  transition: background .15s, color .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
}
.donate-btn svg{ width:16px; height:16px; flex-shrink:0; }
.donate-btn:hover{ background: var(--red); color:#fff; box-shadow: 0 4px 14px rgba(228,0,43,0.28); }
.donate-btn:hover svg{ transform: rotate(-6deg); }
.donate-btn:active{ transform: scale(0.97); }
.coffee-note{ font-family:'IBM Plex Mono', monospace; font-size: 12px; color: var(--muted); }

/* ---------- HERO ---------- */
.hero{
  padding: 44px 0 36px;
  display:grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 48px;
  align-items:start;
}
@media (max-width: 900px){
  .hero{ grid-template-columns: 1fr; padding: 32px 0 20px; gap: 28px; }
}

.eyebrow{
  display:inline-flex; align-items:center; gap:8px;
  font-family:'IBM Plex Mono', monospace;
  font-size:12px; letter-spacing: 0.08em;
  color: var(--red);
  text-transform: uppercase;
  margin-bottom: 14px;
}
.eyebrow .dot{
  width:6px; height:6px; background: var(--red); border-radius:50%;
  animation: blink 1.6s ease-in-out infinite;
}
@keyframes blink{ 0%,100%{opacity:1;} 50%{opacity:0.25;} }

h1.headline{
  font-size: clamp(26px, 3.2vw, 36px);
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 12px;
}
h1.headline .accent{ color: var(--red); }

.sub{
  color: var(--muted);
  font-size: 14.5px;
  max-width: 52ch;
  margin-bottom: 24px;
}
.sub code.mono{
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 13px;
  color: var(--red);
}

/* ---------- PANELS (config cards) ---------- */
.panel{
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px 20px 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(20,22,26,0.03);
}
.panel-head{
  display:flex; align-items:baseline; justify-content:space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.panel-title{
  font-family:'Space Grotesk', sans-serif;
  font-weight:600; font-size: 15px;
}
.panel-hint{
  font-family:'IBM Plex Mono', monospace;
  font-size: 11.5px; color: var(--muted);
}

/* ---------- Columns table ---------- */
.columns-table-head{
  display:grid;
  grid-template-columns: 34px 1fr 1fr 0.85fr 68px;
  gap:10px;
  padding: 0 6px 8px;
  font-family:'IBM Plex Mono', monospace;
  font-size: 10.5px; letter-spacing:0.06em; text-transform:uppercase;
  color: var(--muted);
}
.columns-table-head span:first-child{ grid-column: 2; }

#columns-list{ display:flex; flex-direction:column; gap:8px; margin-bottom:16px; }

.column-row{
  display:grid;
  grid-template-columns: 34px 1fr 1fr 0.85fr 68px;
  gap:10px;
  align-items:center;
  padding: 10px 10px 10px 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.col-index{
  font-family:'IBM Plex Mono', monospace;
  font-size: 12px;
  font-weight:600;
  color: var(--red);
  text-align:center;
}

.column-row .text-input{ width:100%; }

.col-actions{ display:flex; align-items:center; justify-content:flex-end; gap:2px; }

.icon-btn{
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  width: 26px; height:26px;
  border-radius: 4px;
  display:grid; place-items:center;
  cursor:pointer;
  font-size: 12px; line-height:1;
  transition: background .12s ease, color .12s ease;
}
.icon-btn:hover{ background: var(--line); color: var(--text); }
.icon-btn:disabled{ opacity:0.3; cursor:not-allowed; }
.icon-btn:disabled:hover{ background:transparent; }
.icon-btn.remove:hover{ background: var(--red-dim); color: var(--red); }

/* ---------- Inputs ---------- */
.text-input, .mono-input{
  font-family:'IBM Plex Sans', sans-serif;
  font-size: 13.5px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  min-width:0;
}
.mono-input{ font-family:'IBM Plex Mono', monospace; font-size:13px; }
.text-input:focus, .mono-input:focus{
  outline:none; border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-dim);
}
.width-input{ max-width: 110px; }

/* ---------- Buttons ---------- */
.btn-add{
  width:100%;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px dashed var(--line);
  color: var(--red);
  font-family:'IBM Plex Mono', monospace;
  font-size: 13px; font-weight:500;
  border-radius: var(--radius);
  cursor:pointer;
  display:flex; align-items:center; justify-content:center; gap:6px;
  transition: background .15s, border-color .15s;
}
.btn-add:hover{ background: var(--red-dim); border-color: var(--red); }
.btn-add .plus{ font-size:15px; }

.copy-btn{
  margin-top: 16px;
  display:inline-flex; align-items:center; gap:8px;
  background: var(--red);
  color:#fff;
  border:none;
  font-family:'IBM Plex Mono', monospace;
  font-size: 13px; letter-spacing:0.03em;
  padding: 11px 18px;
  border-radius: var(--radius);
  cursor:pointer;
  transition: background .15s, transform .1s;
}
.copy-btn:hover{ background:#c60025; }
.copy-btn:active{ transform: scale(0.98); }
.copy-btn.copied{ background: var(--ink); color:#fff; }

/* ---------- Fields / tab-style segmented controls ---------- */
.field{ margin-bottom:16px; }
.field:last-child{ margin-bottom:0; }
.field > label{
  display:block;
  font-family:'IBM Plex Mono', monospace;
  font-size: 11px; letter-spacing:0.08em; text-transform:uppercase;
  color: var(--muted);
  margin-bottom: 9px;
}
.field-note{ text-transform:none; letter-spacing:normal; font-weight:400; color: var(--muted); }

.row{ display:flex; gap:22px; flex-wrap:wrap; align-items:flex-end; margin-bottom:16px; }
.row .field{ margin-bottom:0; }
.row .field:first-child{ display:flex; flex-direction:column; align-items:flex-start; }
.row .field:first-child > label{ margin-bottom: 9px; }

.tabgroup{
  display:inline-flex; flex-wrap:wrap; gap:4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  width: fit-content;
}
.tab-opt{ position:relative; cursor:pointer; }
.tab-opt input{ position:absolute; opacity:0; pointer-events:none; }
.tab-opt span{
  display:inline-block;
  font-family:'IBM Plex Mono', monospace;
  font-size: 12.5px;
  letter-spacing:0.02em;
  color: var(--muted);
  background: transparent;
  padding: 7px 14px;
  border-radius: 3px;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.tab-opt span:hover{ color: var(--text); }
.tab-opt input:checked + span{ background: var(--red); color:#fff; }
.tab-opt input:focus-visible + span{ outline: 2px solid var(--red); outline-offset: 1px; }

/* Toggle switch */
.switch{
  width:42px; height:24px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  position:relative;
  cursor:pointer;
  padding:0;
  flex:none;
  display:inline-block;
  vertical-align: middle;
  margin-right: 8px;
}
.switch-knob{
  position:absolute; top:2px; left:2px;
  width:18px; height:18px;
  border-radius:50%;
  background:#fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  transition: transform .15s ease;
}
.switch.is-on{ background: var(--red); border-color: var(--red); }
.switch.is-on .switch-knob{ transform: translateX(18px); }
.switch-state{
  font-family:'IBM Plex Mono', monospace;
  font-size:12px; font-weight:700; color: var(--muted);
  vertical-align: middle;
}

/* ---------- VIEWFINDER (live preview) ---------- */
.viewfinder-outer{ position: sticky; top: 88px; }
.viewfinder{
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  overflow:hidden;
  min-height: 180px;
  box-shadow: 0 1px 2px rgba(20,22,26,0.04), 0 8px 24px rgba(20,22,26,0.05);
}
.viewfinder .bracket{
  position:absolute; width:28px; height:28px;
  border: 3px solid var(--red);
}
.viewfinder .bracket.tl{ top:12px; left:12px; border-right:none; border-bottom:none; }
.viewfinder .bracket.tr{ top:12px; right:12px; border-left:none; border-bottom:none; }
.viewfinder .bracket.bl{ bottom:12px; left:12px; border-right:none; border-top:none; }

.preview-scroll{ overflow-x:auto; position:relative; }

#preview-wrap table{
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 100%;
}
#preview-wrap th, #preview-wrap td{
  padding: 9px 13px;
  text-align:left;
  border: 1px solid var(--line);
}
#preview-wrap thead th{ background: var(--panel-2); }
#preview-wrap .empty-state{ color: var(--muted); font-size:13.5px; padding: 20px 4px; }

.viewfinder-caption{
  display:flex; justify-content:space-between; align-items:center;
  margin-top:14px;
  font-family:'IBM Plex Mono', monospace;
  font-size: 12px; color: var(--muted);
}
.viewfinder-caption .status{ color: var(--red); }

/* ---------- FORMULA SECTION ---------- */
section.formula{ padding: 40px 0 60px; }
.section-label{
  display:flex; align-items:center; gap:10px;
  font-family:'IBM Plex Mono', monospace;
  font-size:12px; letter-spacing:0.08em; text-transform:uppercase;
  color: var(--muted);
  margin-bottom: 18px;
}
.section-label .mark{
  width:12px; height:12px; border:2px solid var(--ink); position:relative; flex-shrink:0;
}
.section-label .mark::after{ content:""; position:absolute; inset:3px; background: var(--ink); }

.terminal{
  background: #14161A;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow:hidden;
  box-shadow: 0 1px 2px rgba(20,22,26,0.04), 0 8px 24px rgba(20,22,26,0.05);
}
.terminal-bar{
  display:flex; align-items:center; justify-content:space-between;
  padding: 10px 16px;
  border-bottom: 1px solid #262a33;
  background: #1B1E24;
}
.terminal-bar .path{ font-size:12px; color:#8A93A6; }
.dots{ display:flex; gap:6px; }
.dots span{ width:9px; height:9px; border-radius:50%; background:#3a4152; }

.terminal-body{ padding: 22px 20px; max-height: 420px; overflow-y:auto; }
.terminal-body pre{
  margin:0;
  font-family:'IBM Plex Mono', monospace;
  font-size: 13px;
  line-height:1.7;
  color: #E7E9ED;
  white-space: pre-wrap;
  word-break: break-word;
}
.tok-str{ color:#f2c078; }
.tok-fn{ color:#5EEAD4; font-weight:600; }
.tok-punc{ color:#8A93A6; }
.tok-col{ color:#ff5c73; font-weight:600; }

/* ---------- REFERENCE TABLE ---------- */
section.reference{ padding: 0 0 72px; }
.ref-table{ width:100%; border-collapse:collapse; font-size:14px; }
.ref-table th{
  text-align:left;
  font-family:'IBM Plex Mono', monospace;
  font-size: 11px; letter-spacing:0.06em; text-transform:uppercase;
  color: var(--muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.ref-table td{
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.ref-table td.param{ color: var(--red); white-space:nowrap; }
.ref-table td.desc{ color: var(--text); }
.ref-table td.vals{ color: var(--muted); font-size:13px; }
.ref-table tr:last-child td{ border-bottom:none; }
.ref-wrap{ overflow-x:auto; }

/* ---------- FOOTER ---------- */
footer{ border-top: 1px solid var(--line); padding: 28px 0; }
.footer-row{
  display:flex; justify-content:space-between; align-items:center;
  font-size: 13px; color: var(--muted);
  flex-wrap:wrap; gap:10px;
}
.footer-row .muted{ color:#8b93a1; }

@media (max-width: 900px){
  .viewfinder-outer{ position: static; }
}

@media (max-width: 640px){
  .columns-table-head{ display:none; }
  .column-row{ grid-template-columns: 28px 1fr; grid-template-areas: "idx header" "idx column" "idx sample" "idx actions"; row-gap:8px; }
  .column-row .col-index{ grid-row: 1 / span 4; align-self:start; padding-top:8px; }
  .column-row .col-actions{ justify-content:flex-start; }
}

@media (max-width: 480px){
  .wrap{ padding: 0 18px; }
  h1.headline{ font-size: 28px; }
}

@media (prefers-reduced-motion: reduce){
  .eyebrow .dot{ animation:none; }
}
