:root {
  color-scheme: light;
  --bg: #f4f4f0;
  --surface: #ffffff;
  --surface-soft: #f8f8f5;
  --surface-strong: #fff5cc;
  --ink: #241f20;
  --muted: #6f6a66;
  --line: #ded9d2;
  --line-strong: #bdb5ab;
  --brand-red: #da291c;
  --brand-red-dark: #a71812;
  --brand-yellow: #ffc72c;
  --brand-yellow-soft: rgba(255, 199, 44, 0.28);
  --danger: #b42318;
  --danger-soft: rgba(180, 35, 24, 0.12);
  --shadow: 0 18px 44px rgba(36, 31, 32, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(218, 41, 28, 0.08) 0 12px, transparent 12px 28px),
    linear-gradient(180deg, #ffffff 0, var(--bg) 420px);
  color: var(--ink);
  font-family: "Segoe UI", Arial, system-ui, sans-serif;
  line-height: 1.4;
}

body.auth-pending .login-view,
body.auth-pending .app-shell {
  visibility: hidden;
}

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

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(218, 41, 28, 0.96) 0 48%, rgba(255, 199, 44, 0.95) 48% 52%, #241f20 52%),
    var(--brand-red);
}

.login-shell {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(300px, 420px);
  align-items: stretch;
  gap: 18px;
}

.login-brand,
.login-panel,
.topbar,
.metric-card,
.entry-form,
.records-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: grid;
  align-content: end;
  min-height: 460px;
  padding: 28px;
  background:
    linear-gradient(180deg, rgba(36, 31, 32, 0) 0, rgba(36, 31, 32, 0.84) 100%),
    var(--brand-red);
  color: #fff;
  overflow: hidden;
}

.login-logo {
  width: clamp(220px, 34vw, 360px);
  height: auto;
  margin-bottom: 22px;
  border-radius: 8px;
}

.login-panel {
  display: grid;
  gap: 14px;
  padding: 24px;
  background: var(--surface);
}

.app-shell {
  width: min(1680px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  padding: 18px;
  overflow: hidden;
  background:
    linear-gradient(90deg, #ffffff 0 70%, rgba(255, 199, 44, 0.2) 70%),
    var(--surface);
}

.topbar::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 5px;
  background: linear-gradient(90deg, var(--brand-red) 0 68%, var(--brand-yellow) 68%);
}

.brand-lockup {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand-logo {
  width: clamp(150px, 16vw, 220px);
  height: auto;
  flex: 0 0 auto;
  border-radius: 8px;
}

.brand-copy {
  min-width: 0;
  padding-left: 16px;
  border-left: 1px solid var(--line-strong);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--brand-yellow);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar .eyebrow,
.metric-card span {
  color: var(--brand-red);
}

h1,
h2 {
  margin: 0;
  line-height: 1.08;
  letter-spacing: 0;
}

h1 {
  color: inherit;
  font-size: clamp(1.65rem, 2.6vw, 2.6rem);
  font-weight: 850;
}

h2 {
  font-size: 1.08rem;
  font-weight: 800;
}

.topbar-actions {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.filename-field {
  display: grid;
  gap: 4px;
  width: min(310px, 36vw);
}

.filename-field span,
.entry-form label span,
.login-panel label span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.filename-field input {
  height: 42px;
  min-height: 42px;
  font-size: 0.9rem;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  max-width: 200px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--brand-red);
  font-size: 0.82rem;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button,
.ghost-button,
.primary-button {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.15s ease,
    color 0.15s ease;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
}

.icon-button.small {
  width: 32px;
  height: 32px;
}

.icon-button svg,
.primary-button svg,
.search-box svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.icon-button:hover,
.ghost-button:hover {
  background: var(--brand-yellow-soft);
  border-color: var(--brand-yellow);
}

.icon-button:active,
.primary-button:active,
.ghost-button:active {
  transform: translateY(1px);
}

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

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card {
  min-height: 92px;
  padding: 18px;
  background: linear-gradient(135deg, #ffffff, #fffaf0);
}

.metric-card span {
  display: block;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  color: var(--ink);
  font-size: clamp(1.35rem, 2.3vw, 2rem);
  line-height: 1;
}

.work-area {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.entry-form,
.records-panel {
  background: var(--surface);
}

.entry-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
  position: sticky;
  top: 16px;
}

.form-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  gap: 12px;
}

.entry-form label,
.login-panel label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.check-row {
  grid-template-columns: 18px 1fr;
  align-items: center;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand-red);
  box-shadow: 0 0 0 3px rgba(218, 41, 28, 0.12);
}

input[readonly] {
  background: var(--surface-soft);
  color: var(--muted);
  cursor: not-allowed;
}

.primary-button {
  grid-column: 1 / -1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  background: var(--brand-red);
  border-color: var(--brand-red);
  color: #ffffff;
  font-weight: 850;
  text-transform: uppercase;
}

.primary-button:hover {
  background: var(--brand-red-dark);
  border-color: var(--brand-red-dark);
}

.ghost-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.86rem;
  font-weight: 800;
  text-transform: uppercase;
}

.records-panel {
  min-width: 0;
  overflow: hidden;
}

.records-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(160px, 220px);
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
}

