:root {
  --ink: #193935;
  --muted: #70817d;
  --canvas: #f7f7f2;
  --card: #fffef9;
  --line: #dce3d9;
  --accent: #badb58;
  --accent-dark: #5d7d1b;
  --danger: #b84e45;
  --warning: #be791f;
  --shadow: 0 14px 38px rgba(27, 57, 52, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
.auth-page { min-height: 100vh; min-height: 100svh; padding: 24px; display: grid; place-items: center; background: #fff; }
.auth-loading { color: var(--muted); font-size: 14px; }
.auth-panel { width: min(100%, 440px); padding: 32px; border: 1px solid var(--line); border-radius: 16px; background: #fff; box-shadow: 0 12px 40px rgba(27,57,52,.06); }
.auth-panel h1 { font-size: 24px; letter-spacing: -.8px; margin-bottom: 8px; }
.auth-panel > p { color: var(--muted); font-size: 13px; margin-bottom: 26px; }
.auth-logo { width: 210px; max-width: 100%; height: auto; display: block; margin-bottom: 26px; }
.auth-form { display: grid; gap: 18px; }
.auth-form .button { width: 100%; }
.auth-form .fiscal-error { min-height: 16px; margin: 0; font-size: 13px; }
#account-form .field { align-content: start; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: flex; }
.sidebar { width: 238px; background: var(--ink); color: #eef3e9; display: flex; flex-direction: column; padding: 28px 14px 20px; position: fixed; inset: 0 auto 0 0; }
.brand { display: flex; align-items: center; gap: 10px; color: #fffef9; text-decoration: none; font-size: 25px; font-weight: 760; letter-spacing: -1.4px; padding: 0 12px 36px; }
.brand-mark { display: grid; place-items: center; width: 31px; height: 31px; background: var(--accent); color: var(--ink); border-radius: 9px; font-size: 19px; letter-spacing: -1px; }
.brand-dot { color: var(--accent); }
.nav-links { display: grid; gap: 5px; }
.nav-link { border: 0; background: transparent; color: #aec1bb; padding: 12px 13px; border-radius: 9px; text-align: left; font-size: 14px; font-weight: 620; display: flex; gap: 13px; align-items: center; transition: .15s ease; }
.nav-link:hover { background: rgba(255,255,255,.08); color: white; }
.nav-link.active { color: var(--ink); background: var(--accent); }
.nav-icon { width: 17px; font-size: 18px; text-align: center; line-height: 1; }
.sidebar-footer { margin-top: auto; padding: 14px 12px 0; font-size: 12px; color: #a3b4af; border-top: 1px solid rgba(255,255,255,.12); }
.connection-dot { display: inline-block; width: 7px; height: 7px; background: var(--accent); border-radius: 50%; margin-right: 6px; }

.main-content { width: 100%; margin-left: 238px; padding: 36px clamp(24px, 4vw, 64px) 56px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 32px; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 11px; letter-spacing: .13em; font-weight: 760; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(25px, 3vw, 34px); letter-spacing: -1.6px; margin-bottom: 0; line-height: 1.1; }
h2 { font-size: 18px; letter-spacing: -.6px; margin-bottom: 4px; }
h3 { font-size: 14px; margin-bottom: 0; }
.topbar-actions, .stack-row, .filter-row { display: flex; align-items: center; gap: 10px; }
.button, .icon-button { border: 1px solid var(--line); background: var(--card); color: var(--ink); min-height: 40px; padding: 0 15px; border-radius: 9px; font-weight: 680; font-size: 13px; transition: .15s ease; }
.button:hover, .icon-button:hover { transform: translateY(-1px); border-color: #bccabd; }
.button-primary { border-color: var(--ink); background: var(--ink); color: white; box-shadow: 0 4px 0 #0c2520; }
.button-primary:hover { background: #264c46; }
.button-accent { border-color: var(--accent); background: var(--accent); color: var(--ink); }
.button-danger { color: var(--danger); border-color: #e9c7c4; background: #fff8f7; }
.button-small { min-height: 31px; padding: 0 10px; font-size: 12px; }
.button:disabled, .button:disabled:hover { cursor: not-allowed; transform: none; opacity: .56; border-color: var(--line); box-shadow: none; }
.icon-button { width: 40px; padding: 0; font-size: 20px; }

.dashboard-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.metric-card { background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); padding: 20px; border-radius: 14px; min-height: 132px; position: relative; overflow: hidden; }
.metric-card::after { content: ''; width: 78px; height: 78px; position: absolute; right: -26px; bottom: -31px; border-radius: 50%; background: rgba(186,219,88,.25); }
.metric-card.alert::after { background: rgba(184,78,69,.13); }
.metric-label { color: var(--muted); font-size: 12px; font-weight: 650; }
.metric-value { margin: 16px 0 3px; font-size: clamp(23px, 2.6vw, 31px); letter-spacing: -1.5px; line-height: 1; }
.metric-hint { color: var(--muted); font-size: 12px; }
.section-card { border: 1px solid var(--line); background: var(--card); border-radius: 14px; box-shadow: var(--shadow); margin-top: 26px; overflow: hidden; }
.section-head { padding: 19px 21px; display: flex; justify-content: space-between; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.section-subtitle { font-size: 12px; color: var(--muted); margin: 4px 0 0; }
.link-button { border: 0; color: var(--accent-dark); background: transparent; font-size: 12px; font-weight: 720; padding: 6px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th { text-align: left; color: var(--muted); font-size: 11px; letter-spacing: .07em; text-transform: uppercase; padding: 12px 20px; background: #fbfcf8; white-space: nowrap; }
td { padding: 14px 20px; border-top: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
tr.data-row { cursor: pointer; }
tr.data-row:hover td { background: #fbfdf3; }
.primary-cell { font-weight: 700; }
.secondary-cell { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.amount { font-weight: 730; white-space: nowrap; text-align: right; }
.align-right { text-align: right; }
.status { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 100px; font-size: 11px; font-weight: 720; white-space: nowrap; }
.status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-paid { color: #3e7e61; background: #e7f4eb; }
.status-partial { color: #a76c19; background: #fff3d9; }
.status-open { color: #4f6c66; background: #eaf0ed; }
.status-overdue { color: #a3443e; background: #fbe9e7; }
.status-proforma { color: #697332; background: #eff4d8; }
.empty { text-align: center; padding: 58px 22px; color: var(--muted); }
.empty-icon { display: grid; place-items: center; margin: 0 auto 13px; width: 40px; height: 40px; background: #e9efdf; color: var(--accent-dark); border-radius: 12px; font-size: 21px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.toolbar-left { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search-box { position: relative; }
.search-box::before { content: '⌕'; color: var(--muted); position: absolute; left: 12px; top: 8px; font-size: 18px; }
.search-box input { border: 1px solid var(--line); border-radius: 9px; background: var(--card); min-height: 38px; padding: 0 12px 0 34px; color: var(--ink); outline: none; width: min(280px, 52vw); }
.search-box input:focus, .field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent-dark); box-shadow: 0 0 0 3px rgba(186,219,88,.24); }
.filter-button { min-height: 38px; background: transparent; border: 0; color: var(--muted); padding: 0 10px; border-bottom: 2px solid transparent; font-weight: 680; font-size: 13px; }
.filter-button.active { color: var(--ink); border-bottom-color: var(--accent-dark); }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(17, 41, 36, .5); display: grid; place-items: center; padding: 18px; animation: fade .16s ease; }
.modal { width: min(680px, 100%); max-height: min(840px, calc(100vh - 36px)); overflow: auto; background: var(--card); border-radius: 16px; box-shadow: 0 24px 70px rgba(0,0,0,.26); animation: rise .18s ease; }
.modal-wide { width: min(1060px, 100%); }
.modal-header { padding: 21px 24px 18px; display: flex; justify-content: space-between; align-items: start; border-bottom: 1px solid var(--line); }
.modal-header p { font-size: 12px; color: var(--muted); margin: 4px 0 0; }
.close-modal { border: 0; background: transparent; color: var(--muted); font-size: 25px; line-height: 1; padding: 2px 0 6px 14px; }
.modal-body { padding: 24px; }
.modal-footer { border-top: 1px solid var(--line); padding: 15px 24px; display: flex; justify-content: flex-end; gap: 9px; position: sticky; bottom: 0; background: var(--card); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.form-grid.three { grid-template-columns: 1.3fr .8fr .8fr; }
.field { display: grid; gap: 6px; }
.field-full { grid-column: 1 / -1; }
.field label { font-size: 11px; color: var(--muted); font-weight: 760; letter-spacing: .06em; text-transform: uppercase; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: white; outline: none; min-height: 40px; padding: 9px 10px; color: var(--ink); }
.field textarea { min-height: 76px; resize: vertical; }
.date-control { display: flex; width: 100%; }
.date-control .date-input { border-radius: 8px 0 0 8px; }
.date-button { min-width: 40px; border: 1px solid var(--line); border-left: 0; border-radius: 0 8px 8px 0; background: #eef4e7; color: var(--accent-dark); font-size: 16px; }
.date-button:hover { background: var(--accent); }
.date-picker { position: fixed; z-index: 70; width: min(310px, calc(100vw - 32px)); left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.28); }
.date-picker header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; text-transform: capitalize; }
.date-picker header strong { font-size: 14px; }
.date-picker header button { border: 0; width: 32px; height: 32px; border-radius: 8px; background: #eef4e7; color: var(--ink); font-size: 25px; line-height: 1; }
.calendar-weekdays, .calendar-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; text-align: center; }
.calendar-weekdays { color: var(--muted); font-size: 10px; font-weight: 760; margin-bottom: 5px; }
.calendar-weekdays span { padding: 5px 0; }
.calendar-day, .calendar-empty { height: 34px; display: grid; place-items: center; }
.calendar-day { border: 0; border-radius: 7px; background: transparent; color: var(--ink); font-size: 12px; }
.calendar-day:hover { background: #e8f0da; }
.calendar-day.today { color: var(--accent-dark); font-weight: 760; outline: 1px solid #b6cc7b; }
.calendar-day.selected { background: var(--ink); color: white; outline: 0; }
.required { color: var(--danger); }
.document-lines { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 19px; }
.document-lines-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.line-items { display: grid; gap: 9px; }
.line-item { display: grid; grid-template-columns: minmax(180px, 1.9fr) .7fr .5fr .8fr .55fr 32px; gap: 8px; align-items: end; padding: 10px; background: #f9fbf6; border: 1px solid #e4ebe0; border-radius: 10px; }
.line-item .field label { font-size: 9px; }
.line-item .field input, .line-item .field select { min-height: 36px; padding: 6px 7px; font-size: 12px; }
.remove-line { height: 36px; border: 0; background: #f5e7e4; color: var(--danger); border-radius: 7px; font-size: 18px; }
.document-total-bar { margin-top: 15px; padding: 14px 15px; background: var(--ink); color: white; display: flex; justify-content: space-between; align-items: center; border-radius: 10px; }
.document-total-bar span { color: #bfcfc9; font-size: 12px; }
.document-total-bar strong { font-size: 18px; letter-spacing: -.5px; }
.details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding-bottom: 20px; }
.details-box { padding: 14px; border-radius: 10px; background: #f9fbf6; border: 1px solid #e4ebe0; }
.details-box p { margin: 2px 0; font-size: 13px; }
.details-label { color: var(--muted); font-size: 10px !important; font-weight: 760; letter-spacing: .08em; margin-bottom: 7px !important; }
.payment-progress { height: 8px; background: #e6ece7; border-radius: 100px; overflow: hidden; margin: 10px 0 6px; }
.payment-progress > span { display: block; height: 100%; background: var(--accent-dark); border-radius: inherit; }
.payment-split { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.payment-credit { color: #3e7e61; }
.fiscal-state { margin: 8px 0 4px !important; font-size: 12px !important; }
.fiscal-success { color: #3e7e61; }
.fiscal-pending { color: var(--warning); }
.fiscal-warning, .fiscal-error { color: var(--danger); line-height: 1.35; }
.fiscal-confirmation { margin: 18px 0 0; padding: 11px 12px; border-radius: 8px; background: #fff4df; color: #76501d; font-size: 12px; line-height: 1.45; }
.fiscal-tools-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 18px; }
.fiscal-tool { min-height: 112px; text-align: left; border: 1px solid var(--line); border-radius: 11px; padding: 15px; background: #fbfcf8; color: var(--ink); display: grid; align-content: start; gap: 5px; }
.fiscal-tool:hover { transform: translateY(-1px); border-color: #aabaaa; background: #f4f9e8; }
.fiscal-tool strong { font-size: 14px; }
.fiscal-tool span { color: var(--muted); font-size: 12px; line-height: 1.4; }
.fiscal-tool i { color: var(--accent-dark); font-size: 12px; font-style: normal; font-weight: 720; margin-top: auto; }
.toast-root { position: fixed; z-index: 100; right: 18px; bottom: 18px; display: grid; gap: 9px; max-width: min(380px, calc(100vw - 36px)); }
.toast { background: var(--ink); color: white; box-shadow: 0 12px 35px rgba(0,0,0,.22); padding: 13px 15px; border-radius: 10px; font-size: 13px; animation: rise .2s ease; }
.toast.error { background: #863c37; }
.loading { min-height: 230px; display: grid; place-items: center; color: var(--muted); font-size: 14px; }
.loading::before { content: ''; width: 24px; height: 24px; border: 3px solid #dbe5d4; border-top-color: var(--accent-dark); border-radius: 50%; animation: spin .75s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1100px) { .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 780px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 25px 17px 88px; }
  .topbar { align-items: flex-start; margin-bottom: 25px; }
  .topbar-actions .icon-button { display: none; }
  .topbar-actions .button { padding: 0 10px; font-size: 12px; }
  .mobile-nav { position: fixed; z-index: 20; bottom: 0; left: 0; right: 0; height: 67px; background: rgba(25,57,53,.98); display: grid; grid-template-columns: repeat(5, 1fr); padding: 5px 5px calc(5px + env(safe-area-inset-bottom)); }
  .mobile-nav .nav-link { display: grid; place-items: center; gap: 2px; padding: 5px; border-radius: 8px; font-size: 16px; color: #bdccc7; }
  .mobile-nav .nav-link span { font-size: 9px; }
  .mobile-nav .nav-link.active { color: var(--ink); background: var(--accent); }
  .dashboard-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card { padding: 15px; min-height: 117px; }
  .metric-value { font-size: 23px; }
  .toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar .button { align-self: stretch; }
  .filter-row { width: 100%; overflow: auto; }
  .filter-button { padding: 0 7px; white-space: nowrap; }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal { border-radius: 15px 15px 0 0; max-height: 92vh; }
  .modal-header, .modal-body { padding-left: 17px; padding-right: 17px; }
  .modal-footer { padding: 13px 17px; }
  .form-grid, .form-grid.three, .details-grid, .fiscal-tools-grid { grid-template-columns: 1fr; }
  .line-item { grid-template-columns: 1.3fr 1fr 32px; }
  .line-item .field:nth-child(2), .line-item .field:nth-child(3) { grid-column: auto; }
  .line-item .field:nth-child(4), .line-item .field:nth-child(5) { grid-column: span 1; }
  .line-item .field:nth-child(1) { grid-column: span 2; }
}
@media (min-width: 781px) { .mobile-nav { display: none; } }
@media (max-width: 420px) { .dashboard-grid { grid-template-columns: 1fr; } .topbar { gap: 12px; } h1 { font-size: 25px; } }

@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { position: absolute; inset: 0; padding: 30px; color: #111; }
}
