/* Lavagna Tattica - Framed Sheet (IBM Plex Sans + Mono su timecode) */
:root {
  --ground: #f3f6f4;
  --surface: #ffffff;
  --raised: #f4f6f8;
  --active: #e6ebe8;
  --border: #e2e6e4;
  --rule: #eef1ef;
  --control: #c8cecb;
  --text: #131416;
  --muted: #545956;
  --faint: #636865;
  --accent: #1f6b4a;
  --primary: #131416;
  --primary-ink: #ffffff;
  --positive: #1e7b4f;
  --negative: #c4242a;
  --warning: #92400e;
  --pill-neutral-bg: #ebedee;
  --pill-neutral-ink: #353736;
  --pill-accent-bg: #e4f1ea;
  --pill-accent-ink: #12452f;
  --pill-warn-bg: #fffbeb;
  --pill-warn-ink: #92400e;

  --font: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --fs-title: 22px;
  --fs-section: 16px;
  --fs-body: 14px;
  --fs-small: 13px;

  --sidebar-width: 268px;
  --topbar-height: 48px;
  --gap: 16px;
  --pad: 20px;
  --radius-card: 8px;
  --radius-control: 6px;
  --radius-sheet: 16px;
  --control-height: 32px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, *::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font: var(--fs-body)/20px var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p {
  margin: 0;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

code.timecode,
code.mono-inline {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

/* ---------- Shell L-frame + Sheet ---------- */
.shell {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px 0 14px;
  background: var(--ground);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-mark {
  color: var(--accent);
  flex: none;
}

.brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.topbar-center {
  display: flex;
  align-items: center;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stamp {
  font-size: var(--fs-small);
  color: var(--faint);
  white-space: nowrap;
}

.workspace-frame {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-width: 0;
}

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 12px 16px;
  background: var(--ground);
  min-width: 0;
}

.sidebar-mobile-head {
  display: none;
}

.sidebar-controls {
  display: grid;
  gap: 8px;
}

.group-label {
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--muted);
  padding: 2px 4px 0;
}

.schema-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  max-height: calc(100svh - 265px);
}

.schema-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  padding: 9px 10px;
  display: grid;
  gap: 4px;
  transition: background-color 140ms ease;
}

.schema-item:hover {
  background: var(--surface);
  border-color: var(--border);
}

.schema-item[aria-current="true"] {
  background: var(--surface);
  border-color: var(--control);
}

.schema-item-title {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--text);
}

.schema-item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: var(--fs-small);
  color: var(--muted);
}

.sidebar-bottom {
  margin-top: auto;
  padding-top: 8px;
  display: grid;
  gap: 8px;
}

.sidebar-io {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ---------- White Sheet (inset 8px destra/basso, zero ombra) ---------- */
.sheet {
  margin: 0 8px 8px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sheet);
  padding: var(--pad);
  min-width: 0;
}

.title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.title-main {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.title-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.title-row h1 {
  font-size: var(--fs-title);
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.title-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- Griglia 2 colonne builder ---------- */
.builder-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: var(--gap);
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 14px;
  min-width: 0;
}

.board-panel {
  display: grid;
  gap: 12px;
}

.board-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  flex-wrap: wrap;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-label {
  font-size: var(--fs-small);
  color: var(--muted);
  white-space: nowrap;
}

.status-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-control);
  background: var(--pill-accent-bg);
  color: var(--pill-accent-ink);
  font-size: 13px;
  font-weight: 500;
}

.status-banner.recording {
  background: #ffedea;
  color: #831c1e;
}

.banner-action {
  font-weight: 600;
  white-space: nowrap;
}

.canvas-wrap {
  width: 100%;
  background: #254f38;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  justify-content: center;
}

#tactical-canvas {
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

#tactical-canvas:active {
  cursor: grabbing;
}

/* ---------- Transport & Timeline ---------- */
.transport-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.transport-left,
.transport-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.phase-readout {
  font-size: var(--fs-small);
  color: var(--muted);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timecode {
  font-size: 13px;
  color: var(--text);
  background: var(--raised);
  padding: 4px 8px;
  border-radius: 5px;
}

.timeline-block {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
}

.timeline-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.meta {
  font-size: var(--fs-small);
  color: var(--muted);
  white-space: nowrap;
}

.scrubber {
  flex: 1;
  accent-color: var(--accent);
  height: 20px;
  margin: 0;
}

.timeline-tracks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 26px;
  align-items: center;
}

.track-chip {
  height: 26px;
  padding: 0 9px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--raised);
  font-size: 13px;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.track-chip.ball {
  background: var(--pill-warn-bg);
  color: var(--pill-warn-ink);
  border-color: #fde68a;
}

.track-chip.active {
  border-color: var(--accent);
  background: var(--pill-accent-bg);
  color: var(--pill-accent-ink);
}