.search-box input {
  min-height: 0;
  height: 100%;
  padding: 0;
  border: 0;
  box-shadow: none;
}

.table-wrap {
  position: relative;
  overflow: auto;
  min-height: 320px;
  max-height: calc(100vh - 270px);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: separate;
  border-spacing: 0;
}

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

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--brand-red);
  color: #ffffff;
  font-size: 0.82rem;
  white-space: nowrap;
}

thead th button {
  width: 100%;
  min-height: 34px;
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 850;
  text-align: inherit;
  text-transform: uppercase;
}

thead th button::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 7px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  vertical-align: middle;
}

thead th button[aria-sort="ascending"]::after {
  border-bottom: 6px solid currentColor;
}

thead th button[aria-sort="descending"]::after {
  border-top: 6px solid currentColor;
}

tbody td {
  background: #ffffff;
  font-size: 0.9rem;
}

tbody tr:hover td {
  background: #fffaf0;
}

.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.row-actions {
  display: flex;
  gap: 6px;
  min-width: 82px;
}

.actions-heading {
  width: 96px;
}

.empty-state {
  position: absolute;
  inset: 72px 0 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 850;
  pointer-events: none;
  text-transform: uppercase;
}

.empty-state[hidden] {
  display: none;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(380px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--brand-red);
  border-radius: 8px;
  background: #241f20;
  color: #ffffff;
  box-shadow: var(--shadow);
  font-weight: 800;
}

.password-dialog {
  width: min(420px, calc(100vw - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(36, 31, 32, 0.32);
}

.password-dialog::backdrop {
  background: rgba(36, 31, 32, 0.5);
}

.password-form {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.password-form label {
  display: grid;
  gap: 6px;
}

.password-form label span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.dialog-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr);
  gap: 10px;
}

.dialog-actions .primary-button {
  grid-column: auto;
}

@media (max-width: 1100px) {
  .login-shell,
  .work-area {
    grid-template-columns: 1fr;
  }

  .login-brand {
    min-height: 280px;
  }

  .entry-form {
    position: static;
  }

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

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1680px);
    padding-top: 14px;
  }

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

  .topbar-actions {
    flex-wrap: wrap;
    width: 100%;
  }

  .filename-field {
    width: min(100%, 340px);
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .records-toolbar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 540px) {
  .login-view {
    padding: 12px;
  }

  .login-brand,
  .login-panel {
    padding: 18px;
  }

  .brand-lockup {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .brand-copy {
    padding-left: 0;
    border-left: 0;
  }

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

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

  .metric-card {
    min-height: 78px;
  }
}
