:root {
  --terra-forest: #23463F;
  --earth-brown: #674A2B;
  --warm-cream: #F4F5ED;
  --soft-sage: #71A68C;
  --light-sage: #8CB4A1;
  --deep-cocoa: #302923;
  --olive-gray: #5B6B5F;
  --terra-gold: #A8934E;
  --white: #FFFFFF;
  --danger: #A13B3B;
  --warning: #B17820;
  --info: #366B80;
  --border: rgba(48, 41, 35, .12);
  --shadow: 0 18px 50px rgba(48, 41, 35, .10);
  --shadow-sm: 0 8px 24px rgba(48, 41, 35, .08);
  --radius-xl: 26px;
  --radius-lg: 18px;
  --radius-md: 13px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background: #eef1ec;
  color: var(--deep-cocoa);
  font-family: "Nunito Sans", Arial, sans-serif;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--olive-gray); }
.small { font-size: 13px; }
.text-right { text-align: right; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px 1fr; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--terra-forest); color: var(--warm-cream); padding: 22px 16px;
  display: flex; flex-direction: column; gap: 20px;
}
.brand-lockup { display: flex; align-items: center; gap: 12px; padding: 4px 8px 14px; }
.brand-lockup img { width: 56px; height: 68px; object-fit: contain; }
.brand-lockup strong { font-family: "Plus Jakarta Sans", sans-serif; font-size: 20px; letter-spacing: -.02em; display: block; }
.brand-lockup span { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .11em; opacity: .75; }
.nav-list { display: grid; gap: 7px; }
.nav-button {
  appearance: none; border: 0; color: rgba(244,245,237,.82); background: transparent;
  padding: 12px 14px; border-radius: 14px; display: flex; align-items: center; gap: 11px;
  text-align: left; font-weight: 800; transition: .18s ease;
}
.nav-button svg { width: 19px; height: 19px; }
.nav-button:hover, .nav-button.active { background: rgba(255,255,255,.12); color: #fff; transform: translateX(2px); }
.sidebar-bottom { margin-top: auto; display: grid; gap: 10px; }
.mode-badge { border: 1px solid rgba(255,255,255,.17); background: rgba(255,255,255,.08); border-radius: 14px; padding: 10px 12px; font-size: 12px; }
.mode-badge strong { display:block; color: #fff; }

.main-area { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: 76px; padding: 0 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  background: rgba(238,241,236,.9); backdrop-filter: blur(14px); border-bottom: 1px solid rgba(48,41,35,.08);
}
.topbar h1 { margin: 0; font-family: "Plus Jakarta Sans", sans-serif; color: var(--terra-forest); font-size: 22px; letter-spacing: -.03em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-chip { background: #fff; border: 1px solid var(--border); padding: 7px 11px; border-radius: 999px; font-size: 13px; font-weight: 800; }
.mobile-menu { display:none; }
.content { max-width: 1440px; margin: 0 auto; padding: 26px 28px 56px; }
.view-head { display:flex; align-items:flex-end; justify-content:space-between; gap:18px; margin-bottom: 20px; }
.view-head h2 { margin: 0; color: var(--terra-forest); font-family:"Plus Jakarta Sans", sans-serif; letter-spacing:-.035em; font-size: clamp(25px, 3vw, 38px); }
.view-head p { margin: 6px 0 0; color: var(--olive-gray); }
.actions { display:flex; flex-wrap:wrap; gap:9px; align-items:center; }

.btn {
  border: 0; border-radius: 999px; min-height: 40px; padding: 9px 16px; font-weight: 900;
  display: inline-flex; align-items: center; justify-content:center; gap: 8px; text-decoration:none;
  transition: .18s ease; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 7px 18px rgba(48,41,35,.12); }
.btn:disabled { opacity: .5; cursor:not-allowed; transform:none; box-shadow:none; }
.btn-primary { background: var(--earth-brown); color: #fff; }
.btn-secondary { background: var(--terra-forest); color: #fff; }
.btn-sage { background: var(--soft-sage); color: var(--terra-forest); }
.btn-light { background: #fff; color: var(--terra-forest); border: 1px solid var(--border); }
.btn-danger { background: #fff0ee; color: var(--danger); border: 1px solid rgba(161,59,59,.18); }
.btn-icon { width: 40px; padding: 0; border-radius: 50%; }
.btn svg { width: 18px; height: 18px; }

.card { background: rgba(255,255,255,.92); border: 1px solid rgba(48,41,35,.08); border-radius: var(--radius-xl); box-shadow: var(--shadow-sm); }
.card-pad { padding: 22px; }
.stats-grid { display:grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap:16px; margin-bottom:20px; }
.stat-card { padding: 20px; position:relative; overflow:hidden; min-height:126px; }
.stat-card::after { content:""; position:absolute; width:120px; height:120px; border:25px solid rgba(113,166,140,.13); border-radius:50%; right:-45px; top:-50px; }
.stat-label { color: var(--olive-gray); font-weight:800; font-size:13px; }
.stat-value { margin-top:8px; font:800 clamp(25px, 3vw, 38px)/1 "Plus Jakarta Sans", sans-serif; color:var(--terra-forest); }
.stat-note { margin-top:9px; color:var(--olive-gray); font-size:12px; }
.dashboard-grid { display:grid; grid-template-columns: minmax(0,1.5fr) minmax(300px,.7fr); gap:18px; }
.section-title { display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:14px; }
.section-title h3 { margin:0; color:var(--terra-forest); font:800 18px "Plus Jakarta Sans", sans-serif; }
.quick-actions { display:grid; gap:10px; }
.quick-action { display:flex; align-items:center; gap:13px; padding:14px; border:1px solid var(--border); border-radius:16px; background:#fff; text-decoration:none; font-weight:900; }
.quick-action:hover { border-color:var(--soft-sage); }
.quick-action .icon-bubble { width:42px; height:42px; display:grid; place-items:center; border-radius:14px; background:rgba(113,166,140,.18); color:var(--terra-forest); }

.toolbar { display:flex; flex-wrap:wrap; gap:10px; padding:14px; margin-bottom:14px; align-items:center; }
.filter-toolbar { align-items:flex-end; }
.filter-toolbar select { width:auto; min-width:160px; }
.date-filter { min-width:145px; }
.date-filter label { margin-bottom:3px; font-size:10px; letter-spacing:.06em; text-transform:uppercase; }
.search-box { flex:1; min-width:220px; position:relative; }
.search-box input { padding-left:42px; }
.search-box svg { position:absolute; left:14px; top:50%; transform:translateY(-50%); width:18px; color:var(--olive-gray); }
.form-control, input, select, textarea {
  width:100%; border:1px solid rgba(48,41,35,.16); background:#fff; color:var(--deep-cocoa);
  border-radius:12px; min-height:42px; padding:9px 12px; outline:none; transition:.16s ease;
}
textarea { min-height:90px; resize:vertical; }
input:focus, select:focus, textarea:focus { border-color:var(--soft-sage); box-shadow:0 0 0 4px rgba(113,166,140,.14); }
label { font-weight:900; color:var(--terra-forest); font-size:13px; display:block; margin-bottom:6px; }
.required::after { content:" *"; color:var(--danger); }
.form-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:15px; }
.form-grid-3 { grid-template-columns:repeat(3,minmax(0,1fr)); }
.form-grid-4 { grid-template-columns:repeat(4,minmax(0,1fr)); }
.form-field.full { grid-column:1/-1; }
.field-help { display:block; color:var(--olive-gray); font-size:12px; margin-top:5px; }
.checkbox-line { display:flex; align-items:center; gap:8px; min-height:42px; }
.checkbox-line input { width:auto; min-height:auto; }
.pet-field-head { display:flex; align-items:center; justify-content:space-between; gap:10px; }
.pet-field-head > span { color:var(--forest); font-size:12px; font-weight:800; }
.pet-multi-box { min-height:48px; padding:8px; border:1px solid var(--line); border-radius:12px; display:flex; flex-wrap:wrap; gap:8px; background:#fff; }
.pet-check { display:flex; align-items:center; gap:7px; padding:7px 10px; border:1px solid var(--line); border-radius:999px; background:var(--cream); cursor:pointer; user-select:none; }
.pet-check:has(input:checked) { border-color:var(--sage-dark); background:var(--sage-pale); box-shadow:0 0 0 2px rgba(105,153,126,.12); }
.pet-check input { width:auto; min-height:auto; margin:0; accent-color:var(--forest); }
.pet-check span { display:flex; align-items:baseline; gap:5px; }
.pet-check strong { color:var(--forest); font-size:13px; }
.pet-check small { color:var(--olive-gray); font-size:11px; }
.pet-add-button { margin-top:8px; }
.pet-register-links { display:flex; flex-wrap:wrap; gap:6px; }
.pet-link { display:inline-flex; align-items:center; gap:6px; border:1px solid #d8e5df; background:#eaf3ef; color:var(--terra-forest); padding:6px 9px; border-radius:999px; font-size:11px; font-weight:900; text-transform:uppercase; }
.pet-link svg { width:13px; height:13px; }
.pet-link:hover { border-color:var(--sage-dark); background:var(--sage-pale); }
.owner-link { border:0; background:transparent; padding:0; color:var(--terra-forest); font-weight:900; text-decoration:underline; text-decoration-color:rgba(35,70,63,.3); text-underline-offset:3px; }
.owner-link:hover { text-decoration-color:currentColor; }

.table-wrap { overflow:auto; border-radius:var(--radius-xl); }
table.data-table { width:100%; border-collapse:collapse; min-width:780px; }
.data-table th { text-align:left; background:#f1f3ef; color:var(--olive-gray); font-size:11px; letter-spacing:.08em; text-transform:uppercase; padding:13px 14px; position:sticky; top:0; }
.data-table td { padding:14px; border-top:1px solid rgba(48,41,35,.08); vertical-align:middle; }
.data-table tr:hover td { background:#fbfcfa; }
.table-main { font-weight:900; color:var(--terra-forest); }
.table-sub { color:var(--olive-gray); font-size:12px; margin-top:2px; }
.row-actions { display:flex; gap:6px; justify-content:flex-end; }
.mini-btn { border:1px solid var(--border); background:#fff; color:var(--terra-forest); min-width:34px; height:34px; border-radius:10px; display:grid; place-items:center; }
.mini-btn:hover { background:var(--warm-cream); }
.mini-btn.whatsapp-btn { color:#1f7a45; border-color:rgba(31,122,69,.24); background:#f1fbf4; }
.mini-btn.whatsapp-btn:hover { background:#ddf5e4; }
.archived-row { opacity:.72; }
.archived-row td { background:#f5f4f1; }

.status-pill { display:inline-flex; align-items:center; gap:6px; padding:5px 9px; border-radius:999px; font-size:11px; font-weight:900; text-transform:uppercase; letter-spacing:.04em; }
.status-pill::before { content:""; width:7px; height:7px; border-radius:50%; background:currentColor; }
.status-draft { background:#ececeb; color:#67645f; }
.status-issued { background:#e7f0ec; color:var(--terra-forest); }
.status-partial { background:#fff3d9; color:#8c5d00; }
.status-paid { background:#e2f4e7; color:#26743c; }
.status-overdue { background:#ffe6e4; color:#a13b3b; }
.status-cancelled { background:#f1e9e9; color:#805252; }

.empty-state { text-align:center; padding:50px 20px; color:var(--olive-gray); }
.empty-state .empty-icon { margin:0 auto 14px; width:60px; height:60px; border-radius:20px; background:rgba(113,166,140,.15); display:grid; place-items:center; color:var(--terra-forest); }
.empty-state h3 { color:var(--terra-forest); margin:0 0 5px; }

.content.invoice-editor-view { max-width:1760px; }
.invoice-editor-layout { display:grid; grid-template-columns:minmax(760px,1fr) minmax(500px,.62fr); gap:22px; align-items:start; }
.editor-panel { display:grid; gap:18px; min-width:0; }
.editor-section > h3 { margin:0 0 14px; color:var(--terra-forest); font:800 17px "Plus Jakarta Sans",sans-serif; }
.editor-panel .editor-section { overflow:hidden; margin:0; padding:0; border:1px solid rgba(48,41,35,.1); border-radius:20px; background:rgba(255,255,255,.96); box-shadow:var(--shadow-sm); }
.editor-section > summary::-webkit-details-marker { display:none; }
.editor-section-header { min-height:64px; padding:12px 16px; display:flex; align-items:center; justify-content:space-between; gap:16px; background:var(--terra-forest); color:#fff; cursor:pointer; list-style:none; user-select:none; }
.editor-section-title { min-width:0; display:flex; align-items:center; gap:12px; }
.editor-section-number { width:36px; height:36px; flex:0 0 36px; display:grid; place-items:center; border:1px solid rgba(255,255,255,.32); border-radius:11px; background:rgba(255,255,255,.1); font-size:11px; font-weight:900; letter-spacing:.08em; }
.editor-section-header h3 { margin:0; color:#fff; font:800 15px "Plus Jakarta Sans",sans-serif; }
.editor-section-header p { margin:2px 0 0; color:rgba(255,255,255,.72); font-size:11px; }
.editor-section-trailing { min-width:0; display:flex; align-items:center; gap:10px; }
.editor-section-action { flex:0 0 auto; }
.editor-section-action .btn-light { background:#fff; }
.editor-section-chevron { width:24px; flex:0 0 24px; font-size:20px; text-align:center; transition:transform .18s ease; }
.editor-section[open] .editor-section-chevron { transform:rotate(180deg); }
.editor-section-body { padding:18px; }
.invoice-category-list { display:grid; gap:12px; }
.invoice-item-entry { display:flex; align-items:flex-end; gap:10px; margin-bottom:16px; padding:14px; border:1px solid rgba(35,70,63,.14); border-radius:15px; background:#edf3ef; }
.invoice-item-entry .service-search { flex:1; }
.invoice-item-entry .btn { margin-bottom:22px; }
.invoice-items-empty { min-height:110px; display:grid; place-content:center; gap:4px; padding:22px; border:1px dashed rgba(48,41,35,.2); border-radius:16px; background:#f8faf8; text-align:center; color:var(--olive-gray); }
.invoice-items-empty strong { color:var(--terra-forest); }
.invoice-items-empty span { font-size:12px; }
.invoice-category-editor { overflow:hidden; border:1px solid var(--border); border-radius:16px; background:#f8faf8; }
.invoice-category-editor > summary { min-height:58px; padding:10px 14px; display:grid; grid-template-columns:34px minmax(0,1fr) 24px; gap:10px; align-items:center; color:var(--terra-forest); cursor:pointer; list-style:none; user-select:none; }
.invoice-category-editor > summary::-webkit-details-marker { display:none; }
.invoice-category-editor[open] > summary { background:#e7efe9; border-bottom:1px solid var(--border); }
.category-order-number { width:30px; height:30px; display:grid; place-items:center; border-radius:9px; background:var(--terra-forest); color:#fff; font-size:10px; font-weight:900; }
.category-summary-copy { min-width:0; display:grid; gap:1px; }
.category-summary-copy strong { font:800 13px "Plus Jakarta Sans",sans-serif; }
.category-summary-copy small { color:var(--olive-gray); font-size:10px; }
.category-expand-indicator { font-size:20px; text-align:center; transition:transform .18s ease; }
.invoice-category-editor[open] .category-expand-indicator { transform:rotate(180deg); }
.invoice-category-body { padding:12px; }
.category-empty-state { padding:16px; border:1px dashed rgba(48,41,35,.16); border-radius:12px; text-align:center; color:var(--olive-gray); font-size:12px; background:#fff; }
.invoice-lines { display:grid; gap:12px; }
.invoice-line { overflow:hidden; border:1px solid rgba(48,41,35,.14); border-radius:15px; background:#fff; box-shadow:0 4px 12px rgba(48,41,35,.04); }
.invoice-line > summary::-webkit-details-marker { display:none; }
.invoice-line-header { min-height:48px; padding:8px 10px; display:flex; align-items:center; justify-content:space-between; gap:12px; background:#f2f5f1; cursor:pointer; list-style:none; user-select:none; }
.invoice-line[open] > .invoice-line-header { border-bottom:1px solid var(--border); }
.invoice-line-identity { min-width:0; display:flex; align-items:center; gap:9px; }
.invoice-line-number { width:28px; height:28px; flex:0 0 28px; display:grid; place-items:center; border-radius:8px; background:#fff; border:1px solid var(--border); color:var(--terra-forest); font-size:10px; font-weight:900; }
.invoice-line-identity > div { min-width:0; display:grid; }
.invoice-line-identity strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:var(--terra-forest); font-size:13px; }
.invoice-line-identity small { color:var(--olive-gray); font-size:10px; }
.invoice-line-header-tools { min-width:0; display:flex; align-items:center; justify-content:flex-end; gap:9px; }
.line-compact-summary { min-width:0; display:flex; align-items:center; justify-content:flex-end; gap:6px; flex-wrap:wrap; color:var(--olive-gray); font-size:10px; }
.line-compact-summary span { padding:4px 7px; border-radius:999px; background:#fff; border:1px solid rgba(48,41,35,.1); white-space:nowrap; }
.line-compact-summary strong { min-width:82px; color:var(--terra-forest); font-size:11px; text-align:right; white-space:nowrap; }
.invoice-line-expand-indicator { width:22px; flex:0 0 22px; color:var(--terra-forest); font-size:18px; text-align:center; transition:transform .18s ease; }
.invoice-line[open] .invoice-line-expand-indicator { transform:rotate(180deg); }
.invoice-line-fields { padding:12px; display:grid; grid-template-columns:minmax(210px,1.45fr) minmax(130px,.85fr) minmax(80px,.45fr) minmax(125px,.75fr) minmax(120px,.7fr); gap:10px; align-items:start; }
.invoice-line .form-field { min-width:0; }
.invoice-line .form-field label { min-height:19px; }
.invoice-line .line-total { min-height:42px; display:flex; align-items:center; justify-content:flex-end; border:1px solid rgba(35,70,63,.14); border-radius:12px; background:#edf3ef; font-weight:900; color:var(--terra-forest); padding:8px 10px; white-space:nowrap; }
.invoice-line input[readonly] { background:#eef1ed; color:var(--terra-forest); font-weight:800; cursor:not-allowed; }
.line-actions { display:flex; gap:4px; align-items:center; }
.line-actions .mini-btn { min-width:30px; width:30px; }
.line-description { padding:0 12px 12px; }
.line-relation-options { display:grid; grid-template-columns:minmax(230px,.8fr) minmax(300px,1.6fr); gap:14px; align-items:start; padding:12px; border-top:1px dashed var(--border); background:#fbfcfa; }
.tier-line { align-self:start; min-height:42px; margin:0; padding:9px 11px; border-radius:11px; background:#e8f1eb; }
.line-pet-targets > span { display:block; margin-bottom:6px; font-size:12px; font-weight:800; color:var(--terra-forest); }
.pet-target-checks { display:flex; flex-wrap:wrap; gap:6px; }
.pet-target-check { display:inline-flex; align-items:center; gap:6px; padding:6px 9px; border:1px solid var(--border); border-radius:999px; background:#fff; font-size:12px; font-weight:700; cursor:pointer; }
.pet-target-check:has(input:checked) { border-color:#6f927e; background:#e5f1ea; color:var(--terra-forest); }
.category-chip { display:inline-flex; width:max-content; margin-top:5px; padding:3px 7px; border-radius:999px; background:#e7eee9; color:#365d51; font-size:10px; font-weight:800; }
.medical-service-picker { max-height:280px; overflow:auto; display:grid; gap:10px; padding:10px; border:1px solid var(--border); border-radius:12px; background:#f8faf8; }
.medical-service-group > strong { display:block; margin-bottom:6px; color:var(--terra-forest); font-size:12px; }
.medical-service-options { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:6px; }
.medical-service-check { display:flex; align-items:center; gap:8px; padding:8px; border:1px solid var(--border); border-radius:10px; background:#fff; cursor:pointer; }
.medical-service-check:has(input:checked) { border-color:#6f927e; background:#e5f1ea; }
.medical-service-check span { display:grid; gap:2px; font-size:12px; font-weight:700; }
.medical-service-check small { color:var(--muted); font-weight:500; }
.add-line-bar { display:flex; gap:10px; margin-top:10px; }
.service-search { flex:1; min-width:0; }
.service-search input { width:100%; }
.totals-box { margin-left:auto; max-width:400px; display:grid; gap:8px; }
.finalization-totals { margin-top:18px; padding:16px; border-radius:15px; background:#f2f5f1; }
.total-row { display:grid; grid-template-columns:1fr 150px; gap:12px; align-items:center; }
.total-row strong { text-align:right; color:var(--terra-forest); }
.total-row.grand { padding-top:10px; border-top:2px solid var(--terra-forest); font-size:18px; }
.preview-panel { position:sticky; top:96px; }
.preview-toolbar { display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap; padding:12px; }
.preview-actions, .preview-zoom-controls { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.preview-zoom-controls { margin-left:auto; }
.preview-zoom-controls span { min-width:44px; text-align:center; font-size:12px; font-weight:900; color:var(--terra-forest); }
.preview-zoom-controls .zoom-fit { width:auto; padding:0 9px; }
.preview-frame { padding:14px; background:#dfe4de; border-radius:0 0 var(--radius-xl) var(--radius-xl); max-height:calc(100vh - 190px); overflow:auto; }
.preview-scale { position:relative; margin:0 auto; flex:0 0 auto; }
.preview-scale .terra-invoice-document { width:794px; display:grid; gap:24px; transform-origin:top left; }
.preview-scale .terra-invoice { width:794px; height:1123px; }
.invoice-modal-preview { max-height:650px; overflow:auto; padding:14px; border-radius:18px; background:#dfe4de; }
.invoice-modal-document { width:794px; margin:0 auto; zoom:.58; }

.modal-backdrop { position:fixed; inset:0; z-index:100; background:rgba(25,32,29,.55); backdrop-filter:blur(6px); display:grid; place-items:center; padding:18px; }
.modal { width:min(720px,100%); max-height:92vh; overflow:auto; background:#fff; border-radius:26px; box-shadow:0 30px 90px rgba(0,0,0,.25); }
.modal-lg { width:min(940px,100%); }
.modal-head { padding:20px 22px; border-bottom:1px solid var(--border); display:flex; align-items:center; justify-content:space-between; gap:12px; }
.modal-head h3 { margin:0; color:var(--terra-forest); font:800 20px "Plus Jakarta Sans",sans-serif; }
.modal-body { padding:22px; }
.modal-foot { padding:16px 22px; border-top:1px solid var(--border); display:flex; justify-content:flex-end; gap:9px; position:sticky; bottom:0; background:#fff; }
.close-btn { border:0; background:#f1f3ef; width:38px; height:38px; border-radius:50%; font-size:20px; }
.form-section-label { margin:2px 0 13px; padding-bottom:8px; border-bottom:1px solid var(--border); color:var(--terra-forest); font:800 15px "Plus Jakarta Sans",sans-serif; }
.form-section-label:not(:first-child) { margin-top:24px; }
.client-name-grid { grid-template-columns:minmax(130px,.35fr) minmax(220px,1fr); }
.client-notes { margin-top:18px; }
.danger-callout { display:flex; gap:12px; padding:15px; border:1px solid rgba(161,59,59,.2); border-radius:15px; background:#fff4f2; color:var(--danger); }
.danger-callout svg { flex:0 0 22px; width:22px; margin-top:2px; }
.danger-callout strong { display:block; }
.danger-callout p { margin:4px 0 0; color:#6d4c48; line-height:1.5; }
.archive-confirm { display:grid; gap:12px; margin-top:18px; }
.archive-confirm .checkbox-line { justify-content:flex-start; }
.archive-confirm .checkbox-line input { flex:0 0 auto; }
.backup-file-info { display:grid; gap:3px; margin-bottom:16px; padding:14px 16px; border:1px solid var(--border); border-radius:15px; background:#f5f7f3; }
.backup-file-info span, .backup-file-info small { color:var(--olive-gray); font-size:11px; }
.backup-file-info strong { overflow-wrap:anywhere; color:var(--terra-forest); }
.backup-compare { display:grid; grid-template-columns:minmax(0,1fr) 34px minmax(0,1fr); gap:12px; align-items:center; margin-bottom:16px; }
.backup-compare section { min-width:0; padding:14px; border:1px solid var(--border); border-radius:16px; background:#fbfcfa; }
.backup-compare h4 { margin:0 0 10px; color:var(--terra-forest); font:800 13px "Plus Jakarta Sans",sans-serif; }
.backup-compare-arrow { display:grid; place-items:center; color:var(--soft-sage); font-size:24px; font-weight:900; }
.backup-summary-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:7px; }
.backup-summary-grid div { min-width:0; padding:8px; border-radius:10px; background:#edf3ef; }
.backup-summary-grid span { display:block; overflow:hidden; color:var(--olive-gray); font-size:9px; font-weight:800; text-overflow:ellipsis; white-space:nowrap; }
.backup-summary-grid strong { display:block; margin-top:2px; color:var(--terra-forest); font-size:15px; }
.import-confirm { display:grid; gap:12px; margin-top:16px; }
.import-confirm .checkbox-line { justify-content:flex-start; }
.import-confirm .checkbox-line input { flex:0 0 auto; }
.patient-summary { display:grid; grid-template-columns:repeat(4,1fr); gap:10px; padding:14px; margin-bottom:18px; border-radius:16px; background:#e7f0ec; }
.patient-summary div { display:flex; flex-direction:column; gap:3px; }
.patient-summary span { color:var(--olive-gray); font-size:10px; font-weight:800; text-transform:uppercase; letter-spacing:.07em; }
.patient-summary strong { color:var(--terra-forest); }
.medical-layout { display:grid; grid-template-columns:minmax(0,1fr) minmax(280px,.85fr); gap:20px; align-items:start; }
.medical-layout h4 { margin:0 0 14px; color:var(--terra-forest); font:800 16px "Plus Jakarta Sans",sans-serif; }
.medical-form { display:grid; gap:14px; }
.medical-section { min-width:0; margin:0; padding:16px; border:1px solid var(--border); border-radius:18px; background:#fbfcfa; }
.medical-section legend { padding:0 7px; color:var(--terra-forest); font:800 14px "Plus Jakarta Sans",sans-serif; }
.medical-history { max-height:580px; overflow:auto; padding-right:4px; }
.medical-entry { padding:14px; margin-bottom:10px; border:1px solid var(--border); border-radius:15px; background:#fff; }
.medical-entry-head { display:flex; justify-content:space-between; align-items:flex-start; gap:10px; }
.medical-entry-head > div { display:flex; flex-direction:column; gap:2px; }
.medical-entry-head strong { color:var(--terra-forest); }
.medical-entry-head span { color:var(--olive-gray); font-size:11px; }
.medical-entry p { margin:10px 0 0; font-size:13px; line-height:1.5; }
.medical-entry-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:8px; margin-top:10px; }
.medical-entry-grid div { display:flex; flex-direction:column; padding:8px; border-radius:10px; background:#f3f5f1; }
.medical-entry-grid span { color:var(--olive-gray); font-size:9px; font-weight:900; letter-spacing:.06em; text-transform:uppercase; }
.medical-entry-grid strong { margin-top:2px; font-size:11px; color:var(--terra-forest); }
.relationship-arrow { display:inline-block; margin:0 5px; color:var(--soft-sage); font-weight:900; }
.follow-up-box { display:flex; flex-direction:column; gap:3px; margin-top:11px; padding:10px; border-radius:11px; background:#fff3d9; color:#704d0a; font-size:12px; }
.empty-medical { padding:26px 15px; text-align:center; border:1px dashed var(--border); border-radius:15px; color:var(--olive-gray); }

.toast-stack { position:fixed; right:20px; bottom:20px; z-index:200; display:grid; gap:10px; width:min(380px,calc(100vw - 40px)); }
.toast { background:#fff; border:1px solid var(--border); border-left:6px solid var(--terra-forest); border-radius:14px; box-shadow:var(--shadow); padding:13px 15px; animation:toastIn .25s ease; }
.toast.error { border-left-color:var(--danger); }
.toast.success { border-left-color:#2b8645; }
.toast strong { display:block; margin-bottom:2px; }
@keyframes toastIn { from { opacity:0; transform:translateY(10px); } }
.loading-overlay { position:fixed; inset:0; z-index:300; background:rgba(244,245,237,.74); backdrop-filter:blur(4px); display:grid; place-items:center; }
.loader-card { background:#fff; padding:20px 24px; border-radius:18px; box-shadow:var(--shadow); display:flex; align-items:center; gap:12px; font-weight:900; color:var(--terra-forest); }
.spinner { width:22px; height:22px; border:3px solid rgba(35,70,63,.18); border-top-color:var(--terra-forest); border-radius:50%; animation:spin .8s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }

.auth-page { min-height:100vh; display:grid; grid-template-columns:1fr 1fr; background:var(--warm-cream); }
.auth-visual { padding:60px; background:linear-gradient(135deg,var(--terra-forest),#17322d); color:#fff; position:relative; overflow:hidden; display:flex; flex-direction:column; justify-content:space-between; }
.auth-visual::after { content:""; width:520px; height:520px; border:60px solid rgba(113,166,140,.2); border-radius:50%; position:absolute; right:-230px; top:-190px; }
.auth-visual img { width:170px; position:relative; z-index:1; }
.auth-visual h1 { font:800 clamp(38px,5vw,68px)/1.02 "Plus Jakarta Sans",sans-serif; margin:20px 0; position:relative; z-index:1; }
.auth-visual p { max-width:520px; font-size:18px; color:rgba(255,255,255,.78); position:relative; z-index:1; }
.auth-form-wrap { display:grid; place-items:center; padding:30px; }
.auth-card { width:min(440px,100%); background:#fff; padding:30px; border-radius:28px; box-shadow:var(--shadow); }
.auth-card h2 { margin:0 0 7px; color:var(--terra-forest); font:800 28px "Plus Jakarta Sans",sans-serif; }
.auth-card form { display:grid; gap:15px; margin-top:22px; }
.auth-switch { margin-top:18px; text-align:center; color:var(--olive-gray); }
.link-button { border:0; background:transparent; color:var(--terra-forest); font-weight:900; padding:0; }

/* A4 invoice artwork */
.pdf-render-host { position:fixed; left:-10000px; top:0; width:794px; z-index:-1; }
.terra-invoice-document { width:794px; display:grid; gap:24px; }
.pdf-render-host .terra-invoice-document { gap:0; }
.terra-invoice {
  --inv-forest:#23463F; --inv-brown:#674A2B; --inv-cream:#F4F5ED; --inv-sage:#6f927e; --inv-gray:#d9dcd8; --inv-text:#302923;
  width:794px; height:1123px; position:relative; overflow:hidden; background:#fbfbf7; color:var(--inv-text);
  font-family:"Nunito Sans",Arial,sans-serif; padding:68px 72px 56px; box-shadow:0 14px 40px rgba(48,41,35,.18);
}
.terra-invoice * { box-sizing:border-box; }
.terra-invoice::before { content:""; position:absolute; inset:0 0 auto; height:18px; background:linear-gradient(90deg,var(--inv-forest) 0 68%,var(--inv-sage) 68% 84%,var(--inv-brown) 84%); z-index:1; }
.terra-invoice::after { content:""; position:absolute; left:0; top:18px; bottom:0; width:9px; background:linear-gradient(180deg,rgba(111,146,126,.75),rgba(111,146,126,.08)); z-index:1; }
.terra-invoice .corner, .terra-invoice .stripe { display:none; }
.terra-invoice .corner { position:absolute; background:#8f6f60; z-index:0; }
.corner-top-left { left:-85px; top:-75px; width:360px; height:170px; transform:rotate(15deg); clip-path:polygon(0 0,100% 0,70% 100%,0 100%); }
.corner-top-right { right:-75px; top:-90px; width:310px; height:160px; transform:rotate(-10deg); clip-path:polygon(25% 0,100% 0,100% 100%,0 45%); }
.corner-bottom-left { left:-100px; bottom:-100px; width:370px; height:160px; transform:rotate(8deg); clip-path:polygon(0 0,68% 42%,100% 100%,0 100%); }
.corner-bottom-right { right:-85px; bottom:-60px; width:310px; height:185px; transform:rotate(-4deg); clip-path:polygon(35% 0,100% 0,100% 100%,0 100%); }
.terra-invoice .stripe { position:absolute; height:10px; background:#d9dcd8; z-index:1; }
.stripe-top { top:63px; left:-10px; width:830px; transform:rotate(8deg); box-shadow:0 14px 0 #fff; }
.stripe-bottom { bottom:58px; left:-10px; width:830px; transform:rotate(10deg); box-shadow:0 -14px 0 #fff; }
.invoice-header, .invoice-meta, .invoice-continuation-meta, .invoice-items-wrap, .invoice-continuation-notice, .invoice-summary, .invoice-footer, .invoice-thanks, .invoice-page-number { position:relative; z-index:2; }
.invoice-header { display:flex; align-items:center; justify-content:space-between; gap:30px; padding-bottom:18px; border-bottom:1px solid #dfe5e1; }
.invoice-kicker { font-size:8px; font-weight:900; letter-spacing:.2em; color:var(--inv-sage); margin-bottom:8px; }
.invoice-header h1 { margin:0; font:800 39px/1 "Plus Jakarta Sans",sans-serif; color:#383936; letter-spacing:-.04em; }
.invoice-logo { display:block; width:110px; height:137px; object-fit:contain; margin:0; flex:0 0 auto; }
.invoice-header-continuation { padding-bottom:12px; }
.invoice-header-continuation h1 { display:flex; align-items:baseline; gap:11px; font-size:31px; }
.invoice-header-continuation h1 span { color:var(--inv-sage); font-size:12px; letter-spacing:.13em; }
.invoice-header-continuation .invoice-logo { width:72px; height:82px; }
.invoice-continuation-meta { margin-top:14px; padding:10px 12px; display:grid; grid-template-columns:1.3fr 1fr .75fr; gap:16px; border:1px solid #dfe5e1; border-radius:7px; background:#f5f7f3; }
.invoice-continuation-meta div { min-width:0; display:grid; gap:2px; }
.invoice-continuation-meta span { color:#61736a; font-size:8px; font-weight:900; letter-spacing:.09em; text-transform:uppercase; }
.invoice-continuation-meta strong { overflow:hidden; color:var(--inv-forest); font-size:11px; text-overflow:ellipsis; white-space:nowrap; }
.invoice-meta { margin-top:24px; display:grid; grid-template-columns:1fr 1fr; gap:35px; min-height:125px; }
.invoice-recipient { display:flex; flex-direction:column; align-items:flex-start; font-size:12px; line-height:1.35; }
.micro-label { font-size:8px; letter-spacing:.17em; font-weight:900; margin-bottom:8px; }
.invoice-recipient strong { font-size:13px; }
.invoice-pet-list { margin-top:4px; max-width:100%; }
.invoice-pet-count { margin-top:2px; color:var(--inv-forest); font-weight:800; }
.invoice-number-block { justify-self:end; width:260px; font-size:12px; padding-top:25px; position:relative; }
.invoice-number-block > div:not(.paid-stamp) { display:grid; grid-template-columns:88px 1fr; gap:8px; margin-bottom:6px; }
.invoice-number-block span { color:#48615c; }
.invoice-number-block strong { text-align:right; color:var(--inv-forest); }
.paid-stamp { position:absolute; right:0; top:-18px; border:3px solid #2d7c43; color:#2d7c43; border-radius:9px; padding:6px 13px; transform:rotate(-7deg); font:900 20px "Plus Jakarta Sans",sans-serif; opacity:.85; }
.invoice-items-wrap { margin-top:9px; min-height:310px; }
.invoice-items { width:100%; border-collapse:collapse; table-layout:fixed; font-size:11px; }
.invoice-items th { background:#6f927e; color:#fff; padding:10px 11px; text-align:left; font-weight:900; }
.invoice-items th:first-child { width:37%; }
.invoice-items th:nth-child(2) { width:17%; text-align:right; }
.invoice-items th:nth-child(3) { width:12%; text-align:center; }
.invoice-items th:nth-child(4) { width:16%; text-align:right; }
.invoice-items th:nth-child(5) { width:18%; text-align:right; }
.invoice-items td { padding:8px 11px; border-bottom:1px solid rgba(48,41,35,.07); vertical-align:top; }
.invoice-items td strong { display:block; font-weight:800; }
.invoice-items td small { display:block; color:#6b746e; margin-top:2px; }
.invoice-items .invoice-category-row td { padding:6px 11px; border-bottom:0; background:#edf3ef; color:#31594d; font-size:10px; font-weight:900; letter-spacing:.08em; text-transform:uppercase; }
.invoice-items .invoice-category-row span { font-size:8px; opacity:.7; }
.invoice-items .invoice-item-target { color:#31594d; font-weight:700; }
.invoice-items .invoice-tier-note { font-size:9px; }
.invoice-items td.num { text-align:right; }
.invoice-items td.qty { text-align:center; }
.empty-row { text-align:center; padding:35px !important; color:#7d817e; }
.invoice-continuation-notice { min-height:44px; margin-top:14px; padding:9px 44px 9px 12px; display:grid; gap:1px; border:1px solid rgba(49,89,77,.2); border-radius:7px; background:#edf3ef; color:var(--inv-forest); }
.invoice-continuation-notice strong { font-size:11px; }
.invoice-continuation-notice span { color:#526862; font-size:9px; }
.invoice-continuation-notice b { position:absolute; right:14px; top:50%; transform:translateY(-50%); font-size:22px; }
.invoice-summary { background:#d8dad7; min-height:38px; padding:8px 14px; display:grid; gap:4px; }
.summary-row { display:grid; grid-template-columns:1fr auto; gap:15px; align-items:center; font-size:9px; letter-spacing:.1em; font-weight:900; }
.summary-row strong { letter-spacing:0; font-size:11px; }
.summary-row.total { border-top:1px solid rgba(48,41,35,.18); padding-top:5px; font-size:11px; }
.summary-row.total strong { font-size:15px; color:var(--inv-forest); }
.summary-row.balance { color:#a13b3b; }
.invoice-footer { margin-top:28px; display:grid; grid-template-columns:1fr 1fr; gap:35px; font-size:10px; min-height:155px; }
.payment-info, .practice-info { display:flex; flex-direction:column; align-items:flex-start; line-height:1.45; }
.payment-info strong { font-size:11px; }
.practice-info { align-items:flex-end; text-align:right; justify-self:end; max-width:270px; }
.practice-info strong { font-size:9px; color:var(--inv-forest); }
.invoice-note { margin-top:11px; max-width:300px; }
.invoice-thanks { text-align:center; font-size:8px; color:#61736a; margin-top:7px; }
.invoice-page-number { position:absolute; left:72px; right:72px; bottom:24px; display:flex; align-items:center; justify-content:space-between; gap:20px; padding-top:7px; border-top:1px solid #dfe5e1; color:#61736a; font-size:8px; letter-spacing:.06em; }
.invoice-page-number strong { color:var(--inv-forest); font-size:9px; }
.invoice-watermark { position:absolute; z-index:5; left:50%; top:50%; transform:translate(-50%,-50%) rotate(-26deg); font:900 92px "Plus Jakarta Sans",sans-serif; color:rgba(103,74,43,.09); border:8px solid rgba(103,74,43,.07); padding:8px 20px; border-radius:15px; pointer-events:none; }
.terra-invoice.pdf-mode { box-shadow:none; }

@media print {
  body * { visibility:hidden; }
  #invoice-print-area, #invoice-print-area * { visibility:visible; }
  #invoice-print-area { position:absolute; left:0; top:0; display:block; transform:none !important; box-shadow:none; }
  #invoice-print-area .terra-invoice { page-break-after:always; break-after:page; box-shadow:none; }
  #invoice-print-area .terra-invoice:last-child { page-break-after:auto; break-after:auto; }
}

@media (max-width: 1680px) {
  .invoice-editor-layout { grid-template-columns:1fr; }
  .preview-panel { position:relative; top:auto; }
  .preview-frame { max-height:none; }
}
@media (max-width: 1180px) {
  .stats-grid { grid-template-columns:repeat(2,1fr); }
}
@media (max-width: 860px) {
  .app-shell { grid-template-columns:1fr; }
  .sidebar { position:fixed; z-index:60; left:-280px; width:260px; transition:.2s ease; box-shadow:20px 0 60px rgba(0,0,0,.2); }
  .sidebar.open { left:0; }
  .mobile-menu { display:inline-flex; }
  .topbar { padding:0 16px; height:68px; }
  .content { padding:20px 15px 100px; }
  .topbar h1 { font-size:18px; }
  .dashboard-grid { grid-template-columns:1fr; }
  .view-head { align-items:flex-start; flex-direction:column; }
  .form-grid, .form-grid-3, .form-grid-4 { grid-template-columns:1fr; }
  .form-field.full { grid-column:auto; }
  .auth-page { grid-template-columns:1fr; }
  .auth-visual { display:none; }
  .medical-layout, .patient-summary { grid-template-columns:1fr; }
  .medical-history { max-height:none; }
  .invoice-line-fields { grid-template-columns:1fr 1fr; }
  .invoice-line .item-select-field { grid-column:1/-1; }
  .line-relation-options { grid-template-columns:1fr; }
  .medical-service-options { grid-template-columns:1fr; }
  .line-actions { grid-column:1/-1; justify-self:end; }
  .add-line-bar { align-items:flex-end; }
  .user-chip { display:none; }
}
@media (max-width: 560px) {
  .stats-grid { grid-template-columns:1fr; }
  .stat-card { min-height:105px; }
  .actions { width:100%; }
  .actions .btn { flex:1; }
  .toolbar > select { width:100%; }
  .filter-toolbar select, .date-filter { width:100%; min-width:0; }
  .modal-backdrop { padding:0; align-items:end; }
  .modal { border-radius:26px 26px 0 0; max-height:94vh; }
  .modal-foot { flex-wrap:wrap; }
  .modal-foot .btn { flex:1; }
  .preview-toolbar { align-items:flex-start; }
  .preview-zoom-controls { margin-left:0; }
  .total-row { grid-template-columns:1fr 125px; }
  .invoice-line-fields { grid-template-columns:1fr; }
  .invoice-line .item-select-field { grid-column:auto; }
  .editor-section-header { align-items:flex-start; }
  .editor-section-action { width:100%; }
  .editor-section-action .btn { width:100%; }
  .editor-section-header { flex-wrap:wrap; }
  .invoice-item-entry { align-items:stretch; flex-direction:column; }
  .invoice-item-entry .btn { margin-bottom:0; width:100%; }
  .backup-compare { grid-template-columns:1fr; }
  .backup-compare-arrow { transform:rotate(90deg); }
  .backup-summary-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
}