/* ---------- Inspector Panel ---------- */
.inspector-panel {
  display: grid;
  gap: 14px;
}

.tabs {
  display: flex;
  gap: 20px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  position: relative;
  border: 0;
  background: transparent;
  padding: 6px 0 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}

.tab-btn[aria-selected="true"] {
  color: var(--text);
}

.tab-btn[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
}

.tab-pane {
  display: grid;
  gap: 12px;
}

.tab-pane[hidden] {
  display: none;
}

.field {
  display: grid;
  gap: 5px;
}

.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.input,
select.input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--control);
  border-radius: var(--radius-control);
  background: var(--surface);
  font-size: 14px;
}

.input::placeholder {
  color: var(--faint);
}

.input.compact-select {
  width: auto;
  height: var(--control-height);
  padding: 0 8px;
}

textarea.input.area {
  height: auto;
  padding: 8px 10px;
  line-height: 1.4;
  resize: vertical;
}

.inspector-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding-top: 4px;
}

.subblock {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
}

.subblock:first-child {
  border-top: 0;
  padding-top: 0;
}

.subhead {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.selected-box {
  background: var(--raised);
  border-radius: var(--radius-control);
  padding: 10px 12px;
  display: grid;
  gap: 8px;
}

.btn-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.color-label {
  font-size: 13px;
  color: var(--muted);
}

.swatches {
  display: flex;
  gap: 6px;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 2px solid var(--surface);
  outline: 1px solid var(--control);
  padding: 0;
}

.swatch[aria-pressed="true"] {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}

.compact-list {
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}

.clip-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  background: var(--raised);
  border-radius: 6px;
  font-size: 12px;
}

.clip-row-title {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clip-row-meta {
  color: var(--muted);
}

.clip-row-btns {
  display: flex;
  gap: 4px;
}

.hint {
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Buttons, Pills, Segmented ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--control-height);
  padding: 0 11px;
  border-radius: var(--radius-control);
  border: 1px solid var(--control);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 140ms ease;
}

.btn:hover {
  background: var(--raised);
}

.btn.small-btn {
  height: 30px;
  font-size: 13px;
  padding: 0 8px;
}

.btn.primary {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: transparent;
}

.btn.primary:hover {
  background: #27292d;
}

.btn.primary-outline {
  border-color: var(--text);
  color: var(--text);
  font-weight: 600;
}

.btn.rec-btn[data-active="true"] {
  background: var(--negative);
  color: #ffffff;
  border-color: transparent;
}

.btn.toggle-btn[aria-pressed="true"] {
  background: var(--active);
  border-color: var(--text);
  color: var(--text);
}

.btn.danger-outline {
  color: var(--negative);
  border-color: #f3c2c4;
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--pill-neutral-bg);
  color: var(--pill-neutral-ink);
  white-space: nowrap;
}

.pill.accent {
  background: var(--pill-accent-bg);
  color: var(--pill-accent-ink);
}

.segmented {
  display: inline-flex;
  padding: 2px;
  border-radius: 7px;
  background: var(--raised);
  border: 1px solid var(--border);
}

.segmented.full-seg {
  width: 100%;
}

.segmented.full-seg button {
  flex: 1;
}

.segmented button {
  height: 26px;
  padding: 0 9px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
}

.menu-toggle {
  display: none;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  background: var(--primary);
  color: var(--primary-ink);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
}

/* ---------- Tablet e Mobile ---------- */
@media (max-width: 1120px) {
  .builder-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 920px) {
  .workspace-frame {
    grid-template-columns: minmax(0, 1fr);
  }

  .menu-toggle {
    display: inline-flex;
    min-height: 40px;
    padding: 0 10px;
  }

  .topbar-center {
    display: none;
  }

  .sidebar {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100svh;
    z-index: 30;
    background: var(--surface);
    padding: 16px;
    transform: translateX(-105%);
    visibility: hidden;
    pointer-events: none;
    transition: transform 200ms var(--ease-out);
  }

  .sidebar.open {
    transform: none;
    visibility: visible;
    pointer-events: auto;
  }

  .sidebar-mobile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--rule);
  }

  .sidebar-title {
    font-size: 16px;
    font-weight: 600;
  }

  .schema-list {
    max-height: none;
    flex: 1;
  }

  .sheet {
    margin: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    padding: 16px;
  }
}

@media (max-width: 600px) {
  .topbar {
    padding: 0 12px;
  }

  #storage-badge {
    display: none;
  }

  .title-row {
    gap: 10px;
  }

  .title-row h1 {
    font-size: 20px;
  }

  .title-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .title-actions .btn,
  .transport-left .btn {
    min-height: 40px;
  }

  .board-toolbar {
    gap: 8px;
  }

  .panel {
    padding: 10px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }
}
