/* ============================================================================
   AudioForge Studio — Professional Web Audio Editor
   Dark DAW theme (Audition-class layout)
   ========================================================================== */

:root {
  --bg0: #0d0e13;
  --bg1: #14161d;
  --bg2: #1b1e27;
  --bg3: #232733;
  --bg4: #2b3040;
  --border: #2e3342;
  --border-light: #3a4152;
  --text: #d7dae4;
  --text-dim: #8a90a3;
  --text-faint: #5d6375;
  --accent: #7c5cff;
  --accent2: #22d3ee;
  --accent-grad: linear-gradient(135deg, #7c5cff, #22d3ee);
  --green: #2ecc71;
  --yellow: #f1c40f;
  --red: #e74c3c;
  --orange: #ff9f43;
  --meter-green: #1fb859;
  --meter-yellow: #ffd23f;
  --meter-red: #ff4545;
  --sel: rgba(124, 92, 255, 0.28);
  --mono: "Cascadia Mono", "Consolas", "SF Mono", Menlo, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg0);
  color: var(--text);
  font: 13px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select { font: inherit; }

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--bg1); }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 6px; border: 2px solid var(--bg1); }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }
* { scrollbar-width: thin; scrollbar-color: var(--bg4) var(--bg1); }

/* ============================ APP LAYOUT ============================ */

#app {
  display: grid;
  grid-template-rows: 46px 42px 1fr 26px;
  height: 100vh;
}

/* ============================ TITLE BAR ============================ */

#titlebar {
  display: flex;
  align-items: center;
  gap: 18px;
  background: linear-gradient(180deg, #191c26, #12141b);
  border-bottom: 1px solid var(--border);
  padding: 0 14px;
}

#brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
#brand-logo { width: 30px; height: 30px; border-radius: 7px; flex: none; object-fit: contain; }
#brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
#brand-name { font-weight: 700; font-size: 13px; letter-spacing: .2px; white-space: nowrap; }
#brand-tag { font-size: 10px; color: var(--text-faint); white-space: nowrap; }

#menubar { display: flex; gap: 2px; flex: none; }
.menu { position: relative; }
.menu > button {
  padding: 5px 11px;
  border-radius: 6px;
  color: var(--text-dim);
}
.menu > button:hover, .menu.open > button { background: var(--bg3); color: var(--text); }
.dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  min-width: 250px;
  background: var(--bg2);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 5px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .55);
  z-index: 400;
}
.menu.open .dropdown { display: block; }
.mi {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 10px;
  border-radius: 5px;
  text-align: left;
  color: var(--text);
  white-space: nowrap;
}
.mi:hover { background: var(--accent); color: #fff; }
.mi.disabled { opacity: .38; pointer-events: none; }
.mi .label { flex: 1; }
.mi .shortcut { color: var(--text-faint); font-size: 11px; font-family: var(--mono); }
.mi:hover .shortcut { color: rgba(255,255,255,.75); }
.mi-sep { height: 1px; background: var(--border); margin: 5px 8px; }

#project-badge {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 999px;
  max-width: 320px;
}
#project-name {
  color: var(--text-dim);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
#project-name:hover { color: var(--text); }
#dirty-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--orange); flex: none; }

/* ============================ TOOLBAR ============================ */

