:root {
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --paper: #f8fafc;
  --panel: #ffffff;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #0f766e;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
  --soft-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(37, 99, 235, 0.08), transparent 26%),
    linear-gradient(180deg, #f8fafc 0%, #eef4ff 100%);
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px clamp(16px, 4vw, 34px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(18px);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 20px;
  color: var(--ink);
}

.brand::before {
  content: "973";
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  box-shadow: var(--soft-shadow);
}

.nav {
  display: flex;
  gap: 8px;
  flex: 1;
}

.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  border-radius: 8px;
  padding: 0 12px;
  color: var(--muted);
  font-weight: 650;
}

.nav a:hover {
  color: var(--primary);
  background: #eff6ff;
  text-decoration: none;
}

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 30px auto 52px;
}

.page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

h1, h2 { margin: 0; }
h1 {
  font-size: clamp(28px, 4vw, 38px);
  line-height: 1.05;
  letter-spacing: 0;
}
h2 { font-size: 20px; margin-bottom: 14px; }

.muted, .hint {
  color: var(--muted);
}

.hint {
  margin: 0;
  font-size: 13px;
}

.panel, .stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
}

.panel { padding: 24px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.stat {
  position: relative;
  overflow: hidden;
  padding: 20px;
}

.stat::after {
  content: "";
  position: absolute;
  inset: auto -28px -36px auto;
  width: 110px;
  height: 110px;
  border-radius: 8px;
  background: rgba(37, 99, 235, 0.08);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 14px;
}

.stat strong {
  display: block;
  margin-top: 6px;
  font-size: 34px;
  letter-spacing: 0;
}

.grid.two {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 18px;
}

.cage-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.cage-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: linear-gradient(180deg, #ffffff, #f8fafc);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
}

.cage-card strong {
  display: block;
  font-size: 30px;
  color: var(--primary-dark);
}

.cage-card span, .cage-card small {
  display: block;
  color: var(--muted);
}

.auth-shell {
  min-height: calc(100vh - 150px);
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(430px, 100%);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.form-grid.compact {
  margin-bottom: 20px;
}

.settings-card + .settings-card {
  margin-top: 18px;
}

.section-heading {
  display: grid;
  gap: 4px;
  padding-bottom: 4px;
}

.section-heading p {
  margin: 0;
}

label {
  display: grid;
  gap: 7px;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 12px 13px;
  font: inherit;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

input[readonly] {
  color: var(--muted);
  background: #f8fafc;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

textarea { resize: vertical; }

.wide { grid-column: 1 / -1; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  align-self: end;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.availability-panel {
  display: grid;
  align-content: center;
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: #eff6ff;
}

.availability-panel span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.availability-panel strong {
  font-size: 28px;
  color: var(--primary-dark);
}

.payment-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.payment-summary div {
  display: grid;
  gap: 7px;
}

.payment-summary span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.payment-summary strong {
  display: flex;
  align-items: center;
  min-height: 47px;
  font-size: 26px;
  color: var(--primary-dark);
}

.form-actions, .actions, .invoice-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}

button, .primary-button, .secondary-button, .ghost-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.primary-button {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.24);
}

.primary-button:hover {
  background: var(--primary-dark);
  text-decoration: none;
  transform: translateY(-1px);
}

.secondary-button {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

.danger-button {
  color: var(--danger);
  border-color: #fecaca;
}

.ghost-button {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

.table-wrap {
  overflow-x: auto;
}

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

th, td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  background: #f8fafc;
}

.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
  text-transform: capitalize;
  color: #fff;
  background: var(--muted);
}

.badge.available, .badge.paid, .badge.picked_up, .badge.active { background: var(--primary); }
.badge.reserved, .badge.partial, .badge.pending { background: var(--warning); }
.badge.sold { background: var(--accent); }
.badge.unpaid, .badge.cancelled { background: var(--danger); }

.alert {
  display: none;
}

.alert.success {
  color: #145235;
  background: #e7f5ec;
}

.alert.error {
  color: #7d2626;
  background: #f9e8e8;
}

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

.inline-form select {
  min-width: 140px;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.report-grid {
  margin-top: 18px;
}

.invoice-actions {
  justify-content: flex-start;
  margin-bottom: 18px;
}

.invoice {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 36px;
  max-width: 780px;
  margin: 0 auto;
  box-shadow: var(--shadow);
}

.invoice header, .invoice-grid {
  display: flex;
  justify-content: space-between;
  gap: 24px;
}

.invoice header {
  padding-bottom: 24px;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 24px;
}

.invoice-meta {
  display: grid;
  gap: 6px;
  text-align: right;
}

.invoice-grid {
  margin-bottom: 24px;
}

.invoice-grid span {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  font-weight: 800;
}

.animal-code {
  display: block;
  font-size: 42px;
  color: var(--primary-dark);
}

.invoice-table td:last-child {
  text-align: right;
  font-weight: 800;
}

.total-row td {
  font-size: 22px;
  border-top: 2px solid var(--ink);
}

.thermal-receipt {
  display: none;
}

.invoice-qr {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.invoice-qr img {
  width: 112px;
  height: 112px;
}

.invoice-qr p {
  margin: 5px 0;
  color: var(--muted);
}

.invoice-qr small {
  display: block;
  color: var(--muted);
  word-break: break-all;
}

.verify-animal {
  display: grid;
  place-items: center;
  gap: 4px;
  min-height: 190px;
  border-radius: 8px;
  background: #eff6ff;
  text-align: center;
}

.verify-animal span {
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
}

.verify-animal strong {
  color: var(--primary-dark);
  font-size: 58px;
  line-height: 1;
}

.detail-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.detail-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.detail-list span {
  color: var(--muted);
}

.alert-inline {
  border-radius: 8px;
  padding: 13px 14px;
  font-weight: 800;
}

.alert-inline.success {
  color: #145235;
  background: #e7f5ec;
}

.alert-inline.error {
  color: #7d2626;
  background: #f9e8e8;
}

.empty-state {
  text-align: center;
}

@media (max-width: 780px) {
  .topbar, .page-title, .invoice header, .invoice-grid {
    align-items: stretch;
    flex-direction: column;
  }

  .nav {
    flex-wrap: wrap;
  }

  .stats-grid, .grid.two, .form-grid, .cage-grid, .payment-summary {
    grid-template-columns: 1fr;
  }

  .invoice-meta {
    text-align: left;
  }
}

@media print {
  .topbar, .no-print, .alert {
    display: none !important;
  }

  body, .page {
    background: #fff;
    margin: 0;
    width: 100%;
  }

  .invoice {
    border: 0;
    box-shadow: none;
    max-width: none;
  }

  body.thermal-print-mode {
    width: var(--thermal-width, 80mm);
    margin: 0;
  }

  body.thermal-print-mode .page {
    width: var(--thermal-width, 80mm);
    margin: 0;
    padding: 0;
  }

  body.thermal-print-mode .invoice {
    display: none !important;
  }

  body.thermal-print-mode .thermal-receipt {
    display: block;
    width: calc(var(--thermal-width, 80mm) - 8mm);
    margin: 0 auto;
    padding: 4mm 2mm;
    color: #000;
    background: #fff;
    font-family: "Courier New", monospace;
    font-size: 11px;
    line-height: 1.35;
  }

  .thermal-receipt header {
    text-align: center;
    border-bottom: 1px dashed #000;
    padding-bottom: 8px;
    margin-bottom: 8px;
  }

  .thermal-receipt h1 {
    font-size: 18px;
    line-height: 1.1;
    margin: 0 0 3px;
  }

  .thermal-receipt p {
    margin: 0;
  }

  .thermal-lines {
    display: grid;
    gap: 3px;
    border-bottom: 1px dashed #000;
    padding-bottom: 8px;
    margin-bottom: 8px;
  }

  .thermal-lines div {
    display: flex;
    justify-content: space-between;
    gap: 8px;
  }

  .thermal-lines span {
    flex: 0 0 auto;
  }

  .thermal-lines strong {
    text-align: right;
    word-break: break-word;
  }

  .thermal-animal {
    text-align: center;
    border-bottom: 1px dashed #000;
    padding-bottom: 8px;
    margin-bottom: 8px;
  }

  .thermal-animal span {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
  }

  .thermal-animal strong {
    display: block;
    font-size: 30px;
    line-height: 1.1;
    margin: 2px 0;
  }

  .thermal-total {
    border-top: 1px solid #000;
    padding-top: 5px;
    margin-top: 3px;
    font-size: 14px;
  }

  .thermal-notes {
    border-bottom: 1px dashed #000;
    padding-bottom: 8px;
    margin-bottom: 8px;
  }

  .thermal-receipt footer {
    text-align: center;
    padding-top: 4px;
  }

  .thermal-qr {
    display: block;
    width: 24mm;
    height: 24mm;
    margin: 0 auto 4px;
  }
}
