/* Subus — dark chrome around a light grid, following Aegisub's layout. */

:root {
  --chrome: #2b2b2e;
  --chrome-2: #37373b;
  --chrome-line: #1d1d20;
  --text: #e8e8ea;
  --text-dim: #9a9aa2;
  --accent: #4a90d9;

  --grid-bg: #ffffff;
  --grid-line: #d8d8dc;
  --grid-head: #c6d9ec;
  --grid-text: #14141a;
  --row-selected: #d8f0dd;
  --row-active-border: #e050a0;

  --ok: #6ac46a;
  --warn: #e8b84a;
  --error: #f06060;

  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--chrome);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

/* --- toolbar ------------------------------------------------------------- */

#toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  background: var(--chrome-2);
  border-bottom: 1px solid var(--chrome-line);
  flex: none;
}

.brand-logo {
  height: 24px;
  width: auto;
  display: block;
  flex: none;
  user-select: none;
}

.doc-title {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
  max-width: 34ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-title.is-dirty { color: var(--warn); }

/* Save state, stated in words rather than a symbol you have to remember. */
.save-state {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px 2px 6px;
  border-radius: 10px;
  font-size: 11px;
  white-space: nowrap;
  border: 1px solid transparent;
  user-select: none;
}
.save-state .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
}

.save-state[data-state="saved"] {
  color: #7fbf7f;
  background: rgba(106, 196, 106, 0.12);
  border-color: rgba(106, 196, 106, 0.3);
}
.save-state[data-state="saved"] .dot { background: var(--ok); }

.save-state[data-state="dirty"] {
  color: #f0cd7a;
  background: rgba(232, 184, 74, 0.15);
  border-color: rgba(232, 184, 74, 0.45);
}
.save-state[data-state="dirty"] .dot { background: var(--warn); }

.save-state[data-state="new"] {
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.12);
}
.save-state[data-state="new"] .dot { background: var(--text-dim); }
.doc-title { cursor: text; }
.doc-title:hover { color: var(--text); }

.title-edit {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  background: #1f1f22;
  border: 1px solid var(--accent);
  border-radius: 3px;
  padding: 3px 5px;
  width: 34ch;
}
.title-edit:focus { outline: none; }

.sep {
  width: 1px;
  align-self: stretch;
  background: var(--chrome-line);
  margin: 0 4px;
}
.grow { flex: 1; }

.counts {
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
}

button {
  font: inherit;
  color: var(--text);
  background: #45454a;
  border: 1px solid #55555c;
  border-radius: 4px;
  padding: 4px 9px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: #52525a; }
button:active:not(:disabled) { background: #3a3a40; }
button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* --- spectrogram --------------------------------------------------------- */

#spectro {
  position: relative;
  flex: none;
  height: 210px;
  min-height: 90px;
  max-height: 60vh;
  background: #101014;
  border-bottom: 1px solid var(--chrome-line);
  /* Resizable so you can trade grid space for spectrogram detail. */
  resize: vertical;
  overflow: hidden;
}

#spectro-canvas {
  display: block;
  cursor: crosshair;
}

.spectro-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: #55555e;
  font-size: 12px;
}
.spectro-empty b { color: #8a8a98; }

/* --- transport ----------------------------------------------------------- */

#transport {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
  padding: 5px 8px;
  background: #212126;
  border-bottom: 1px solid var(--chrome-line);
}

/* Labelled toolbar buttons. The file actions carry words because a mistake
   there costs work, and because three document-shaped glyphs in one row cannot
   be told apart at this size. Undo and redo stay icon-only: those two arrows
   are universal, and they are reversible anyway. */
.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 9px 0 7px;
  white-space: nowrap;
}
.tool-btn svg {
  display: block;
  flex: none;
  opacity: 0.85;
}
.tool-btn .lbl { font-size: 12px; }
.tool-btn:hover:not(:disabled) svg { opacity: 1; }

/* Save is the action you reach for most, so it reads as the primary one —
   but only while there is actually something to save. */
.tool-btn.is-primary:not(:disabled) {
  color: #cfe3ff;
  border-color: #4a6f9e;
  background: #3a5372;
}
.tool-btn.is-primary:not(:disabled):hover { background: #456385; }

.tool-btn.is-danger:not(:disabled):hover {
  color: #ffd9d9;
  border-color: #8d4646;
  background: #6d3535;
}

/* Icon buttons: square, so the glyph is the whole affordance. */
.icon-btn,
#transport button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 26px;
  padding: 0;
}
.icon-btn svg,
#transport button svg { display: block; }

#transport button.tp-primary {
  width: 34px;
  border-color: #6a6a76;
  background: #4e4e58;
}
#transport button.tp-primary:hover:not(:disabled) { background: #5c5c68; }

/* The in/out point buttons echo the marker colours. */
#transport button.tp-start { color: #ff7b74; }
#transport button.tp-end { color: #7aa8ff; }

/* Toggle state for Follow. */
#transport button.tp-toggle.is-on {
  color: #9dd0ff;
  border-color: var(--accent);
  background: #2f4256;
}

