:root {
  color-scheme: light;
  --ink: #111820;
  --ink-2: #26313c;
  --paper: #f7f4ee;
  --surface: #fffdf8;
  --line: #ded6c9;
  --muted: #6d746f;
  --gold: #b8863b;
  --wine: #7a1f2b;
  --sage: #3f665d;
  --blue: #31465f;
  --shadow: 0 18px 55px rgba(17, 24, 32, 0.14);
  --radius: 8px;
  --focus: 0 0 0 3px rgba(184, 134, 59, 0.28);
  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;
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(122, 31, 43, 0.08), transparent 28%),
    linear-gradient(300deg, rgba(63, 102, 93, 0.1), transparent 32%),
    var(--paper);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffefa;
  color: var(--ink);
  padding: 0.72rem 0.78rem;
  outline: none;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

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

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--gold);
  box-shadow: var(--focus);
  outline: none;
}

label {
  display: grid;
  gap: 0.38rem;
  color: var(--ink-2);
  font-size: 0.84rem;
  font-weight: 700;
}

.boot-screen,
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.boot-screen {
  gap: 1rem;
  align-content: center;
  color: var(--muted);
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 1px solid rgba(184, 134, 59, 0.55);
  border-radius: 50%;
  color: var(--gold);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45rem;
  font-weight: 700;
}

.auth-panel {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 0.88fr 1.12fr;
  overflow: hidden;
  border: 1px solid rgba(222, 214, 201, 0.95);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-brand {
  min-height: 620px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 2rem;
  background:
    linear-gradient(145deg, rgba(17, 24, 32, 0.88), rgba(17, 24, 32, 0.97)),
    radial-gradient(circle at top left, rgba(184, 134, 59, 0.32), transparent 36%);
  color: #fbf8f0;
}

.auth-brand h1,
.sidebar h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 5vw, 3.6rem);
  font-weight: 500;
}

.auth-brand p {
  max-width: 28rem;
  color: rgba(251, 248, 240, 0.74);
  line-height: 1.7;
}

.auth-copy {
  display: grid;
  gap: 1rem;
}

.auth-copy .brand-mark {
  border-color: rgba(184, 134, 59, 0.85);
}

.auth-form {
  padding: clamp(1.2rem, 4vw, 2.4rem);
}

.auth-tabs,
.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 0.25rem;
  padding: 0.28rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f0ebe2;
}

.auth-tabs button,
.segmented button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0.6rem 0.9rem;
  font-weight: 800;
}

.auth-tabs button.active,
.segmented button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 6px rgba(17, 24, 32, 0.08);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.form-grid .span-2,
.span-2 {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.7rem;
  margin-top: 1rem;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
  padding: 1.4rem;
  background: #111820;
  color: #fbf8f0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.sidebar h1 {
  font-size: 1.7rem;
}

.nav-list {
  display: grid;
  gap: 0.35rem;
}

.nav-list button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: rgba(251, 248, 240, 0.78);
  padding: 0.82rem 0.9rem;
  text-align: left;
  font-weight: 800;
}

.nav-list button.active,
.nav-list button:hover {
  border-color: rgba(184, 134, 59, 0.42);
  background: rgba(255, 253, 248, 0.08);
  color: #fffdf8;
}

.sidebar-footer {
  margin-top: auto;
  color: rgba(251, 248, 240, 0.66);
  font-size: 0.8rem;
  line-height: 1.5;
}

.main {
  min-width: 0;
  padding: clamp(1rem, 2.8vw, 2rem);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.2rem;
}

.topbar h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 500;
}

.topbar-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.8rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.page-stack {
  display: grid;
  gap: 1rem;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.88);
  box-shadow: 0 8px 28px rgba(17, 24, 32, 0.07);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0;
}

.panel-header h3 {
  margin: 0;
  font-size: 1rem;
}

.entry-form,
.settings-form {
  padding: 1rem;
}

.entry-form {
  display: grid;
  grid-template-columns:
    minmax(220px, 1.3fr)
    minmax(120px, 0.6fr)
    minmax(140px, 0.8fr)
    minmax(180px, 0.9fr)
    minmax(150px, 0.8fr)
    auto;
  align-items: end;
  gap: 0.75rem;
}

.entry-form.delegated {
  grid-template-columns:
    minmax(220px, 1.1fr)
    minmax(170px, 0.8fr)
    minmax(220px, 0.95fr)
    minmax(180px, 1fr);
}

