:root {
  --bg: #f5f7f4;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #667085;
  --line: #d9e2dc;
  --brand: #1b6f5c;
  --brand-dark: #115044;
  --accent: #c15f3c;
  --soft: #e9f3ef;
  --warn: #8a4b12;
  --danger: #a33b3b;
  --shadow: 0 10px 28px rgba(31, 41, 51, 0.08);
}

* { box-sizing: border-box; }

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

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

button {
  border: 0;
  cursor: pointer;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card .panel-head {
  padding: 18px 18px 0;
}

.login-error {
  color: var(--danger);
  background: #fff2f2;
  border: 1px solid #f0c9c9;
  border-radius: 7px;
  padding: 10px;
  font-size: 13px;
}

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

.sidebar {
  background: #183f38;
  color: #f6fbf8;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.sidebar-footer {
  display: grid;
  gap: 8px;
}

.brand {
  display: grid;
  gap: 6px;
}

.brand h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
  font-weight: 800;
}

.brand span {
  color: #b8d8cf;
  font-size: 15px;
  font-weight: 700;
}

.brand a { text-decoration: none; color: inherit; }

.user-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.user-box label,
.field label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.user-box label {
  color: #cfe5de;
}

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

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

select:focus, input:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(27, 111, 92, 0.12);
}

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

.nav a {
  color: #d8eee8;
  background: transparent;
  text-align: left;
  border-radius: 7px;
  padding: 11px 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  text-decoration: none;
}

.nav a.active,
.nav a:hover {
  background: #226556;
  color: #fff;
}

.main {
  min-width: 0;
  padding: 24px;
  display: grid;
  gap: 20px;
  align-content: start;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.title h2 {
  margin: 0 0 4px;
  font-size: 24px;
}

.title p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  justify-content: flex-end;
}

.clock {
  min-width: 230px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 10px 14px;
  text-align: right;
}

.clock strong {
  display: block;
  font-size: 18px;
  color: var(--brand-dark);
}

.clock span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.btn {
  border-radius: 7px;
  min-height: 39px;
  padding: 9px 13px;
  color: #fff;
  background: var(--brand);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.btn:hover {
  background: var(--brand-dark);
}

.btn.secondary {
  background: #eef4f1;
  color: var(--brand-dark);
  border: 1px solid var(--line);
}

.btn.secondary:hover {
  background: #dfece7;
}

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

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
}

.finance-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
  padding: 12px 12px 0;
}

.finance-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
  padding: 12px;
}

.finance-box span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.finance-box strong {
  display: block;
  margin-top: 7px;
  font-size: 20px;
  color: var(--brand-dark);
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 15px;
  box-shadow: var(--shadow);
  min-height: 94px;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat strong {
  display: block;
  margin-top: 10px;
  font-size: 24px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel-head {
  padding: 16px 16px 0;
}

.panel-head h3 {
  margin: 0 0 4px;
  font-size: 17px;
}

.panel-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

form {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

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

.list {
  padding: 12px;
  display: grid;
  gap: 10px;
  max-height: 560px;
  overflow: auto;
}

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

.item.clickable {
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.item.clickable:hover,
.item.clickable.active {
  border-color: var(--brand);
  transform: translateY(-1px);
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(240px, 340px) minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}

.timeline {
  display: grid;
  gap: 10px;
  padding: 12px;
  max-height: 360px;
  overflow: auto;
}

.timeline-entry {
  border-left: 3px solid var(--brand);
  background: #fbfdfb;
  padding: 10px 12px;
  display: grid;
  gap: 5px;
}

.settlement-row td {
  color: var(--brand-dark);
  background: var(--soft);
}

.hidden {
  display: none !important;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

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

.item strong {
  font-size: 15px;
}

.item small,
.meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.pill {
  white-space: nowrap;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
  background: var(--soft);
  color: var(--brand-dark);
}

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

.table-wrap {
  overflow: auto;
  padding: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th, td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 11px 9px;
  font-size: 13px;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  background: #f8faf8;
  position: sticky;
  top: 0;
}

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

.notice {
  color: var(--brand-dark);
  background: var(--soft);
  border: 1px solid #c9e1d9;
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
}

.flash {
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
}

.flash.ok {
  color: var(--brand-dark);
  background: var(--soft);
  border: 1px solid #c9e1d9;
}

.flash.error {
  color: var(--danger);
  background: #fff2f2;
  border: 1px solid #f0c9c9;
}

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

  .sidebar {
    position: static;
  }

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

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

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

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

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

@media (max-width: 620px) {
  .main {
    padding: 16px;
  }

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

  .toolbar {
    justify-content: stretch;
  }

  .toolbar .btn {
    flex: 1;
  }

  .stats,
  .finance-summary,
  .row,
  .nav {
    grid-template-columns: 1fr;
  }
}
