:root{
  --bg: #0b1220;
  --panel: rgba(255,255,255,0.06);
  --panel2: rgba(255,255,255,0.08);
  --text: rgba(255,255,255,0.92);
  --muted: rgba(255,255,255,0.65);
  --border: rgba(255,255,255,0.14);
  --accent: #7dd3fc;
  --accent2:#a78bfa;
  --good:#34d399;
  --warn:#fbbf24;
  --bad:#fb7185;
  --shadow: 0 12px 30px rgba(0,0,0,0.35);
  --radius: 16px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  --font: 15px;
  --line: 1.35;
}

[data-theme="light"]{
  --bg: #f6f8ff;
  --panel: rgba(17,24,39,0.04);
  --panel2: rgba(17,24,39,0.06);
  --text: rgba(17,24,39,0.92);
  --muted: rgba(17,24,39,0.62);
  --border: rgba(17,24,39,0.14);
  --shadow: 0 12px 30px rgba(17,24,39,0.12);
  --accent: #0284c7;
  --accent2:#7c3aed;
  --good:#059669;
  --warn:#b45309;
  --bad:#e11d48;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  background:
    radial-gradient(1200px 700px at 10% 10%, rgba(167,139,250,0.20), transparent 65%),
    radial-gradient(1000px 600px at 85% 20%, rgba(125,211,252,0.18), transparent 60%),
    radial-gradient(900px 600px at 50% 100%, rgba(52,211,153,0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--font);
  line-height: var(--line);
}

.app{
  display:grid;
  grid-template-columns: 360px 1fr 360px;
  gap: 14px;
  padding: 14px;
  max-width: 1700px;
  margin: 0 auto;
}

/* Medium screens: keep preview but stack it below editor */
@media (max-width: 1200px){
  .app{
    grid-template-columns: 320px minmax(0, 1fr);
    grid-template-rows: auto auto;
  }
  .right{
    grid-column: 1 / -1;
  }
}

/* Base mobile helpers (hidden by default, enabled in mobile media query) */
.mobileTabsHeader{
  display:none;
}
.mobileSttBar{
  display:none;
}
.navToggle{
  display:none;
}
.navBodyInner{
  /* wrapper for collapsible nav content on mobile */
}

@media (max-width: 860px){
  html, body{
    font-size: 16px;
  }

  .app{
    grid-template-columns: 1fr;
    padding: 8px;
    width: 100%;
  }

  .nav{
    position:relative !important;
    top:auto !important;
    margin-bottom: 8px;
  }

  .nav .card{
    position: static;
    max-height: none;
    overflow: visible;
  }

  /* Collapsible workflow/procedure panel */
  .navToggle{
    display:block;
    width:100%;
    margin-bottom:8px;
  }
  .navBodyInner.navBodyInner-closed{
    display:none;
  }

  /* Mobile Editor / Preview tabs */
  .mobileTabsHeader{
    display:flex;
    gap:8px;
    margin-bottom:8px;
    position:sticky;
    top:0;
    z-index:20;
    padding:6px 2px 6px 2px;
    background: linear-gradient(180deg, rgba(15,23,42,0.96), rgba(15,23,42,0.92));
    border-radius: 999px;
  }
  .mobileTab{
    flex:1;
    border-radius: 999px;
    border:1px solid var(--border);
    background: rgba(255,255,255,0.04);
    color: var(--muted);
    font-size: 13px;
    padding: 8px 10px;
    text-align:center;
    cursor:pointer;
  }
  .mobileTab--active{
    background: rgba(125,211,252,0.18);
    color: var(--text);
    border-color: rgba(125,211,252,0.6);
  }

  /* On mobile, use app class to decide which pane is visible */
  .app.mobile-tab-editor .right{
    display:none;
  }
  .app.mobile-tab-preview .main{
    display:none;
  }

  /* Sticky bottom dictation bar */
  .mobileSttBar{
    display:flex;
    position:fixed;
    left:0;
    right:0;
    bottom:0;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: rgba(15,23,42,0.96);
    border-top:1px solid var(--border);
    z-index:50;
    gap:8px;
  }
  .mobileSttBar .btn{
    flex:1;
    min-height:44px;
    font-size:14px;
    padding:10px 12px;
  }

  /* Touch-friendly tweaks */
  .btn{
    min-height:40px;
  }
  .checkItem{
    font-size:14px;
  }
  .checkItem input{
    margin-top:5px;
  }

  .input, select, textarea{
    font-size:16px;
  }
  textarea{
    min-height:130px;
  }

  .section{
    margin-bottom:16px;
  }

  /* Slightly lighter shadow on low-end mobile for perf */
  .card{
    box-shadow: 0 8px 18px rgba(0,0,0,0.28);
  }
}

.card{
  background: linear-gradient(180deg, var(--panel), rgba(255,255,255,0.02));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
}
.cardHeader{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 12px 14px;
  border-bottom:1px solid var(--border);
  background: linear-gradient(90deg, rgba(167,139,250,0.10), rgba(125,211,252,0.08));
}
.cardHeader h3{
  margin:0;
  font-size: 14px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
}
.cardBody{ padding: 12px 14px; }

.btnRow{ display:flex; gap:8px; flex-wrap:wrap; }
.btn{
  appearance:none;
  border:1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 12px;
  cursor:pointer;
  font-weight:600;
  font-size: 13px;
  transition: transform .06s ease, background .15s ease, border-color .15s ease;
  user-select:none;
}
.btn:hover{ background: rgba(255,255,255,0.08); }
.btn:active{ transform: translateY(1px); }
.btnPrimary{ border-color: rgba(125,211,252,0.45); background: rgba(125,211,252,0.14); }
.btnGood{ border-color: rgba(52,211,153,0.45); background: rgba(52,211,153,0.12); }
.btnBad{ border-color: rgba(251,113,133,0.45); background: rgba(251,113,133,0.10); }

.chip{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:6px 10px;
  border:1px solid var(--border);
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
  white-space:nowrap;
}

.field label{
  display:block;
  font-size:12px;
  color: var(--muted);
  margin-bottom:6px;
  font-weight:700;
  letter-spacing:0.2px;
}

.input, select, textarea{
  width:100%;
  padding: 10px 10px;
  border-radius: 12px;
  border:1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  outline:none;
  font-size: 14px;
}
textarea{ min-height: 90px; resize: vertical; }

.mini{
  font-size: 12px;
  color: var(--muted);
  margin-top:8px;
}

.nav{
  position: relative;
}

/* Make the left WORKFLOW card stick while scrolling */
.nav .card{
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.procList{
  display:flex;
  flex-direction:column;
  gap:10px;
  max-height: 420px;
  overflow:auto;
  padding-right: 6px;
  -webkit-overflow-scrolling: touch;
}

.procCard{
  border:1px solid var(--border);
  background: rgba(255,255,255,0.03);
  border-radius: 14px;
  padding: 10px 10px;
  cursor:pointer;
}
.procCard:hover{ background: rgba(255,255,255,0.06); }
.procTitle{ font-weight:900; margin-bottom:4px; }
.procMeta{ color: var(--muted); font-size: 12px; display:flex; gap:8px; flex-wrap:wrap; }

.tag{
  font-size: 11px;
  color: var(--muted);
  padding: 4px 8px;
  border:1px solid var(--border);
  border-radius: 999px;
  background: rgba(255,255,255,0.03);
  white-space:nowrap;
}

.section{
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow:hidden;
  background: rgba(255,255,255,0.03);
}
.sectionHeader{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 10px 12px;
  user-select:none;
  background: linear-gradient(90deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  border-bottom:1px solid var(--border);
}
.sectionHeader strong{
  font-size: 14px;
  letter-spacing: 0.2px;
}
.sectionBody{ padding: 12px; }

.activeGlow{
  box-shadow: 0 0 0 3px rgba(167,139,250,0.14), 0 0 0 1px rgba(167,139,250,0.35) inset;
  border-color: rgba(167,139,250,0.50) !important;
  background: rgba(167,139,250,0.07) !important;
}

.organRow{
  display:grid;
  grid-template-columns: 180px 1fr;
  gap:10px;
  align-items:start;
  margin-bottom: 12px;
}
@media (max-width: 860px){
  .organRow{ grid-template-columns: 1fr; }
}

.checks{
  display:flex;
  flex-direction:column;
  gap:8px;
  padding: 10px;
  border:1px dashed var(--border);
  border-radius: 14px;
  background: rgba(255,255,255,0.02);
}
.checkItem{
  display:flex;
  gap:10px;
  align-items:flex-start;
  color: var(--muted);
  font-size: 13px;
  cursor:pointer;
  user-select:none;
}
.checkItem input{ margin-top:3px; }

.monoBox{
  border:1px solid var(--border);
  background: rgba(255,255,255,0.03);
  border-radius: 14px;
  padding: 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
}

/* Enable smoother scrolling on iOS Safari */
.main,
.right{
  -webkit-overflow-scrolling: touch;
}

/* Touch-specific tap target boosts */
[data-touch="1"] .btn{
  min-height:44px;
}
[data-touch="1"] .checkItem input{
  width:22px;
  height:22px;
}