.entry-form.delegated .wide-row {
  grid-column: 1 / -1;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-top: 1px solid rgba(222, 214, 201, 0.75);
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  border-top: 1px solid rgba(222, 214, 201, 0.75);
  padding: 0.82rem 0.9rem;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
}

.data-table th button {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font: inherit;
  font-weight: 900;
  text-transform: inherit;
}

.data-table tbody tr:hover {
  background: rgba(184, 134, 59, 0.07);
}

.empty-state {
  padding: 2rem 1rem;
  color: var(--muted);
  text-align: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  border: 1px solid rgba(17, 24, 32, 0.12);
  border-radius: 999px;
  background: #fffefa;
  color: var(--ink-2);
  padding: 0.18rem 0.62rem;
  font-size: 0.78rem;
  font-weight: 850;
}

.pill.critical {
  background: rgba(122, 31, 43, 0.12);
  color: var(--wine);
}

.pill.high {
  background: rgba(184, 134, 59, 0.14);
  color: #815d24;
}

.pill.standard {
  background: rgba(49, 70, 95, 0.1);
  color: var(--blue);
}

.pill.low {
  background: rgba(63, 102, 93, 0.12);
  color: var(--sage);
}

.life-area {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
}

.swatch {
  width: 0.72rem;
  height: 0.72rem;
  border: 1px solid rgba(17, 24, 32, 0.15);
  border-radius: 50%;
  background: var(--swatch, var(--gold));
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.38rem;
}

.btn,
.icon-btn,
.text-btn,
.danger-btn {
  min-height: 2.55rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffefa;
  color: var(--ink);
  padding: 0.68rem 0.86rem;
  font-weight: 850;
}

.btn.primary {
  border-color: #111820;
  background: #111820;
  color: #fffdf8;
}

.btn.gold {
  border-color: #9f7432;
  background: var(--gold);
  color: #fffdf8;
}

.icon-btn {
  width: 2.55rem;
  padding: 0;
  font-size: 1.08rem;
}

.text-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2rem;
  padding: 0.42rem 0.58rem;
  font-size: 0.8rem;
  line-height: 1.1;
  white-space: nowrap;
}

.danger-btn {
  border-color: rgba(122, 31, 43, 0.28);
  color: var(--wine);
}

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

.fine-print {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
}

.life-list {
  display: grid;
  gap: 0.55rem;
  padding: 1rem;
}

.life-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.8rem;
  border: 1px solid rgba(222, 214, 201, 0.78);
  border-radius: var(--radius);
  background: #fffefa;
  padding: 0.72rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(17, 24, 32, 0.5);
}

.modal {
  width: min(760px, 100%);
  max-height: min(88vh, 820px);
  overflow: auto;
  border: 1px solid rgba(222, 214, 201, 0.9);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.86rem 1rem;
  border-bottom: 1px solid var(--line);
}

.modal-header h3 {
  margin: 0;
}

.modal .settings-form {
  padding: 0.86rem 1rem 0.9rem;
}

.modal .form-grid {
  gap: 0.72rem;
}

.modal input,
.modal select,
.modal textarea {
  padding: 0.62rem 0.7rem;
}

.modal textarea {
  min-height: 72px;
}

.modal .form-actions {
  margin-top: 0.72rem;
}

.hidden {
  display: none !important;
}

#toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 40;
  display: grid;
  gap: 0.5rem;
}

.toast {
  width: min(380px, calc(100vw - 2rem));
  border: 1px solid rgba(17, 24, 32, 0.14);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius);
  background: #fffdf8;
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 0.9rem 1rem;
}

.toast.error {
  border-left-color: var(--wine);
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .entry-form,
  .entry-form.delegated,
  .settings-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .auth-screen {
    padding: 0;
  }

  .auth-panel {
    min-height: 100vh;
    grid-template-columns: 1fr;
    border: 0;
    border-radius: 0;
  }

  .auth-brand {
    min-height: auto;
    gap: 2rem;
  }

  .topbar,
  .panel-header,
  .search-row {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    display: grid;
  }

  .topbar-meta {
    justify-content: flex-start;
  }

  .nav-list,
  .entry-form,
  .entry-form.delegated,
  .settings-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .data-table {
    min-width: 920px;
  }
}
