:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #eef3f5;
  --ink: #172027;
  --muted: #68757f;
  --line: #dce4e8;
  --blue: #1f5f7a;
  --blue-dark: #16465b;
  --amber: #c8892e;
  --danger: #ba3d35;
  --success: #327a52;
  --shadow: 0 16px 42px rgba(25, 41, 52, 0.08);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: #15222b;
  color: #eef6f8;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e9f2f5;
  color: var(--blue-dark);
  font-weight: 850;
}

.brand strong { display: block; font-size: 15px; }
.brand small { display: block; color: #a8b8c0; font-size: 12px; margin-top: 2px; }

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

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: 7px;
  color: #c4d2d8;
  font-size: 14px;
  font-weight: 650;
}

.nav img {
  width: 18px;
  height: 18px;
  filter: invert(89%) sepia(11%) saturate(224%) hue-rotate(153deg) brightness(91%) contrast(83%);
}

.nav a:hover,
.nav a.active {
  background: #233440;
  color: #ffffff;
}

.company-card {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
}

.company-card strong {
  display: block;
  font-size: 12px;
  line-height: 1.45;
}

.company-card span {
  display: block;
  margin-top: 8px;
  color: #a8b8c0;
  font-size: 12px;
}

.content {
  min-width: 0;
  padding: 26px;
}

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

.topbar h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.15;
}

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

.top-actions,
.panel-head,
.print-actions,
.quick-actions,
.tabs {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-actions { flex-wrap: wrap; justify-content: flex-end; }

.btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 14px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 750;
}

.btn img { width: 17px; height: 17px; filter: invert(100%); }
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }

.logout-form {
  margin: 0;
}

.icon-action {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  cursor: pointer;
}

.icon-action img {
  width: 17px;
  height: 17px;
}

.login-body {
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(31, 95, 122, 0.08), rgba(200, 137, 46, 0.08)),
    var(--bg);
}

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

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

.login-brand {
  padding: 0;
  color: var(--ink);
}

.login-brand small {
  color: var(--muted);
}

.login-panel h1 {
  margin: 28px 0 8px;
  font-size: 28px;
  line-height: 1.1;
}

.login-panel p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.5;
}

.login-error {
  margin-bottom: 14px;
  padding: 11px 12px;
  border: 1px solid rgba(186, 61, 53, 0.24);
  border-radius: 7px;
  background: rgba(186, 61, 53, 0.08);
  color: var(--danger);
  font-size: 13px;
  font-weight: 800;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel,
.quick-create,
.customer-head {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  min-height: 134px;
  padding: 18px;
}

.metric span,
.paper-parties span,
.paper-bottom span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 12px;
  font-size: 26px;
  line-height: 1.1;
}

.metric small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 18px;
  margin-bottom: 18px;
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 18px;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel + .panel,
.document-form .panel + .panel {
  margin-top: 18px;
}

.panel-head {
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-head h2,
.quick-create h2,
.form-panel h2,
.customer-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

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

.text-link {
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
}

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

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

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

th {
  background: var(--surface-2);
  color: #4c5962;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

td a {
  color: var(--blue);
  font-weight: 800;
}

td small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

tr:last-child td { border-bottom: 0; }
.empty { color: var(--muted); text-align: center; }

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eef3f5;
  color: #43515a;
  font-size: 12px;
  font-weight: 800;
}

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

.balance-list {
  display: grid;
  gap: 8px;
}

.balance-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.balance-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.quick-create {
  padding: 18px;
}

.quick-actions {
  margin-top: 12px;
  flex-wrap: wrap;
}

.quick-actions a,
.tabs a {
  min-height: 36px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  font-size: 13px;
  font-weight: 800;
}

.tabs {
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.tabs a.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.form-panel.wide { max-width: 860px; }
.stack-form { display: grid; gap: 12px; }
.form-row, .form-grid {
  display: grid;
  gap: 12px;
}
.form-row { grid-template-columns: 1fr 1fr; }
.form-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }

label {
  display: grid;
  gap: 6px;
  color: #40505a;
  font-size: 13px;
  font-weight: 800;
}

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

input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 95, 122, 0.14);
}

.customer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  margin-bottom: 18px;
}

.customer-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

.customer-head > strong {
  font-size: 28px;
}

.line-table {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.line-head,
.line-row {
  display: grid;
  grid-template-columns: minmax(240px, 1.4fr) 105px 100px 130px 90px 130px 42px;
  gap: 8px;
  align-items: center;
}

.line-head {
  background: var(--surface-2);
  padding: 10px;
  color: #4c5962;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.line-row {
  padding: 10px;
  border-top: 1px solid var(--line);
}

.line-row output {
  color: var(--ink);
  font-weight: 850;
  text-align: right;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
}

.icon-btn img {
  width: 16px;
  height: 16px;
}

.total-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
  margin-top: 18px;
}

.total-box dl,
.paper-bottom dl,
.paper-parties dl {
  margin: 0;
  display: grid;
  gap: 8px;
}

.total-box dl {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

dl div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

dt {
  color: var(--muted);
  font-weight: 750;
}

dd {
  margin: 0;
  font-weight: 850;
}

.total-box div:last-child dd,
.grand dd {
  color: var(--blue);
  font-size: 22px;
}

.document-preview {
  max-width: 1040px;
  margin: 0 auto;
}

.print-actions {
  justify-content: flex-end;
  margin-bottom: 14px;
}

.paper {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 34px;
  box-shadow: var(--shadow);
}

.paper-head,
.paper-parties,
.paper-bottom {
  display: flex;
  justify-content: space-between;
  gap: 34px;
}

.paper-head {
  border-bottom: 2px solid var(--ink);
  padding-bottom: 24px;
}

.paper-head strong {
  display: block;
  font-size: 18px;
  max-width: 540px;
}

.paper-head p,
.paper-parties p,
.paper-bottom p {
  margin: 6px 0 0;
  color: #4c5962;
  line-height: 1.5;
}

.paper-title {
  text-align: right;
}

.paper-title span {
  display: block;
  color: var(--muted);
  font-weight: 850;
}

.paper-title strong {
  margin-top: 8px;
  font-size: 24px;
}

.paper-parties {
  padding: 24px 0;
}

.paper-table {
  min-width: unset;
  border: 1px solid var(--line);
}

.paper-bottom {
  padding-top: 24px;
}

.paper-bottom > div {
  max-width: 560px;
}

@media (max-width: 1120px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-grid, .work-grid, .total-box { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }
  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .company-card { display: none; }
  .content { padding: 16px; }
  .topbar, .paper-head, .paper-parties, .paper-bottom, .customer-head {
    align-items: flex-start;
    flex-direction: column;
  }
  .top-actions { justify-content: flex-start; }
  .metric-grid, .form-row, .form-grid { grid-template-columns: 1fr; }
  .line-head { display: none; }
  .line-row {
    grid-template-columns: 1fr 1fr;
    padding: 12px;
  }
  .line-row input:first-child {
    grid-column: 1 / -1;
  }
  .line-row output {
    text-align: left;
  }
  .paper {
    padding: 20px;
  }
}

@media print {
  body { background: #fff; }
  .sidebar, .topbar, .print-actions { display: none; }
  .app-shell { display: block; }
  .content { padding: 0; }
  .paper {
    border: 0;
    box-shadow: none;
    border-radius: 0;
  }
}
