:root {
  --brand: #0f6a5f;
  --brand-dark: #093f39;
  --brand-soft: #e8f4ef;
  --brand-2: #e5b64b;
  --ink: #14211f;
  --muted: #6b7773;
  --line: #dde7e2;
  --surface: #ffffff;
  --bg: #f4f7f5;
  --danger: #b42318;
  --warn: #a15c07;
  --ok: #157347;
  --shadow: 0 20px 60px rgba(20, 33, 31, .10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); color: var(--ink); }
body { min-height: 100vh; margin: 0; background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; }
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(180deg, rgba(15, 106, 95, .08), rgba(229, 182, 75, .08) 34%, transparent 72%),
    var(--bg);
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(18, 92, 84, .94), rgba(42, 82, 69, .72)),
    url("../logo.png") center/280px no-repeat,
    var(--brand);
}

.login-card {
  width: min(420px, 100%);
  background: rgba(255, 255, 255, .96);
  border: 1px solid rgba(255, 255, 255, .65);
  border-radius: 8px;
  padding: 34px;
  box-shadow: var(--shadow);
}
.login-card img { width: 116px; height: 84px; object-fit: contain; }
.login-card h1 { margin: 14px 0 6px; font-size: 34px; }
.login-card p { margin: 0 0 24px; color: var(--muted); line-height: 1.5; }

.app-shell { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .08), transparent 28%),
    var(--brand-dark);
  color: white;
  box-shadow: 18px 0 50px rgba(9, 63, 57, .14);
}
.brand { display: flex; align-items: center; gap: 14px; color: white; font-weight: 900; font-size: 24px; margin-bottom: 28px; min-height: 76px; }
.brand img { width: 92px; height: 66px; object-fit: contain; background: white; border-radius: 8px; padding: 7px; box-shadow: 0 12px 26px rgba(0,0,0,.18); }
.sidebar nav { display: grid; gap: 8px; }
.sidebar nav a {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: rgba(255, 255, 255, .82);
  border-radius: 8px;
  padding: 11px 13px;
  font-weight: 700;
}
.sidebar nav a.active, .sidebar nav a:hover { background: rgba(255, 255, 255, .13); color: white; box-shadow: inset 3px 0 0 var(--brand-2); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.user-mini { margin-top: auto; padding: 16px; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.08); border-radius: 8px; display: grid; gap: 5px; }
.user-mini span { color: rgba(255,255,255,.68); font-size: 12px; }
.user-mini a { color: white; font-weight: 700; margin-top: 8px; }

