:root {
  --ink: #111827;
  --muted: #64748b;
  --line: #d9e2ef;
  --panel: #ffffff;
  --back: #f4f7fb;
  --blue: #064c99;
  --navy: #073763;
  --cyan: #13a8d8;
  --green: #12805c;
  --amber: #b36b00;
  --red: #b42318;
  --shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 268px 1fr;
  color: var(--ink);
  background: var(--back);
  font-family: Inter, Segoe UI, Arial, sans-serif;
}

body.locked {
  display: block;
  overflow: hidden;
}

body.locked .sidebar,
body.locked .app-shell {
  display: none;
}

body.unlocked .login-screen {
  display: none;
}

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

button {
  cursor: pointer;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(6, 76, 153, 0.10), rgba(19, 168, 216, 0.12)),
    #f7fbff;
}

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

.login-brand,
.login-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-brand {
  min-height: 360px;
  display: grid;
  place-items: center;
  padding: 28px;
  position: relative;
  overflow: hidden;
}

.login-brand img {
  max-width: 92%;
  height: auto;
  animation: brandPulse 2.6s ease-in-out infinite;
}

.signal-loader {
  position: absolute;
  left: 36px;
  right: 36px;
  bottom: 34px;
  height: 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.signal-loader span {
  border-radius: 999px;
  background: var(--cyan);
  transform-origin: left center;
  animation: signalRun 1.1s ease-in-out infinite;
}

.signal-loader span:nth-child(2) {
  animation-delay: 0.12s;
  background: var(--blue);
}

.signal-loader span:nth-child(3) {
  animation-delay: 0.24s;
}

.signal-loader span:nth-child(4) {
  animation-delay: 0.36s;
  background: var(--blue);
}

.login-card {
  display: grid;
  gap: 14px;
  padding: 26px;
}

.login-card h1 {
  margin-bottom: 6px;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-weight: 700;
}

.loading .login-card {
  pointer-events: none;
  opacity: 0.74;
}

@keyframes brandPulse {
  0%,
  100% {
    transform: translateY(0) scale(1);
    filter: drop-shadow(0 10px 18px rgba(6, 76, 153, 0.08));
  }
  50% {
    transform: translateY(-4px) scale(1.015);
    filter: drop-shadow(0 18px 24px rgba(6, 76, 153, 0.15));
  }
}

@keyframes signalRun {
  0%,
  100% {
    opacity: 0.35;
    transform: scaleX(0.45);
  }
  50% {
    opacity: 1;
    transform: scaleX(1);
  }
}

.sidebar {
  min-height: 100vh;
  background: #ffffff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
}

.brand {
  padding: 22px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.brand img {
  display: block;
  max-width: 100%;
  height: auto;
}

.nav {
  display: grid;
  gap: 6px;
  padding: 18px 12px;
}

.nav-item,
.ghost-btn,
.primary-btn,
.danger-btn,
.icon-btn {
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 38px;
}

.nav-item {
  text-align: left;
  color: var(--muted);
  background: transparent;
  padding: 10px 12px;
}

.nav-item.active,
.nav-item:hover {
  color: var(--blue);
  background: #eaf3ff;
  border-color: #c7defa;
}

.sidebar-foot {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding: 14px 12px 18px;
  border-top: 1px solid var(--line);
}

#importDataInput {
  display: none;
}

.app-shell {
  min-width: 0;
}

.topbar {
  min-height: 96px;
  padding: 20px 26px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 3;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 0;
  font-size: 28px;
}

h2 {
  margin-bottom: 14px;
  font-size: 21px;
}

h3 {
  margin-bottom: 8px;
  font-size: 16px;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  background: #ffffff;
  color: var(--ink);
}

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

#globalSearch {
  width: 320px;
}

.view {
  display: none;
  padding: 24px 26px 42px;
}

.active-view {
  display: block;
}

.grid {
  display: grid;
  gap: 16px;
}

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

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

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

.panel,
.metric,
.record-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.metric {
  padding: 16px;
}

.metric .value {
  margin: 4px 0 0;
  font-size: 28px;
  font-weight: 800;
}

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

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.toolbar .filters {
  display: flex;
  gap: 8px;
  align-items: center;
}

.primary-btn {
  color: #ffffff;
  background: var(--blue);
  border-color: var(--blue);
  padding: 9px 14px;
  font-weight: 700;
}

.primary-btn:hover {
  background: var(--navy);
}

.ghost-btn {
  color: var(--blue);
  background: #ffffff;
  border-color: var(--line);
  padding: 9px 12px;
  text-align: center;
}

.danger-btn {
  color: #ffffff;
  background: var(--red);
  border-color: var(--red);
  padding: 8px 11px;
}

.icon-btn {
  width: 34px;
  color: var(--muted);
  background: #ffffff;
  border-color: var(--line);
}

.record-list {
  display: grid;
  gap: 12px;
}

.record-card {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.record-row,
.split-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
  background: #eef2f7;
  color: #334155;
}

.pill.good {
  background: #e7f7ef;
  color: var(--green);
}

.pill.warn {
  background: #fff5df;
  color: var(--amber);
}

.pill.bad {
  background: #fff0ee;
  color: var(--red);
}

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

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

.mini-table th {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0;
}

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

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

.check-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.check-item {
  display: flex;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
}

.check-item input {
  width: auto;
}

dialog {
  width: min(860px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.modal-card {
  padding: 0;
}

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

.modal-head h2 {
  margin: 0;
}

#modalBody {
  max-height: min(68vh, 720px);
  overflow: auto;
  padding: 18px;
}

.modal-actions {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  justify-content: flex-end;
}

.invoice-lines {
  display: grid;
  gap: 8px;
}

.invoice-line {
  display: grid;
  grid-template-columns: 1.8fr 0.7fr 0.8fr 40px;
  gap: 8px;
  align-items: center;
}

.empty {
  padding: 26px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #ffffff;
}

@media (max-width: 980px) {
  body {
    grid-template-columns: 1fr;
  }

  .login-shell {
    grid-template-columns: 1fr;
  }

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

  .sidebar {
    min-height: 0;
    position: static;
  }

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

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

  #globalSearch {
    width: 100%;
  }

  .grid.cols-2,
  .grid.cols-3,
  .grid.cols-4,
  .form-grid,
  .check-grid {
    grid-template-columns: 1fr;
  }

  .invoice-line {
    grid-template-columns: 1fr;
  }
}
