:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #17212f;
  --muted: #627083;
  --line: #d8e0ea;
  --accent: #1267b0;
  --accent-dark: #0a4d86;
  --success: #1b7f52;
  --danger: #b42318;
  --paper: #fbfdff;
  --shadow: 0 16px 40px rgba(23, 33, 47, 0.10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

[hidden],
.screen-hidden {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

button,
.download-link {
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 7px 11px;
  color: #ffffff;
  background: var(--accent);
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.download-link:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

button:disabled,
.download-link.disabled {
  border-color: #b9c5d4;
  background: #d7dee8;
  color: #7a8796;
  cursor: not-allowed;
}

.secondary-btn {
  color: var(--ink);
  background: #ffffff;
  border-color: var(--line);
}

.secondary-btn:hover {
  color: var(--ink);
  background: #eef4fb;
  border-color: #b9c8da;
}

input,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  color: var(--ink);
  background: #ffffff;
}

label {
  display: block;
  margin: 11px 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin-bottom: 6px;
  font-size: 26px;
}

.login-panel p {
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.error-text {
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 320px minmax(0, 1fr);
}

.sidebar {
  overflow-y: auto;
  max-height: 100vh;
  border-right: 1px solid var(--line);
  padding: 14px;
  background: #eef3f9;
}

.brand-row,
.workspace-toolbar,
.dialog-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-row {
  margin-bottom: 14px;
}

.brand-row h1 {
  font-size: 22px;
}

.brand-row p,
.small-note,
#record-meta {
  color: var(--muted);
  font-size: 13px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--panel);
}

.panel h2,
.table-panel h2,
.dialog-panel h2 {
  margin-bottom: 10px;
  font-size: 15px;
}

.panel button {
  width: 100%;
  margin-top: 10px;
}

.status-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
}

.status-line span {
  color: var(--muted);
}

.status-line strong {
  min-width: 0;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.marker-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.marker-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-size: 13px;
}

.marker-toggle input {
  width: auto;
  min-height: auto;
}

.download-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.workspace {
  display: grid;
  min-width: 0;
  grid-template-rows: auto 300px auto minmax(240px, 1fr);
  gap: 12px;
  padding: 14px;
}

.workspace-toolbar {
  min-height: 58px;
}

.workspace-toolbar h2 {
  margin-bottom: 4px;
  font-size: 20px;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.waveform-panel {
  position: relative;
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper);
}

#waveform-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 260px;
  cursor: crosshair;
  touch-action: none;
}

.canvas-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  pointer-events: none;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.summary-strip div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--panel);
}

.summary-strip span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.summary-strip strong {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-grid {
  display: grid;
  min-height: 0;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: 12px;
}

.table-panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
}

.table-wrap {
  overflow: auto;
  height: calc(100% - 30px);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  border-bottom: 1px solid #e6edf5;
  padding: 7px 8px;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  color: var(--muted);
  background: #f7fafc;
  font-size: 11px;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #f3f8fd;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(520px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: #ffffff;
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 13px;
  z-index: 50;
}

dialog {
  width: min(900px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(23, 33, 47, 0.28);
}

.dialog-panel {
  padding: 14px;
}

.dialog-actions {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.dialog-actions select {
  max-width: 220px;
}

.remote-records-list {
  overflow: auto;
  max-height: 62vh;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.remote-record-row {
  display: grid;
  grid-template-columns: 1.1fr 0.7fr 0.7fr 0.7fr;
  gap: 8px;
  border-bottom: 1px solid #e6edf5;
  padding: 9px 10px;
  font-size: 12px;
}

.remote-record-row:first-child {
  color: var(--muted);
  background: #f7fafc;
  font-weight: 700;
  text-transform: uppercase;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    grid-template-rows: auto 300px auto auto;
  }

  .data-grid,
  .summary-strip {
    grid-template-columns: 1fr;
  }
}