#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  overflow-x: auto;
  overflow-y: hidden;
}
.tb-group { display: flex; align-items: center; gap: 3px; flex: none; }
.tb-sep { width: 1px; height: 22px; background: var(--border); flex: none; }
.tb-flex { flex: 1; }
.tb-btn {
  min-width: 30px;
  height: 28px;
  padding: 0 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  flex: none;
}
.tb-btn:hover { background: var(--bg3); color: var(--text); border-color: var(--border-light); }
.tb-btn.wide { padding: 0 10px; }
.tb-btn.toggle.active {
  background: linear-gradient(180deg, rgba(124,92,255,.30), rgba(34,211,238,.18));
  border-color: var(--accent);
  color: #fff;
}
.tb-btn.record { color: #ff6b6b; }
.tb-btn.record.armed { background: rgba(231,76,60,.22); border-color: var(--red); color: #ff8080; animation: recpulse 1.2s infinite; }
@keyframes recpulse { 50% { box-shadow: 0 0 0 3px rgba(231,76,60,.18); } }

#time-lcd {
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: #07080c;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 12px;
  min-width: 150px;
  height: 30px;
  flex: none;
}
#time-main { font-family: var(--mono); font-size: 14px; color: #c7f7ff; letter-spacing: .5px; }
#time-sub { font-family: var(--mono); font-size: 10px; color: var(--text-faint); }

.tb-label { color: var(--text-faint); font-size: 11px; flex: none; }
.tb-select {
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  height: 28px;
  padding: 0 6px;
  flex: none;
}

/* ============================ MAIN ROW ============================ */

#main-row { display: flex; min-height: 0; }

#editor-column { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#ruler-row {
  display: flex;
  height: 30px;
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  flex: none;
}
#headers-gutter {
  width: 232px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-right: 1px solid var(--border);
}
.gutter-label { font-size: 10px; letter-spacing: 1.5px; color: var(--text-faint); font-weight: 600; }
#ruler-viewport { flex: 1; position: relative; overflow: hidden; }
#ruler-canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: col-resize; }

#timeline-row { display: flex; flex: 1; min-height: 0; }

/* -------- Track headers -------- */
#track-headers {
  width: 232px;
  flex: none;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: var(--bg1);
  position: relative;
}
.th-card {
  border-bottom: 1px solid var(--border);
  background: var(--bg1);
  padding: 7px 9px 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  position: relative;
  overflow: hidden;
}
.th-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--track-color, var(--accent));
}
.th-card.selected { background: var(--bg2); }
.th-top { display: flex; align-items: center; gap: 7px; padding-left: 5px; }
.th-color { width: 10px; height: 10px; border-radius: 3px; flex: none; cursor: pointer; }
.th-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: text;
}
.th-name:hover { color: #fff; }
.th-x {
  color: var(--text-faint);
  font-size: 13px;
  padding: 0 4px;
  border-radius: 4px;
  flex: none;
}
.th-x:hover { color: var(--red); background: rgba(231,76,60,.15); }
.th-btns { display: flex; gap: 4px; padding-left: 5px; }
.mini-btn {
  flex: 1;
  height: 20px;
  border-radius: 4px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .3px;
}
.mini-btn:hover { color: var(--text); border-color: var(--border-light); }
.mini-btn.on-m { background: rgba(241,196,15,.20); border-color: var(--yellow); color: var(--yellow); }
.mini-btn.on-s { background: rgba(46,204,113,.18); border-color: var(--green); color: var(--green); }
.mini-btn.on-r { background: rgba(231,76,60,.20); border-color: var(--red); color: #ff7b7b; animation: recpulse 1.2s infinite; }
.mini-btn.on-fx { background: rgba(124,92,255,.22); border-color: var(--accent); color: #b6a3ff; }
.mini-btn.on-sp { background: rgba(34,211,238,.18); border-color: var(--accent2); color: var(--accent2); }
.th-sliders { display: flex; flex-direction: column; gap: 3px; padding-left: 5px; }
.th-slider { display: grid; grid-template-columns: 34px 1fr 44px; align-items: center; gap: 6px; }
.th-slider label { font-size: 9px; letter-spacing: .8px; color: var(--text-faint); }
.th-slider .val { font-size: 10px; font-family: var(--mono); color: var(--text-dim); text-align: right; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--bg4);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--bg1);
  box-shadow: 0 1px 4px rgba(0,0,0,.5);
}
input[type="range"]::-moz-range-thumb {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--text); border: 2px solid var(--bg1);
}
input[type="range"].accent::-webkit-slider-thumb { background: var(--accent2); }

/* -------- Timeline viewport -------- */
#timeline-viewport { flex: 1; position: relative; overflow: auto; background: var(--bg0); }
#timeline-spacer { position: absolute; top: 0; left: 0; width: 10px; height: 10px; }
#timeline-canvas { position: sticky; top: 0; left: 0; display: block; cursor: default; }

/* ============================ MIXER ============================ */

