:root {
  --ink: #0f1c2e;
  --ink-soft: #3a4a5c;
  --steel: #1e3a5f;
  --steel-mid: #2d5a87;
  --glass: #7eb6d9;
  --glass-soft: #c5e1f0;
  --sand: #e8eef3;
  --paper: #f4f7fa;
  --line: #d0dbe6;
  --ok: #1f7a4d;
  --warn: #b07a16;
  --danger: #a83232;
  --sidebar: #10233a;
  --sidebar-2: #16304d;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(16, 35, 58, 0.08);
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Instrument Serif", Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(126, 182, 217, 0.18), transparent 60%),
    radial-gradient(900px 500px at -10% 100%, rgba(30, 58, 95, 0.08), transparent 55%),
    linear-gradient(180deg, #eef3f7 0%, var(--paper) 40%, #e9eef4 100%);
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(185deg, var(--sidebar) 0%, var(--sidebar-2) 55%, #0c1a2b 100%);
  color: #dce7f2;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid rgba(255,255,255,0.06);
}

.brand {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  padding: 0.5rem 0.65rem 1.4rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 1rem;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: linear-gradient(145deg, var(--glass), var(--steel-mid));
  color: white;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
}

.brand-text strong {
  display: block;
  font-size: 1.05rem;
  color: #fff;
  font-weight: 600;
}

.brand-text span {
  font-size: 0.78rem;
  opacity: 0.7;
}

.nav-group {
  margin: 1rem 0.65rem 0.4rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  opacity: 0.45;
}

.side-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: #c4d4e6;
  text-decoration: none;
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  margin-bottom: 0.2rem;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}

.side-nav .nav-link:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
  transform: translateX(2px);
}

.side-nav .nav-link.active {
  background: linear-gradient(90deg, rgba(126,182,217,0.22), rgba(126,182,217,0.05));
  color: #fff;
  box-shadow: inset 3px 0 0 var(--glass);
}

.nav-ico { width: 1.2rem; opacity: 0.8; text-align: center; }

.sidebar-foot {
  margin-top: auto;
  padding: 1rem 0.65rem 0.25rem;
  opacity: 0.4;
  font-size: 0.75rem;
}

.main-wrap { min-width: 0; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.4rem 1.8rem 0.6rem;
}

.page-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 2rem;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.page-sub {
  margin: 0.2rem 0 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.topbar-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.content {
  padding: 0.8rem 1.8rem 2rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: rgba(255,255,255,0.78);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  animation: rise 0.5s ease both;
}

.stat-card:nth-child(2) { animation-delay: 0.05s; }
.stat-card:nth-child(3) { animation-delay: 0.1s; }
.stat-card:nth-child(4) { animation-delay: 0.15s; }

.stat-card::after {
  content: "";
  position: absolute;
  right: -20px;
  top: -20px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(126,182,217,0.25), transparent 70%);
}

.stat-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--steel);
  line-height: 1.1;
}

.stat-hint { margin-top: 0.35rem; font-size: 0.8rem; color: #6a7c8f; }

.panel {
  background: rgba(255,255,255,0.85);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.1rem;
  overflow: hidden;
  animation: rise 0.45s ease both;
}

.panel-h {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.15rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fbfdff, #f3f7fb);
}

.panel-h h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.panel-b { padding: 1.15rem; }

.table-modern {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table-modern th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #607388;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--line);
  background: #f7fafc;
  white-space: nowrap;
}

.table-modern td {
  padding: 0.75rem;
  border-bottom: 1px solid #e8eef4;
  vertical-align: middle;
}

.table-modern tr:hover td { background: #f5f9fc; }

.badge-soft {
  display: inline-flex;
  align-items: center;
  padding: 0.22rem 0.55rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.b-draft { background: #e8eef4; color: #46586b; }
.b-sent { background: #dceef8; color: #1e5a86; }
.b-ok { background: #d8f0e4; color: #1f7a4d; }
.b-warn { background: #f7ecd5; color: #8a6414; }
.b-danger { background: #f6dede; color: #a83232; }
.b-prod { background: #e2e4f8; color: #3d458a; }

.btn-primary {
  --bs-btn-bg: var(--steel);
  --bs-btn-border-color: var(--steel);
  --bs-btn-hover-bg: var(--steel-mid);
  --bs-btn-hover-border-color: var(--steel-mid);
  --bs-btn-active-bg: #16304d;
  --bs-btn-active-border-color: #16304d;
}

.btn-outline-primary {
  --bs-btn-color: var(--steel);
  --bs-btn-border-color: var(--steel);
  --bs-btn-hover-bg: var(--steel);
  --bs-btn-hover-border-color: var(--steel);
}

.btn-ghost {
  background: white;
  border: 1px solid var(--line);
  color: var(--ink);
}

.btn-ghost:hover { background: var(--sand); color: var(--ink); }

.form-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.3rem;
}

.form-control, .form-select {
  border-color: var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  background: #fff;
}

.form-control:focus, .form-select:focus {
  border-color: var(--glass);
  box-shadow: 0 0 0 0.2rem rgba(126, 182, 217, 0.25);
}

.toolbar {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  align-items: end;
}

.money { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

.draw-box {
  background: linear-gradient(160deg, #f7fbfe, #eaf3f9);
  border: 1px dashed #9dbad0;
  border-radius: 12px;
  min-height: 280px;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.draw-box svg { max-width: 100%; height: auto; }

.lines-editor { overflow-x: auto; }

.lines-editor table input,
.lines-editor table select {
  min-width: 90px;
  font-size: 0.85rem;
  padding: 0.35rem 0.45rem;
}

.summary-box {
  background: linear-gradient(160deg, #10233a, #1e3a5f);
  color: #e8f1f8;
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
}

.summary-box .row-line {
  display: flex;
  justify-content: space-between;
  padding: 0.28rem 0;
  font-size: 0.92rem;
}

.summary-box .total {
  margin-top: 0.5rem;
  padding-top: 0.55rem;
  border-top: 1px solid rgba(255,255,255,0.15);
  font-size: 1.15rem;
  font-weight: 700;
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: #6a7c8f;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .side-nav { display: flex; flex-wrap: wrap; width: 100%; }
  .nav-group, .sidebar-foot { display: none; }
  .brand { border: 0; margin: 0; padding: 0.25rem; }
}
