:root {
  color-scheme: light dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-2: #f6f9fc;
  --text: #182230;
  --muted: #66788a;
  --border: #d7e1ea;
  --border-strong: #b9c8d8;
  --primary: #2367c7;
  --primary-hover: #1c56a8;
  --primary-soft: #e7f0ff;
  --danger: #c7352f;
  --shadow: 0 18px 48px rgb(20 31 43 / 12%);
  --radius: 8px;
}

:root[data-theme="dark"] {
  --bg: #0f141b;
  --surface: #161d26;
  --surface-2: #101720;
  --text: #e8edf3;
  --muted: #9aa9b8;
  --border: #2a3542;
  --border-strong: #3b4a5c;
  --primary: #4d8df7;
  --primary-hover: #77a8ff;
  --primary-soft: #162947;
  --danger: #ff8077;
  --shadow: 0 18px 48px rgb(0 0 0 / 30%);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at top left, color-mix(in srgb, var(--primary) 14%, transparent), transparent 34rem),
    var(--bg);
}

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

button {
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  padding: 0 16px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 650;
}

button:hover {
  background: var(--primary-hover);
}

button:disabled {
  cursor: not-allowed;
  opacity: .6;
}

.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.secondary:hover {
  background: var(--primary-soft);
}

.icon-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  font-size: 28px;
  line-height: 1;
}

.icon-button:hover {
  background: var(--surface-2);
}

.hidden {
  display: none !important;
}

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

.theme-control {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 3px;
  width: max-content;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgb(15 23 42 / 8%);
}

.login-view > .theme-control {
  position: fixed;
  top: 18px;
  right: 18px;
}

.theme-option {
  min-height: 32px;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.theme-option:hover,
.theme-option.active {
  background: var(--primary-soft);
  color: var(--text);
}

.theme-option.active {
  color: var(--primary);
}

.panel,
dialog form {
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  display: grid;
  gap: 16px;
  width: min(100%, 420px);
  padding: 28px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1;
}

h2 {
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.05;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 560;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

textarea {
  min-height: 132px;
  resize: vertical;
}

.data-view {
  display: grid;
  gap: 18px;
  width: min(100%, 1440px);
  margin: 0 auto;
  padding: 24px;
}

.topbar,
.actions,
.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar p {
  color: var(--muted);
  margin-top: 5px;
  font-weight: 650;
}

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

.switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.switcher button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.switcher button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.actions {
  align-items: center;
}

.table-wrap {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgb(15 23 42 / 6%);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 13px 14px;
  text-align: left;
  vertical-align: top;
}

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

th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

td {
  color: var(--text);
}

.cell-textarea {
  width: 34%;
}

.cell-boolean {
  width: 108px;
}

td.actions-cell {
  width: 138px;
}

.cell-value {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  min-width: 0;
}

.cell-value.expanded {
  grid-template-columns: minmax(0, 1fr);
}

.cell-text {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.cell-value:not(.expanded) .cell-text {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.link-button {
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.link-button:hover {
  background: var(--primary-soft);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status-badge.active {
  background: #dcfce7;
  color: #166534;
}

.status-badge.inactive {
  background: #fee2e2;
  color: #991b1b;
}

:root[data-theme="dark"] .status-badge.active {
  background: #143a25;
  color: #86efac;
}

:root[data-theme="dark"] .status-badge.inactive {
  background: #4a1f21;
  color: #fca5a5;
}

.error {
  color: var(--danger);
  min-height: 20px;
}

.message {
  color: var(--muted);
}

dialog {
  width: min(94vw, 760px);
  border: 0;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgb(4 9 15 / 58%);
}

dialog form {
  display: grid;
  gap: 18px;
  padding: 26px;
}

.form-fields {
  display: grid;
  gap: 15px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 11px;
  width: max-content;
  max-width: 100%;
  color: var(--text);
}

.checkbox-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

@media (max-width: 820px) {
  .data-view {
    padding: 16px;
  }

  .topbar,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .theme-control,
  .topbar button,
  .actions button {
    width: 100%;
  }

  .theme-control {
    grid-template-columns: repeat(3, 1fr);
  }

  .theme-option {
    width: 100%;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }

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

  td {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 10px;
    border-bottom: 0;
    padding: 9px 14px;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
  }

  td.actions-cell {
    width: auto;
    grid-template-columns: 1fr;
  }

  td.actions-cell::before {
    display: none;
  }

  td.actions-cell button {
    width: 100%;
  }
}