#mixer-panel {
  width: 250px;
  flex: none;
  background: var(--bg1);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#mixer-panel.hidden { display: none; }
#mixer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  letter-spacing: 1.5px;
  font-weight: 700;
  color: var(--text-faint);
  flex: none;
}
#mixer-close { color: var(--text-faint); font-size: 15px; }
#mixer-close:hover { color: var(--text); }
#mixer-strips { flex: 1; overflow-y: auto; overflow-x: hidden; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 8px; padding: 8px; }

.mx-strip {
  width: 106px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.mx-strip.master { border-color: var(--border-light); background: linear-gradient(180deg, #20242f, #1a1d26); }
.mx-name {
  font-size: 10px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text-dim);
}
.mx-btns { display: flex; gap: 3px; }
.mx-btns .mini-btn { height: 17px; font-size: 9px; }
.mx-mid { display: flex; gap: 6px; height: 130px; }
.mx-fader-wrap { display: flex; align-items: center; justify-content: center; width: 30px; }
input[type="range"].fader {
  writing-mode: vertical-lr;
  direction: rtl;
  -webkit-appearance: slider-vertical;
  width: 26px; height: 100%;
}
input[type="range"].fader::-webkit-slider-thumb { width: 24px; height: 12px; border-radius: 3px; background: linear-gradient(180deg,#e6e9f2,#b9bfce); border: 1px solid #05060a; }
.mx-meter-wrap { flex: 1; position: relative; border: 1px solid var(--border); border-radius: 4px; background: #07080c; overflow: hidden; }
.mx-meter-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.mx-db { font-size: 9px; font-family: var(--mono); color: var(--text-dim); text-align: center; }
.mx-lim { font-size: 8px; letter-spacing: .6px; text-align: center; color: var(--text-faint); }

/* ============================ STATUS BAR ============================ */

#statusbar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg1);
  border-top: 1px solid var(--border);
  padding: 0 12px;
  font-size: 11px;
  color: var(--text-dim);
}
#status-left { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#status-center, #status-right { flex: none; font-family: var(--mono); font-size: 10px; color: var(--text-faint); }
#status-right b { color: var(--accent2); font-weight: 600; }

/* ============================ DIALOGS ============================ */

#dialog-root .dlg-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 9, .62);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  animation: fadein .12s ease-out;
}
@keyframes fadein { from { opacity: 0; } }

.dlg {
  background: var(--bg2);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  min-width: 430px;
  max-width: min(92vw, 860px);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .6);
  animation: pop .14s ease-out;
}
@keyframes pop { from { transform: scale(.97); opacity: 0; } }
.dlg-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
}
.dlg-head h3 { font-size: 13px; font-weight: 700; flex: 1; }
.dlg-head .sub { font-size: 11px; color: var(--text-faint); }
.dlg-x { color: var(--text-faint); font-size: 17px; width: 26px; height: 26px; border-radius: 6px; }
.dlg-x:hover { background: var(--bg3); color: var(--text); }
.dlg-body { padding: 14px 16px; overflow-y: auto; min-height: 40px; }
.dlg-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 16px;
  border-top: 1px solid var(--border);
}
.dlg-foot .left { flex: 1; display: flex; gap: 8px; }

.btn {
  height: 30px;
  padding: 0 16px;
  border-radius: 7px;
  background: var(--bg3);
  border: 1px solid var(--border-light);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}
