:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-subtle: #f0f5f7;
  --line: #dfe7ec;
  --line-strong: #c9d6de;
  --text: #18212b;
  --muted: #667684;
  --accent: #0f8f8c;
  --accent-strong: #0b6f84;
  --accent-soft: #e3f5f3;
  --danger: #b42318;
  --danger-soft: #fff0ed;
  --shadow: 0 14px 40px rgba(24, 33, 43, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
}

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

button {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.ghost {
  background: transparent;
}

.danger {
  border-color: #ffc9c2;
  background: var(--danger-soft);
  color: var(--danger);
}

.ghost-danger {
  background: transparent;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--text);
  padding: 0 10px;
  font-size: 13px;
}

textarea {
  min-height: 80px;
  padding: 9px 10px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  padding: 22px 16px;
}

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

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

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

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-list a {
  border-radius: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  padding: 10px 11px;
  text-decoration: none;
}

.nav-list a.active,
.nav-list a:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--line-strong);
}

.status-dot.online {
  background: var(--accent);
}

.main {
  padding: 26px;
  min-width: 0;
}

.topbar,
.section-heading,
.login-panel,
.filters,
.button-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar {
  justify-content: space-between;
  margin-bottom: 18px;
}

.topbar h1,
.section-heading h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 27px;
  line-height: 1.1;
}

.topbar p,
.section-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.login-panel {
  flex-wrap: wrap;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  box-shadow: var(--shadow);
}

.login-panel label {
  min-width: 180px;
  flex: 1;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric,
.surface {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric {
  min-height: 112px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 16px;
}

.metric span,
.metric small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.metric strong {
  font-size: 25px;
  line-height: 1.1;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.85fr);
  gap: 14px;
  align-items: start;
}

.timeline-surface {
  grid-row: span 2;
}

.surface {
  min-width: 0;
  padding: 16px;
}

.stack-surface + .stack-surface {
  margin-top: 14px;
}

.section-heading {
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-heading.compact {
  align-items: flex-start;
}

.filters {
  width: min(610px, 100%);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 11px;
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}

th {
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

th:nth-child(2),
td:nth-child(2) {
  width: 72px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 92px;
}

th:nth-child(4),
td:nth-child(4) {
  width: 88px;
}

th:nth-child(5),
td:nth-child(5) {
  width: 70px;
}

th:nth-child(6),
td:nth-child(6) {
  width: 96px;
  text-align: right;
}

td:nth-child(6) button {
  min-width: 72px;
}

.timeline-actions {
  display: grid;
  justify-content: end;
  gap: 6px;
}

.capture-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  max-width: 100%;
}

.capture-actions span {
  min-width: 86px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
}

.capture-actions button {
  min-width: 76px;
}

.sync-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.event-editor-row td {
  background: #fbfcfd;
}

.event-edit-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 6px 0;
  text-align: left;
}

.event-edit-form .wide,
.event-edit-actions {
  grid-column: 1 / -1;
}

.event-edit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.event-title {
  display: grid;
  gap: 3px;
}

.event-title strong {
  font-size: 13px;
}

.event-title span,
.muted-line,
.device-list,
.sync-ack-list,
.planner-list,
.capture-list {
  color: var(--muted);
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: var(--surface-subtle);
  color: var(--muted);
  padding: 0 8px;
  font-size: 12px;
  font-weight: 650;
}

.pill.active,
.pill.reviewed,
.pill.completed {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.pill.unprocessed {
  background: #fff7e8;
  color: #a15c00;
}

.pill.archived {
  background: #edf0f2;
  color: #586571;
}

.empty-state {
  display: none;
  margin-top: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.capture-item,
.planner-item,
.sync-ack-item,
.device-item {
  display: grid;
  gap: 5px;
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.capture-item {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
}

.device-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.sync-ack-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.device-item > div,
.sync-ack-item > div,
.muted-line {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.sync-ack-item time {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.device-item button {
  padding: 8px 10px;
}

.capture-item:last-child,
.planner-item:last-child,
.sync-ack-item:last-child,
.device-item:last-child {
  border-bottom: 0;
}

.capture-item strong,
.planner-item strong,
.sync-ack-item strong,
.device-item strong {
  color: var(--text);
  font-size: 13px;
}

.planner-form {
  display: grid;
  gap: 10px;
}

.planner-list {
  margin-top: 12px;
}

.planner-summary,
.planner-edit-form {
  display: grid;
  gap: 8px;
}

.planner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.planner-actions button {
  padding: 8px 10px;
}

.sync-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.sync-chip {
  display: grid;
  gap: 4px;
  min-height: 70px;
  align-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-subtle);
  padding: 10px;
}

.sync-chip.wide {
  grid-column: 1 / -1;
}

.sync-chip span,
.sync-chip small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.sync-chip strong {
  overflow: hidden;
  color: var(--text);
  font-size: 15px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.export-scope {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--text);
}

.export-scope input {
  width: auto;
  min-height: auto;
}

.export-summary {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-subtle);
  padding: 10px;
}

.export-summary span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.export-summary strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.privacy-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.privacy-card {
  display: grid;
  gap: 4px;
  min-height: 74px;
  align-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-subtle);
  padding: 10px;
}

.privacy-card.wide {
  grid-column: 1 / -1;
}

.privacy-card span,
.privacy-card small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.privacy-card strong {
  overflow: hidden;
  font-size: 15px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
  margin-top: 14px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(460px, calc(100vw - 36px));
  transform: translateY(12px);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  padding: 12px 14px;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.legal-page {
  max-width: 920px;
  margin: 0 auto;
}

.legal-topbar {
  align-items: flex-start;
}

.legal-copy {
  display: grid;
  gap: 14px;
  line-height: 1.7;
}

.legal-copy h2 {
  margin-top: 8px;
}

.legal-copy p {
  color: var(--muted);
  margin: 0;
}

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

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }

  .nav-list {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
  }

  .sidebar-footer {
    margin-top: 0;
    margin-left: auto;
  }

  .metric-grid,
  .bottom-grid,
  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .main {
    padding: 18px;
  }

  .topbar,
  .section-heading,
  .capture-actions,
  .sync-actions,
  .filters,
  .button-row {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .capture-actions,
  .sync-actions,
  .button-row {
    width: 100%;
  }

  .topbar-actions button,
  .capture-actions button,
  .sync-actions button,
  .button-row button {
    flex: 1;
  }

  .capture-actions span {
    min-width: 0;
    text-align: left;
  }

  .event-edit-form {
    grid-template-columns: 1fr;
    max-width: calc(100vw - 72px);
  }

  .privacy-summary {
    grid-template-columns: 1fr;
  }

  .event-editor-row td {
    left: 0;
    position: sticky;
    z-index: 1;
  }
}
