:root {
  color-scheme: dark;
  --ink: #e7f2f4;
  --muted: #8ea3aa;
  --line: #1f3b46;
  --bg: #071015;
  --bg-layer: radial-gradient(circle at 12% 0%, rgba(32, 199, 181, 0.10), transparent 28%),
    linear-gradient(135deg, #071015 0%, #0a151c 48%, #0c1118 100%);
  --panel: #0e1a21;
  --panel-2: #12242d;
  --field-bg: #071319;
  --header-bg: rgba(8, 18, 24, 0.92);
  --table-head: #12242d;
  --table-head-text: #aeeef3;
  --accent: #20c7b5;
  --accent-dark: #17a596;
  --accent-2: #66e3ff;
  --button-secondary: #263f49;
  --button-secondary-text: #d6eef2;
  --hover-row: rgba(32, 199, 181, 0.10);
  --shadow: rgba(0, 0, 0, 0.32);
  --green: #27e19a;
  --blue: #66e3ff;
  --yellow: #ffb84d;
  --orange: #ff9a56;
  --red: #ff5b6b;
  --gray: #8ea3aa;
  --radius: 6px;
  --control-height: 28px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --ink: #10232a;
  --muted: #51666e;
  --line: #c8dce1;
  --bg: #eef5f6;
  --bg-layer: linear-gradient(135deg, #f8fcfd 0%, #eef6f7 46%, #e7f0f2 100%);
  --panel: #ffffff;
  --panel-2: #eef7f8;
  --field-bg: #ffffff;
  --header-bg: rgba(247, 252, 253, 0.94);
  --table-head: #e6f4f6;
  --table-head-text: #123943;
  --accent: #079786;
  --accent-dark: #087d71;
  --accent-2: #0f7ea3;
  --button-secondary: #d7e8ec;
  --button-secondary-text: #183038;
  --hover-row: rgba(7, 151, 134, 0.10);
  --shadow: rgba(16, 35, 42, 0.12);
  --green: #17803d;
  --blue: #0f7ea3;
  --yellow: #b77400;
  --orange: #d15c0b;
  --red: #d8344a;
  --gray: #64748b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--bg-layer);
  font-family: "Segoe UI", Arial, sans-serif;
}

body.locked .topbar,
body.locked main {
  display: none;
}

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

body.locked .login-view {
  display: grid;
}

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

.login-box label {
  display: block;
  margin-top: 14px;
}

.login-box button {
  width: 100%;
  margin-top: 14px;
}

.hint,
.error-text {
  font-size: 13px;
}

.hint {
  margin: 12px 0 0;
  color: var(--muted);
}

.error-text {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--red);
}

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

button {
  align-items: center;
  display: inline-flex;
  justify-content: center;
  min-height: var(--control-height);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 9px;
  color: var(--button-secondary-text);
  background: var(--button-secondary);
  cursor: pointer;
  font-weight: 600;
  line-height: 1.1;
  white-space: nowrap;
}

button:hover {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(102, 227, 255, 0.12);
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #041317;
}

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

button.danger {
  border-color: rgba(255, 91, 107, 0.6);
  color: #ffffff;
  background: var(--red);
}

button.small {
  min-height: 28px;
  padding: 4px 10px;
  font-size: 12px;
}

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

.dropdown-host {
  position: relative;
}

.custom-dropdown {
  position: absolute;
  z-index: 50;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 14px 28px var(--shadow);
}

.custom-dropdown-row {
  display: flex;
  align-items: stretch;
  width: 100%;
  min-height: 32px;
}

.custom-dropdown-row + .custom-dropdown-row {
  border-top: 1px solid var(--line);
}

.custom-dropdown-value {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border: 0;
  border-radius: 0;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
}

.custom-dropdown-remove {
  width: 34px;
  min-height: 32px;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  color: var(--red);
  background: var(--panel);
  font-size: 18px;
  line-height: 1;
}

.custom-dropdown-value:hover,
.custom-dropdown-remove:hover {
  background: var(--hover-row);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 8px 16px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 12px;
}

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

h1 {
  margin-bottom: 0;
  font-size: 20px;
  font-weight: 650;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  align-items: center;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-height);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  font-size: 12px;
}

.mini-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--control-height);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.mini-toggle input {
  width: 14px;
  min-height: 14px;
  margin: 0;
  accent-color: var(--accent);
}

main {
  padding: 14px 16px 30px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 10px 24px var(--shadow);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.toolbar {
  display: grid;
  grid-template-columns: 1.5fr repeat(7, minmax(120px, 1fr)) repeat(4, auto);
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}

input,
select,
textarea {
  width: 100%;
  min-height: var(--control-height);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 8px;
  background: var(--field-bg);
  color: var(--ink);
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
}

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

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 16px;
}