.tp-sep {
  width: 1px;
  align-self: stretch;
  background: #35353d;
  margin: 0 4px;
}

.tp-slider {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-dim);
}
.tp-slider svg { display: block; flex: none; }
.tp-slider input[type="range"] {
  width: 68px;
  accent-color: var(--accent);
}

.tp-pos {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  min-width: 66px;
  text-align: right;
}

/* The browser has not unlocked audio yet: say so rather than showing a stalled
   counter and a pause button that never resolves. */
.tp-pos.is-blocked { color: var(--warn); }
#transport button.is-blocked {
  color: var(--warn);
  border-color: var(--warn);
}

.tp-audio-name {
  font-size: 11px;
  color: var(--text-dim);
  max-width: 26ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- edit box ------------------------------------------------------------ */

#editbox {
  flex: none;
  padding: 7px 10px 9px;
  background: var(--chrome);
  border-bottom: 1px solid var(--chrome-line);
}

.edit-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-dim);
  white-space: nowrap;
  user-select: none;
}

#editbox input[type="text"],
#editbox input[type="number"],
#editbox select,
#editbox textarea {
  font: inherit;
  color: var(--text);
  background: #1f1f22;
  border: 1px solid #4a4a52;
  border-radius: 3px;
  padding: 4px 6px;
  min-width: 0;
}
#editbox input:disabled,
#editbox select:disabled,
#editbox textarea:disabled {
  opacity: 0.45;
}
#editbox input:focus,
#editbox select:focus,
#editbox textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.grow-1 { flex: 1; }
.grow-2 { flex: 2; }
.spacer { flex: 1; }

.num { width: 62px; text-align: right; font-family: var(--mono); }
.time { width: 108px; text-align: center; font-family: var(--mono); }

.charcount {
  min-width: 34px;
  padding: 4px 6px;
  text-align: center;
  color: var(--text-dim);
  background: #1f1f22;
  border: 1px solid #3a3a42;
  border-radius: 3px;
  font-family: var(--mono);
}

.fmt {
  width: 30px;
  padding: 4px 0;
  text-align: center;
}

.edit-text {
  display: block;
  width: 100%;
  height: 68px;
  resize: vertical;
  font-family: var(--mono) !important;
  font-size: 13px;
  line-height: 1.5;
}

/* --- grid --------------------------------------------------------------- */

#grid-container {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--grid-bg);
  outline: none;
}

table.grid {
  width: 100%;
  border-collapse: collapse;
  color: var(--grid-text);
  font-size: 12.5px;
}

table.grid thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--grid-head);
  border-right: 1px solid #a9bccf;
  border-bottom: 1px solid #8fa6bd;
  padding: 4px 6px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
}

table.grid td {
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid #ececf0;
  padding: 3px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-num   { width: 44px;  text-align: right;  font-variant-numeric: tabular-nums; }
.col-time  { width: 96px;  text-align: center; font-family: var(--mono); }
.col-cps   { width: 44px;  text-align: center; padding: 0 !important; }
.col-style { width: 110px; }
.col-actor { width: 90px; }
.col-text  { width: auto; }

.cps-cell {
  display: block;
  padding: 3px 6px;
  font-variant-numeric: tabular-nums;
}

table.grid tbody tr { cursor: default; }
table.grid tbody tr:hover { background: #f2f6fa; }
table.grid tbody tr.is-selected { background: var(--row-selected); }
table.grid tbody tr.is-selected:hover { background: #cbe9d2; }

/* The active row gets Aegisub's magenta outline. Using box-shadow keeps the
   row height from shifting the way a border would. */
table.grid tbody tr.is-active td {
  box-shadow:
    inset 0 1px 0 var(--row-active-border),
    inset 0 -1px 0 var(--row-active-border);
}
table.grid tbody tr.is-active td:first-child {
  box-shadow:
    inset 1px 0 0 var(--row-active-border),
    inset 0 1px 0 var(--row-active-border),
    inset 0 -1px 0 var(--row-active-border);
}
table.grid tbody tr.is-active td:last-child {
  box-shadow:
    inset -1px 0 0 var(--row-active-border),
    inset 0 1px 0 var(--row-active-border),
    inset 0 -1px 0 var(--row-active-border);
}

table.grid tbody tr.is-comment td { color: #8a8a92; font-style: italic; }

/* --- status bar --------------------------------------------------------- */

#statusbar {
  flex: none;
  min-height: 24px;
  display: flex;
  align-items: center;
  padding: 3px 10px;
  background: var(--chrome-2);
  border-top: 1px solid var(--chrome-line);
  font-size: 12px;
  color: var(--text-dim);
}
#status.ok    { color: var(--ok); }
#status.warn  { color: var(--warn); }
#status.error { color: var(--error); }

/* --- drop overlay ------------------------------------------------------- */

#drop-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(20, 20, 26, 0.72);
  z-index: 100;
}
#drop-overlay.visible { display: flex; }

.drop-inner {
  padding: 22px 34px;
  border: 2px dashed var(--accent);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  background: rgba(40, 40, 48, 0.9);
}