.main { min-width: 0; padding: 24px clamp(16px, 3vw, 38px) 42px; }
.topbar { display: flex; align-items: center; gap: 16px; justify-content: space-between; margin-bottom: 24px; padding: 14px 16px; background: rgba(255,255,255,.76); border: 1px solid rgba(221,231,226,.82); border-radius: 8px; backdrop-filter: blur(14px); }
.topbar div { margin-right: auto; }
.topbar p { margin: 0 0 4px; color: var(--muted); font-size: 13px; }
.topbar h1 { margin: 0; font-size: clamp(24px, 3vw, 34px); letter-spacing: 0; }
.icon-btn { display: none; width: 42px; height: 42px; place-items: center; border: 1px solid var(--line); background: white; border-radius: 8px; color: var(--ink); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.metric-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.metric, .panel, .hero-balance {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 36px rgba(20, 33, 31, .06);
}
.metric { padding: 20px; display: grid; gap: 8px; min-height: 116px; align-content: center; border-top: 4px solid var(--brand-2); }
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { font-size: clamp(22px, 2vw, 30px); overflow-wrap: anywhere; }

.hero-balance {
  padding: clamp(22px, 4vw, 38px);
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand) 64%, var(--brand-2));
  color: white;
}
.hero-balance.is-minus { background: linear-gradient(135deg, #7f1d1d, #b45309); }
.hero-balance span { display: block; opacity: .82; margin-bottom: 8px; }
.hero-balance strong { display: block; font-size: clamp(34px, 7vw, 62px); margin-bottom: 22px; overflow-wrap: anywhere; }
.hero-balance div { display: flex; gap: 10px; flex-wrap: wrap; }
.hero-balance .ghost { background: rgba(255,255,255,.16); color: white; border-color: rgba(255,255,255,.32); }

.panel { padding: 20px; margin-bottom: 16px; }
.panel.narrow { max-width: 880px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.panel h2, .panel h3 { margin: 0 0 14px; }
.panel h2 { font-size: 20px; }
.panel h3 { font-size: 16px; margin-top: 20px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: white; }
table { width: 100%; border-collapse: collapse; min-width: 720px; background: white; }
th, td { padding: 13px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: #f7faf8; }
td small { display: block; color: var(--muted); margin-top: 3px; }
tr[onclick] { cursor: pointer; }
tr[onclick]:hover { background: #f7faf8; }
.right { text-align: right; }
.minus { color: var(--danger); font-weight: 800; }
.empty { color: var(--muted); text-align: center; padding: 24px; }

.badge { display: inline-flex; align-items: center; min-height: 28px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; background: #eef3f0; color: var(--muted); white-space: nowrap; }
.badge.pending { background: #fff7db; color: #8a5700; }
.badge.revision { background: #fff0d9; color: var(--warn); }
.badge.approved { background: #e6f6ee; color: var(--ok); }
.badge.transferred, .badge.posted { background: #dcfce7; color: #166534; }
.badge.rejected, .badge.void { background: #fee2e2; color: var(--danger); }
.badge.active { background: #dcfce7; color: #166534; }
.badge.inactive { background: #eef2f1; color: #66736f; }

.form { display: grid; gap: 14px; }
.form.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; }
label { display: grid; gap: 7px; font-size: 13px; color: var(--muted); font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: white;
  color: var(--ink);
  outline: none;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(18, 92, 84, .14); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.filters { display: grid; grid-template-columns: 1.3fr 1fr 1fr auto auto auto; gap: 12px; align-items: end; margin-bottom: 14px; }

button, .primary, .ghost, .warn, .danger, .install-btn, .success-btn, .mini-btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
}
.primary { background: var(--brand); color: white; }
.primary:hover { background: var(--brand-dark); }
.ghost { background: white; color: var(--brand); border-color: var(--line); }
.warn { background: #fff7ed; color: var(--warn); border-color: #fed7aa; }
.danger { background: #fee2e2; color: var(--danger); border-color: #fecaca; }
.success-btn { background: #e7f7ed; color: #126238; border-color: #bfe7cd; white-space: nowrap; }
.install-btn { background: var(--brand-2); color: #271b02; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-actions { margin-top: 10px; }
.inline-form { display: inline-flex; margin: 0; }
.mini-btn { min-height: 34px; padding: 7px 10px; font-size: 12px; background: #f7faf8; color: var(--brand); border-color: var(--line); }
.mini-btn.danger { color: var(--danger); background: #fff5f5; border-color: #fecaca; }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid var(--line); background: white; }
.alert.success { background: #eaf8ef; border-color: #bfe7cd; color: #14532d; }
.alert.danger { background: #fff1f2; border-color: #fecdd3; color: #9f1239; }

.timeline { display: grid; }
.timeline-item { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 13px 0; border-bottom: 1px solid var(--line); }
.timeline-item:last-child { border-bottom: 0; }
.timeline-item > span { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; font-weight: 900; }
.timeline-item .up { background: #dcfce7; color: #166534; }
.timeline-item .down { background: #fee2e2; color: var(--danger); }
.timeline-item small { display: block; color: var(--muted); margin-top: 3px; }
.timeline-item b { white-space: nowrap; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr); gap: 16px; align-items: start; }
.record-head { display: flex; align-items: start; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.record-head h2 { margin-bottom: 4px; }
.record-head p { margin: 0; color: var(--muted); }
.record { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 10px 16px; }
.record dt { color: var(--muted); font-weight: 800; }
.record dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 300px; transform: translateX(-100%); transition: transform .2s ease; z-index: 10; }
  .nav-open .sidebar { transform: translateX(0); }
  .icon-btn { display: grid; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: 1fr; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .main { padding: 14px 12px 32px; }
  .topbar { align-items: flex-start; }
  .metric-grid, .metric-grid.two, .grid-3, .form.compact, .filters { grid-template-columns: 1fr; }
  .panel { padding: 14px; }
  .panel-head { align-items: stretch; flex-direction: column; }
  .record { grid-template-columns: 1fr; }
  .timeline-item { grid-template-columns: 32px minmax(0, 1fr); }
  .timeline-item b { grid-column: 2; }
}

@media print {
  .sidebar, .topbar, .filters button, .install-btn { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; }
  .panel, .metric { box-shadow: none; }
}