.table-panel,
.details {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 24px var(--shadow);
  min-width: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.section-head h2 {
  margin: 0;
}

.section-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 295px);
}

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

th,
td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 12px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--table-head);
  color: var(--table-head-text);
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 600;
}

tr {
  cursor: pointer;
}

tr:hover,
tr.selected {
  background: var(--hover-row);
}

tr.signal-red {
  background: rgba(255, 91, 107, 0.12);
}

tr.signal-yellow {
  background: rgba(255, 184, 77, 0.12);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid currentColor;
}

.badge.green,
.badge.light-green {
  color: #bfffe6;
  background: rgba(39, 225, 154, 0.16);
}

.badge.blue {
  color: #bdf4ff;
  background: rgba(102, 227, 255, 0.16);
}

.badge.yellow {
  color: #ffe0a6;
  background: rgba(255, 184, 77, 0.18);
}

.badge.orange {
  color: #ffd0b0;
  background: rgba(255, 154, 86, 0.18);
}

.badge.red {
  color: #ffd6dc;
  background: rgba(255, 91, 107, 0.20);
}

.badge.gray {
  color: #d9e6e9;
  background: rgba(142, 163, 170, 0.18);
}

:root[data-theme="light"] .badge.green,
:root[data-theme="light"] .badge.light-green {
  color: #075e3a;
  background: #d1fae5;
}

:root[data-theme="light"] .badge.blue {
  color: #075985;
  background: #dbeafe;
}

:root[data-theme="light"] .badge.yellow {
  color: #7a5200;
  background: #fef3c7;
}

:root[data-theme="light"] .badge.orange {
  color: #9a3412;
  background: #ffedd5;
}

:root[data-theme="light"] .badge.red {
  color: #991b1b;
  background: #fee2e2;
}

:root[data-theme="light"] .badge.gray {
  color: #334155;
  background: #e2e8f0;
}

.details {
  padding: 16px;
  max-height: calc(100vh - 215px);
  overflow: auto;
}

.empty {
  color: var(--muted);
  display: grid;
  min-height: 160px;
  place-items: center;
}

.kv {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 6px 12px;
  margin: 14px 0;
  font-size: 14px;
}

.kv span:nth-child(odd) {
  color: var(--muted);
}

.history {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.history-item {
  border-left: 3px solid var(--accent);
  padding: 8px 0 8px 10px;
  background: var(--panel-2);
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-item strong {
  display: block;
}

.history-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

dialog {
  width: min(980px, calc(100vw - 30px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 24px 60px var(--shadow);
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.55);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  margin: 0;
}

.icon {
  width: 30px;
  min-height: 30px;
  padding: 0;
  font-size: 18px;
}

.refresh-btn {
  font-size: 17px;
  line-height: 1;
}

.theme-toggle-btn {
  font-size: 15px;
  line-height: 1;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 18px;
  max-height: 70vh;
  overflow: auto;
}

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

label > input,
label > select,
label > textarea {
  margin-top: 5px;
}

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

.users-layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 14px;
  padding: 18px;
}

.users-list {
  display: grid;
  gap: 8px;
  max-height: 56vh;
  overflow: auto;
}

.user-row {
  width: 100%;
  min-height: auto;
  padding: 10px;
  text-align: left;
}

.user-row strong,
.user-row span {
  display: block;
}

.user-row span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.user-row.inactive {
  opacity: 0.55;
}

.user-editor {
  padding: 0;
  max-height: 56vh;
}

.photo-preview {
  min-height: 120px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  padding: 8px;
  color: var(--muted);
  background: var(--field-bg);
  font-size: 13px;
}

.photo-preview img,
.history-photo {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

.photo-preview img {
  max-height: 160px;
}

.history-photo {
  margin-top: 8px;
  max-height: 220px;
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 18px;
  margin: 0;
  border-top: 1px solid var(--line);
}

@media (max-width: 1180px) {
  .toolbar {
    grid-template-columns: repeat(4, minmax(130px, 1fr));
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .details {
    max-height: none;
  }
}

@media (max-width: 760px) {
  .topbar {
    display: block;
    padding: 18px;
  }

  .actions {
    justify-content: flex-start;
    margin-top: 14px;
  }

  main {
    padding: 14px;
  }

  .stats,
  .toolbar,
  .form-grid,
  .users-layout {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    max-height: none;
  }
}

@media print {
  .topbar .actions,
  .toolbar,
  dialog {
    display: none !important;
  }

  body {
    background: #fff;
  }

  main,
  .topbar {
    padding: 0;
  }

  .layout {
    display: block;
  }

  .details {
    margin-top: 14px;
  }
}
