:root {
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #dbe4f0;
  --text: #102033;
  --muted: #66768a;
  --primary: #174ea6;
  --primary-strong: #103a7d;
  --primary-soft: #eaf2ff;
  --success: #0f8a4b;
  --success-soft: #e8fbf0;
  --warning: #a06207;
  --warning-soft: #fff6df;
  --danger: #b42318;
  --danger-soft: #ffeceb;
  --shadow: 0 18px 40px rgba(16, 32, 51, 0.08);
  --radius: 22px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Tahoma, Arial, sans-serif;
  background: linear-gradient(180deg, #f7fafd 0%, var(--bg) 100%);
  color: var(--text);
}
a { text-decoration: none; color: inherit; }
small { font-size: 12px; }

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at top right, rgba(23, 78, 166, 0.08), transparent 30%),
    radial-gradient(circle at bottom left, rgba(15, 138, 75, 0.07), transparent 26%),
    linear-gradient(160deg, #eef4fb, #f9fbfd);
}
.login-card {
  width: 100%;
  max-width: 520px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 28px;
  padding: 32px;
  box-shadow: 0 30px 80px rgba(16, 32, 51, 0.14);
}
.login-card h1 { margin: 0 0 8px; font-size: 30px; }
.login-note {
  margin-top: 18px;
  padding: 16px;
  border-radius: 18px;
  background: linear-gradient(180deg, #fbfdff, #f2f6fb);
  border: 1px solid var(--line);
  color: #3f5269;
}

.app-shell {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  background: linear-gradient(180deg, #0f2340 0%, #142d52 55%, #0f2340 100%);
  color: #fff;
  padding: 28px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 10px;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, #eaf2ff, #b7d0ff);
  color: var(--primary-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.sidebar-note {
  margin: 0 0 22px;
  color: rgba(255,255,255,0.75);
  line-height: 1.7;
  font-size: 13px;
}
.nav-group-title {
  color: rgba(255,255,255,0.55);
  font-size: 12px;
  margin: 16px 10px 8px;
}
.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: rgba(255,255,255,0.82);
  padding: 13px 14px;
  border-radius: 16px;
  margin-bottom: 8px;
  transition: 0.18s ease;
}
.nav-link:hover,
.nav-link.active {
  background: rgba(255,255,255,0.10);
  color: #fff;
  transform: translateX(-2px);
}
.nav-link small { color: rgba(255,255,255,0.58); }
.sidebar-foot {
  margin-top: 22px;
  padding: 14px;
  border-radius: 18px;
  background: rgba(255,255,255,0.08);
  font-size: 12px;
  color: rgba(255,255,255,0.74);
  line-height: 1.8;
}

.main-content {
  padding: 22px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  background: rgba(255,255,255,0.9);
  border: 1px solid rgba(255,255,255,0.7);
  padding: 14px 18px;
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.topbar-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.topbar-user {
  font-weight: 700;
}
.badge,
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-soft { background: var(--primary-soft); color: var(--primary-strong); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-neutral { background: #eef2f6; color: #42556f; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head h1 {
  margin: 0 0 8px;
  font-size: 30px;
}
.page-head p {
  margin: 0;
  max-width: 760px;
}
.hero-card {
  background: linear-gradient(130deg, #173968 0%, #174ea6 52%, #2269d2 100%);
  color: #fff;
  border-radius: 28px;
  padding: 24px;
  box-shadow: 0 24px 55px rgba(23, 78, 166, 0.22);
  margin-bottom: 18px;
}
.hero-grid {
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: 18px;
  align-items: stretch;
}
.hero-card h1,
.hero-card h2,
.hero-card p,
.hero-card .muted { color: #fff; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.hero-card .btn-light { background: rgba(255,255,255,0.16); color: #fff; border: 1px solid rgba(255,255,255,0.18); }
.hero-card .btn-light:hover { background: rgba(255,255,255,0.22); }
.hero-box {
  border-radius: 22px;
  padding: 18px;
  background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.12);
}
.hero-kpi {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.hero-kpi .mini {
  background: rgba(255,255,255,0.08);
  border-radius: 18px;
  padding: 14px;
}
.hero-kpi span { display: block; color: rgba(255,255,255,0.82); font-size: 13px; }
.hero-kpi strong { display: block; margin-top: 8px; font-size: 24px; }

.panel,
.stat-card {
  background: rgba(255,255,255,0.92);
  border-radius: var(--radius);
  padding: 18px;
  border: 1px solid rgba(255,255,255,0.75);
  box-shadow: var(--shadow);
}
.panel { margin-bottom: 18px; }
.compact-panel { padding: 14px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.panel-head h2,
.panel-head h3 { margin: 0; font-size: 20px; }
.panel-subtitle { color: var(--muted); font-size: 13px; }
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card {
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: "";
  position: absolute;
  inset-inline-start: -20px;
  bottom: -24px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: rgba(23, 78, 166, 0.07);
}
.stat-card span { display: block; color: var(--muted); margin-bottom: 10px; font-size: 13px; }
.stat-card strong { display: block; font-size: 30px; margin-bottom: 4px; }
.stat-card small { color: #72839b; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.three-col { display: grid; grid-template-columns: 1.1fr .9fr .9fr; gap: 18px; }
.distribution-layout { grid-template-columns: 360px minmax(0, 1fr); }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.form-grid label,
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: #34465c;
}
.full-width { grid-column: 1 / -1; }
input[type=text], input[type=password], input[type=number], input[type=file], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 13px;
  background: #fff;
  font-size: 14px;
  color: var(--text);
  transition: border-color .16s ease, box-shadow .16s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #7fb0ff;
  box-shadow: 0 0 0 4px rgba(23,78,166,0.08);
}
textarea { resize: vertical; min-height: 90px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  transition: .18s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: linear-gradient(135deg, var(--primary), #2163cf); color: #fff; box-shadow: 0 10px 20px rgba(23, 78, 166, 0.18); }
.btn-light { background: #f5f8fc; color: var(--text); border: 1px solid var(--line); }
.btn-success { background: linear-gradient(135deg, var(--success), #18a35a); color: #fff; }
.btn-warning { background: linear-gradient(135deg, #b5740f, #dc9707); color: #fff; }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 12px; }

.filters-inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filters-inline > * { flex: 0 1 auto; }
.filters-inline input[type=text] { min-width: 280px; }
.alert {
  padding: 14px 16px;
  border-radius: 16px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert-success { background: var(--success-soft); color: var(--success); border-color: #bee9d0; }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: #f7c7c1; }
.muted { color: var(--muted); }

.table-wrap { overflow: auto; }
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 760px;
}
th, td {
  padding: 13px 12px;
  border-bottom: 1px solid #e8eef5;
  text-align: right;
  vertical-align: middle;
}
thead th {
  background: #f6f9fc;
  position: sticky;
  top: 0;
  z-index: 1;
  color: #42566d;
}
tbody tr:hover { background: #fbfdff; }
.table-card {
  border: 1px solid #e8eef5;
  border-radius: 20px;
  overflow: hidden;
}
.family-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.family-grid div {
  padding: 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, #fbfdff, #f4f8fc);
  border: 1px solid #ebf0f5;
}
.family-grid span { display: block; color: var(--muted); margin-bottom: 6px; font-size: 12px; }
.family-grid strong { font-size: 18px; }
.search-results { display: flex; flex-wrap: wrap; gap: 10px; }
.search-pill {
  background: #f1f6ff;
  color: #174ea6;
  padding: 12px 16px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #d7e5ff;
}
.search-pill:hover { background: #e7f0ff; }
.note-box {
  background: linear-gradient(180deg, #fbfdff, #f6f9fc);
  border: 1px solid #e4ebf4;
  border-radius: 18px;
  padding: 16px;
  color: #32445b;
  line-height: 1.8;
}
.signature-box {
  border: 1px solid #d8e3ef;
  border-radius: 20px;
  padding: 14px;
  margin: 16px 0;
  background: linear-gradient(180deg, #ffffff, #fbfdff);
}
.signature-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 10px;
}
#signatureCanvas {
  width: 100%;
  height: 220px;
  border: 1px dashed #c8d7ea;
  border-radius: 14px;
  display: block;
  background: #fff;
  touch-action: none;
}
.progress {
  height: 12px;
  border-radius: 999px;
  background: #e7eef7;
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(135deg, var(--primary), #2e78f6);
}
.metric-list {
  display: grid;
  gap: 12px;
}
.metric-row {
  display: grid;
  grid-template-columns: 150px 1fr 70px;
  gap: 12px;
  align-items: center;
}
.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.quick-link {
  padding: 16px;
  border-radius: 18px;
  background: linear-gradient(180deg, #fbfdff, #f4f8fc);
  border: 1px solid #e6edf6;
}
.quick-link strong { display: block; margin-bottom: 6px; }
.quick-link small { color: var(--muted); line-height: 1.7; }
.chip-set { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 8px 11px;
  border-radius: 999px;
  background: #f5f8fb;
  border: 1px solid #dfe8f2;
  color: #43566f;
  font-size: 12px;
}
.legend-list {
  display: grid;
  gap: 10px;
}
.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.legend-item .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
}
.dot-primary { background: var(--primary); }
.dot-success { background: var(--success); }
.dot-warning { background: var(--warning); }
.dot-danger { background: var(--danger); }
.inline-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 16px;
  background: #f8fbff;
  border: 1px solid #e5eef9;
}
.kv-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.kv-item {
  padding: 12px 14px;
  border: 1px solid #e7edf6;
  border-radius: 16px;
  background: #fafcff;
}
.kv-item span { display: block; color: var(--muted); margin-bottom: 4px; font-size: 12px; }
.kv-item strong { font-size: 17px; }
.receipt-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.receipt-sheet {
  max-width: 1080px;
  margin: 0 auto;
  background: #fff;
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 26px;
}
.receipt-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 2px solid #eaf0f7;
  padding-bottom: 16px;
  margin-bottom: 18px;
}
.receipt-title h1 { margin: 0 0 6px; font-size: 28px; }
.receipt-title p { margin: 0; color: var(--muted); }
.receipt-signature {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 18px;
  align-items: end;
}
.receipt-signature-box {
  border: 1px solid #e3ebf4;
  border-radius: 18px;
  padding: 14px;
  min-height: 170px;
  background: #fff;
}
.receipt-signature-box img {
  max-width: 100%;
  max-height: 120px;
  display: block;
  margin: 10px auto 0;
}
.columns-2 { columns: 2 180px; column-gap: 24px; }
.columns-2 li { break-inside: avoid; margin-bottom: 8px; }
.print-note { font-size: 12px; color: var(--muted); }

@media print {
  @page { size: A4 portrait; margin: 8mm; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  body { background: #fff !important; font-size: 12px; }
  .sidebar, .topbar, .page-head, .receipt-actions, .btn, .alert { display: none !important; }
  .app-shell { display: block; }
  .main-content { padding: 0 !important; }
  
  .receipt-sheet { 
    max-width: 100% !important; 
    margin: 0 !important; 
    padding: 16px !important; 
    box-shadow: none !important; 
    border: 1px solid #dce4ee !important; 
    border-radius: 20px !important; 
  }
  .receipt-header { margin-bottom: 12px; padding-bottom: 12px; }
  .receipt-title h1 { font-size: 20px; margin-bottom: 4px; }
  
  .kv-list { 
    display: grid !important; 
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important; 
    gap: 8px !important; 
  }
  .kv-item { 
    padding: 8px 12px !important; 
    border: 1px solid #e7edf6 !important; 
    border-radius: 12px !important; 
    background: #fafcff !important; 
  }
  .kv-item span { font-size: 11px !important; margin-bottom: 2px !important; }
  .kv-item strong { font-size: 14px !important; }
  
  .panel { 
    margin-top: 14px !important; 
    padding: 12px !important; 
    box-shadow: none !important; 
    border: 1px solid #dce4ee !important; 
    border-radius: 16px !important; 
  }
  .panel-head h2 { font-size: 16px; margin-bottom: 8px; }
  
  table { min-width: 100%; border-collapse: separate; border-spacing: 0; }
  th, td { padding: 6px 8px !important; font-size: 11px !important; border-bottom: 1px solid #e8eef5 !important; }
  th { background: #f6f9fc !important; color: #42566d !important; }
  
  .status-badge { padding: 4px 8px !important; font-size: 10px !important; }
  
  .receipt-signature { 
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important; 
    gap: 12px !important; 
    margin-top: 14px !important; 
  }
  .receipt-signature-box { 
    min-height: 90px !important; 
    padding: 10px !important; 
    border: 1px solid #e3ebf4 !important;
    border-radius: 14px !important;
    background: #fff !important;
  }
  .receipt-signature-box img { max-height: 60px !important; margin-top: 4px !important; }
  
  .print-note { margin-top: 12px !important; font-size: 10px !important; text-align: center; }
  .print-only { display: block !important; }
}

@media (max-width: 1120px) {
  .hero-grid, .three-col, .receipt-signature { grid-template-columns: 1fr; }
  .app-shell { grid-template-columns: 240px minmax(0, 1fr); }
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    padding: 16px;
    border-bottom-left-radius: 26px;
    border-bottom-right-radius: 26px;
  }
  .sidebar-note, .sidebar-foot { display: none; }
  nav { display: flex; flex-wrap: wrap; gap: 6px; }
  .nav-link { margin-bottom: 0; padding: 10px 14px; font-size: 13px; flex: 1 1 auto; justify-content: center; }
  .nav-link small { display: none; }
  .nav-group-title { margin: 12px 6px 8px; text-align: center; font-size: 11px; }
  .brand { justify-content: center; }
  
  .two-col, .distribution-layout, .form-grid, .family-grid, .kv-list { grid-template-columns: 1fr; }
  .main-content { padding: 14px; }
  .page-head h1 { font-size: 24px; }
  .filters-inline input[type=text] { min-width: 0; width: 100%; }
  .metric-row { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: stretch; text-align: center; }
  .topbar-meta { justify-content: center; }
  .receipt-header { flex-direction: column; align-items: center; text-align: center; }
  .receipt-actions { justify-content: center; width: 100%; }
}

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.print-only { display: none; }
