:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --ink: #1f2a27;
  --muted: #64706b;
  --line: #dfe5df;
  --primary: #256e5b;
  --primary-strong: #174b3d;
  --accent: #d28a31;
  --danger: #b43b42;
  --ok: #2f7d4e;
  --warn: #a56515;
  --shadow: 0 18px 45px rgba(31, 42, 39, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(130deg, rgba(37, 110, 91, 0.92), rgba(31, 42, 39, 0.82)),
    url("https://images.unsplash.com/photo-1562259949-e8e7689d7828?auto=format&fit=crop&w=1600&q=80") center/cover;
}

.login-panel {
  width: min(100%, 430px);
  padding: 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.login-panel h1,
.topbar h2,
.section-head h3,
.dialog-head h3 {
  margin: 0;
}

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

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

.hint {
  margin: 0;
  font-size: 13px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  color: white;
  background: #1f2a27;
}

.brand,
.user-pill,
.metric,
.meta-row,
.dialog-head,
.section-head {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark,
.user-pill span {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #1f2a27;
  font-weight: 800;
}

.brand small,
.user-pill small {
  display: block;
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.72);
}

.nav {
  display: grid;
  gap: 8px;
}

.nav button,
.ghost,
.primary,
.danger {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 700;
}

.nav button {
  text-align: left;
  color: rgba(255, 255, 255, 0.82);
  background: transparent;
}

.nav button.active,
.nav button:hover {
  color: white;
  background: rgba(255, 255, 255, 0.12);
}

.primary {
  color: white;
  background: var(--primary);
}

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

.ghost {
  color: var(--ink);
  background: #edf1ed;
}

.sidebar .ghost {
  margin-top: auto;
  color: white;
  background: rgba(255, 255, 255, 0.12);
}

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

.full {
  width: 100%;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 24px;
}

.user-pill {
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.user-pill small {
  color: var(--muted);
}

.section-head {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-head p {
  margin: 6px 0 0;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.metric {
  justify-content: space-between;
  gap: 12px;
  min-height: 92px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  min-width: 0;
  overflow-wrap: anywhere;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

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

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

.item {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.item-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.item h4 {
  margin: 0 0 4px;
  overflow-wrap: anywhere;
}

.item p {
  margin: 0;
  color: var(--muted);
}

.badge {
  flex: 0 1 auto;
  overflow-wrap: anywhere;
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--primary-strong);
  background: #e8f3ef;
  font-size: 12px;
  font-weight: 800;
}

.badge.warn {
  color: var(--warn);
  background: #fff1df;
}

.badge.danger {
  color: var(--danger);
  background: #fde8ea;
}

.badge.ok {
  color: var(--ok);
  background: #e5f4ea;
}

.meta-row {
  flex-wrap: wrap;
  gap: 8px;
}

.meta {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 9px;
  color: var(--muted);
  font-size: 12px;
}

.item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.item-actions button {
  min-height: 36px;
  padding: 8px 10px;
}

.back-btn {
  width: fit-content;
  margin-bottom: 12px;
}

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

.ledger-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

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

.ledger-table th {
  position: sticky;
  top: 0;
  color: var(--muted);
  background: #f9faf8;
  font-size: 12px;
  text-transform: uppercase;
}

.ledger-table tr:last-child td {
  border-bottom: 0;
}

.ledger-table .num {
  text-align: right;
  white-space: nowrap;
}

.ledger-table .strong {
  color: var(--primary-strong);
  font-weight: 800;
}

.compact-btn {
  min-height: 32px;
  padding: 6px 9px;
  font-size: 12px;
}

.form {
  display: grid;
  gap: 14px;
}

.stack {
  margin-top: 22px;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: white;
}

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

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

dialog {
  width: min(720px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(31, 42, 39, 0.48);
}

.dialog-form {
  padding: 18px;
}

.dialog-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: #edf1ed;
  font-weight: 900;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0;
  margin: 18px 0 0;
}

.locked {
  opacity: 0.55;
}

.checkbox-label { display: flex; align-items: center; }
.checkbox-label input { width: 20px; min-height: 20px; }
.sidebar #logoutBtn { margin-top: 0; }
.nav button { overflow-wrap: anywhere; }
.file-list { list-style: none; padding: 0; margin: 0 0 20px; }
.file-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.file-row > div { min-width: 0; }
.file-row a { color: var(--primary-strong); overflow-wrap: anywhere; }
.file-row small { display: block; color: var(--muted); margin-top: 4px; }
#uploadStatus, #filesTitle { overflow-wrap: anywhere; }
.ledger-table td:first-child { white-space: nowrap; }

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

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .sidebar .brand { grid-column: 1 / -1; }

  .nav {
    grid-column: 1 / -1;
    display: flex;
    overflow-x: auto;
    min-width: 0;
  }

  .nav button {
    text-align: center;
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .main {
    padding: 16px;
  }

  .metrics,
  .item-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar,
  .section-head,
  .item-head {
    align-items: stretch;
    flex-direction: column;
  }

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

  .two-col {
    grid-template-columns: 1fr;
  }

  .user-pill {
    width: 100%;
  }
}
