:root {
  color-scheme: light;
  --bg: #f4efe7;
  --bg-accent: #f7f1e6;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #ffffff;
  --text: #1f1a17;
  --muted: #6a5e56;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #d9f0eb;
  --border: #d9cfc2;
  --border-strong: #cdbdaa;
  --danger: #b42318;
  --danger-bg: #fde7e7;
  --danger-text: #8a1c1c;
  --success-bg: #e6f6f2;
  --success-text: #155e55;
  --success-border: #94d2c4;
  --shadow: 0 24px 60px rgba(58, 39, 23, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  background:
    radial-gradient(circle at top left, #fff6de, transparent 28%),
    radial-gradient(circle at top right, rgba(15, 118, 110, 0.08), transparent 22%),
    linear-gradient(180deg, var(--bg-accent) 0%, var(--bg) 30%, #f8f3eb 100%);
  color: var(--text);
}

.shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 1rem 0;
  border-bottom: 1px solid rgba(217, 207, 194, 0.85);
  background: rgba(244, 239, 231, 0.82);
  backdrop-filter: blur(14px);
}

.site-header .shell {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.25rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.site-nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.98rem;
  padding: 0.65rem 0.9rem;
  border-radius: 999px;
  transition: background 120ms ease, color 120ms ease;
}

.site-nav a:hover {
  background: rgba(255, 255, 255, 0.75);
  color: var(--text);
}

.brand {
  color: var(--text);
  text-decoration: none;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

main.shell {
  padding: 2rem 0 3.5rem;
}

.panel,
.auth-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1.6rem;
  box-shadow: var(--shadow);
}

.auth-panel {
  max-width: 460px;
  margin: 4rem auto 0;
}

.stack-section {
  margin-bottom: 1.25rem;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.stack {
  display: grid;
  gap: 0.9rem;
}

h1,
h2 {
  margin: 0;
  letter-spacing: -0.04em;
}

h1 {
  font-size: clamp(1.7rem, 2.4vw, 2.05rem);
  font-weight: 800;
}

h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

p {
  margin: 0;
  font-size: 0.98rem;
}

code,
.config-line {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.89rem;
}

label {
  font-weight: 600;
  color: #1e293b;
  font-size: 0.95rem;
}

input,
select,
textarea,
button,
.button-link {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  padding: 0.82rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-solid);
  color: var(--text);
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #7bc7bc;
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
}

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

button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.96rem;
}

button {
  border: 0;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.button-link {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

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

.secondary-button {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.secondary-button:hover {
  background: #f7f2ea;
}

.danger-button {
  background: var(--danger);
}

.danger-button:hover {
  background: #b91c1c;
}

.flash-stack {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.flash {
  padding: 0.9rem 1rem;
  border-radius: 14px;
  border: 1px solid transparent;
  font-weight: 500;
}

.flash-error {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-color: #efb2b2;
}

.flash-success {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: var(--success-border);
}

.section-heading p {
  margin: 0.45rem 0 0;
  color: var(--muted);
  max-width: 62ch;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.table-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel-solid);
}

input[type="checkbox"] {
  width: 1.2rem;
  height: 1.2rem;
  accent-color: var(--accent);
  cursor: pointer;
}

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

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

thead th {
  border-top: 0;
  background: #f9f4ec;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody tr:hover {
  background: #fcf8f2;
}

.config-line {
  white-space: pre-wrap;
  word-break: break-all;
}

.status-pill {
  display: inline-block;
  padding: 0.32rem 0.62rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.status-pill.active {
  background: #d7f4ee;
  color: #0f5f58;
}

.status-pill.deleted {
  background: #efe2d3;
  color: #785b2d;
}

.row-deleted {
  opacity: 0.68;
}

.readonly-input {
  background: #f7f2ea;
  color: var(--muted);
}

.table-link {
  color: var(--accent-dark);
  font-weight: 600;
  text-decoration: none;
}

.table-link:hover {
  color: var(--accent);
}

.subpanel {
  margin-top: 0.35rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.card-tight {
  gap: 0.8rem;
}

.checkbox-list {
  display: grid;
  gap: 0.75rem;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 250, 243, 0.92);
}

.checkbox-row input[type="checkbox"] {
  flex: 0 0 auto;
  margin-top: 0.2rem;
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

.checkbox-hit-area {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f7f2ea;
  cursor: pointer;
}

.checkbox-hit-area:hover {
  border-color: #7bc7bc;
  background: #e9f6f3;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #f7f2ea;
}

.toggle-row input[type="checkbox"] {
  margin: 0;
}

.user-edit-layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.compact-code-input {
  min-height: 78px;
  resize: none;
  font-size: 0.87rem;
  line-height: 1.45;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.compact-checkbox-list {
  max-height: 620px;
}

.compact-checkbox-row {
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.85rem;
}

.compact-checkbox-row input[type="checkbox"] {
  margin: 0;
}

.config-item-body {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
  flex: 1 1 auto;
}

.config-item-id {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.config-item-state {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 500;
}

.compact-config-line {
  font-size: 0.82rem;
  line-height: 1.45;
}

.checkbox-decision {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f7f2ea;
  white-space: nowrap;
  flex: 0 0 auto;
}

.checkbox-decision span {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.1rem;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.row-actions form {
  margin: 0;
}

.icon-button {
  min-width: 44px;
  padding: 0;
}

.icon-button svg {
  width: 1rem;
  height: 1rem;
  fill: currentColor;
}

.filter-form {
  display: grid;
  gap: 0.9rem;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.9rem;
}

.filter-grid > div {
  display: grid;
  gap: 0.45rem;
}

.filter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

@media (max-width: 860px) {
  .site-header .shell,
  .header-actions,
  .section-heading,
  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .site-nav {
    width: 100%;
  }

  .table-actions {
    justify-content: stretch;
  }

  .table-actions > * {
    width: 100%;
  }

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

  .compact-checkbox-row {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100% - 1rem, 100%);
  }

  main.shell {
    padding-top: 1.25rem;
  }

  .panel,
  .auth-panel {
    padding: 1.15rem;
    border-radius: 16px;
  }

  th,
  td {
    padding: 0.8rem 0.75rem;
  }
}