.btn:hover { background: var(--bg4); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.12); }
.btn.danger { background: transparent; border-color: var(--red); color: #ff8080; }
.btn.danger:hover { background: rgba(231,76,60,.15); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn.ghost:hover { color: var(--text); background: var(--bg3); }
.btn.toggled { background: rgba(124,92,255,.25); border-color: var(--accent); color: #fff; }

/* form fields */
.field { display: grid; grid-template-columns: 150px 1fr 74px; align-items: center; gap: 10px; margin-bottom: 11px; }
.field > label { font-size: 12px; color: var(--text-dim); }
.field .val { font-family: var(--mono); font-size: 11px; color: var(--accent2); text-align: right; }
.field input[type="number"], .field select, .field input[type="text"] {
  background: var(--bg1);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  height: 27px;
  padding: 0 8px;
  width: 100%;
}
.field-wide { grid-template-columns: 1fr; }
.checkrow { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 12px; color: var(--text-dim); cursor: pointer; }
.checkrow input { accent-color: var(--accent); }
.dlg-note { font-size: 11px; color: var(--text-faint); background: var(--bg1); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; margin-top: 6px; }
.dlg-note.warn { border-color: rgba(241,196,15,.4); color: #ffe28a; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button {
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  border-radius: 5px 5px 0 0;
}
.tabs button.active { color: #fff; border-bottom-color: var(--accent); background: rgba(124,92,255,.10); }

.fx-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; margin-bottom: 12px; }
.fx-slot {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  background: var(--bg1);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.fx-slot:hover { border-color: var(--border-light); }
.fx-slot.on { border-color: var(--accent); background: rgba(124,92,255,.10); }
.fx-slot .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bg4); flex: none; }
.fx-slot.on .dot { background: var(--accent2); box-shadow: 0 0 8px var(--accent2); }
.fx-slot .nm { flex: 1; font-size: 12px; font-weight: 600; }

table.stats { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 11.5px; }
table.stats td { padding: 5px 8px; border-bottom: 1px solid var(--border); }
table.stats td:first-child { color: var(--text-dim); }
table.stats td:last-child { text-align: right; color: var(--accent2); }

/* EQ graph canvas */
.eq-canvas-wrap { border: 1px solid var(--border); border-radius: 7px; background: #07080c; margin-bottom: 12px; }
.eq-canvas-wrap canvas { display: block; width: 100%; height: 180px; }

/* Markers list */
.mk-list { display: flex; flex-direction: column; gap: 5px; }
.mk-row {
  display: grid;
  grid-template-columns: 86px 1fr auto auto;
  gap: 8px;
  align-items: center;
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 9px;
}
.mk-row .t { font-family: var(--mono); font-size: 11px; color: var(--accent2); cursor: pointer; }
.mk-row .t:hover { text-decoration: underline; }
.mk-row input { background: var(--bg0); border: 1px solid var(--border); color: var(--text); border-radius: 5px; height: 24px; padding: 0 7px; width: 100%; }
.mk-row button { color: var(--text-faint); padding: 2px 6px; border-radius: 4px; }
.mk-row button:hover { color: var(--red); background: rgba(231,76,60,.12); }

/* shortcuts table */
.keys { columns: 2; column-gap: 28px; }
.keys .krow { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; break-inside: avoid; font-size: 12px; }
.keys .krow b { font-family: var(--mono); font-size: 10.5px; color: var(--accent2); font-weight: 600; }

/* ============================ CONTEXT MENU ============================ */

#ctxmenu-root .ctxmenu {
  position: fixed;
  min-width: 220px;
  background: var(--bg2);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 5px;
  box-shadow: 0 14px 40px rgba(0,0,0,.6);
  z-index: 600;
  animation: pop .1s ease-out;
}
.ctxmenu .mi .shortcut { margin-left: auto; }

/* ============================ TOASTS ============================ */

#toast-root {
  position: fixed;
  right: 16px;
  bottom: 38px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 700;
  pointer-events: none;
}
.toast {
  background: var(--bg2);
  border: 1px solid var(--border-light);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 12px;
  color: var(--text);
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  max-width: 380px;
  animation: toastin .18s ease-out;
}
.toast.err { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }
.toast.fadeout { opacity: 0; transition: opacity .3s; }
@keyframes toastin { from { transform: translateX(20px); opacity: 0; } }

/* ============================ MISC ============================ */

.drag-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  background: rgba(13, 14, 19, .82);
  border: 2px dashed var(--accent);
  border-radius: 10px;
  margin: 10px;
  z-index: 50;
  pointer-events: none;
  color: var(--text-dim);
  font-size: 14px;
}
.drag-hint b { color: var(--accent2); font-size: 16px; }

@media (max-width: 1100px) {
  #mixer-panel { position: absolute; right: 0; top: 88px; bottom: 26px; z-index: 300; box-shadow: -12px 0 30px rgba(0,0,0,.5); }
  #brand-tag { display: none; }
}
