:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e6e8ec;
  --text: #1a1d21;
  --muted: #6b7280;
  --primary: #2f5cff;
  --primary-hover: #244bd6;
  --primary-soft: #eef2ff;
  --success: #0f9d58;
  --success-soft: #eafaf1;
  --error: #d9453b;
  --error-soft: #fdecea;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.container {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* min-height (not a fixed height) so if the nav ever wraps on a narrow
     viewport the bar grows instead of clipping the second row. */
  min-height: 60px;
  row-gap: 6px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { color: var(--primary); font-size: 18px; }
.brand-name { font-weight: 650; font-size: 16px; letter-spacing: -0.01em; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 550;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: #fafbfc;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-pill.is-ok { color: var(--success); border-color: #cdeed9; background: var(--success-soft); }
.status-pill.is-ok .status-dot { background: var(--success); }
.status-pill.is-down { color: var(--error); border-color: #f6d4d1; background: var(--error-soft); }
.status-pill.is-down .status-dot { background: var(--error); }

/* Layout */
.main { padding-top: 32px; padding-bottom: 64px; }
.page-head { margin-bottom: 24px; }
.page-head h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.02em; }
.muted { color: var(--muted); }

/* Cards */
.cards { margin-bottom: 40px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.feature-card { max-width: 420px; }
.card-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: 14px;
}
.card h2 { font-size: 17px; margin: 0 0 6px; }
.card-desc { color: var(--muted); font-size: 14px; margin: 0 0 20px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 560;
  line-height: 1;
  padding: 10px 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s ease, border-color .15s ease, opacity .15s ease;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-ico { flex: none; }
.btn-sm { padding: 7px 12px; font-size: 13px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f3f4f6; }

.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: #f3f4f6; }

.btn:disabled, .btn.htmx-request { opacity: .6; pointer-events: none; }

/* Generation states */
.gen-indicator {
  display: none;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafbfc;
  font-size: 14px;
}
.gen-indicator .muted { display: block; font-size: 13px; }
.htmx-indicator.htmx-request,
.htmx-request .htmx-indicator { display: flex; }

.spinner {
  flex: none;
  width: 18px; height: 18px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.gen-result:empty { display: none; }
.result {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
  padding: 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.result-icon {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 50%;
}
.result-body { flex: 1; min-width: 0; }
.result-title { margin: 0; font-weight: 600; font-size: 14px; }
.result-file { margin: 2px 0 0; font-size: 14px; word-break: break-word; }
.result-meta { margin: 2px 0 0; font-size: 13px; }
.result-success { background: var(--success-soft); border-color: #cdeed9; }
.result-success .result-icon { background: #d6f3e2; color: var(--success); }
.result-error { background: var(--error-soft); border-color: #f6d4d1; }
.result-error .result-icon { background: #fbdad6; color: var(--error); }

/* Reports list */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-head h2 { font-size: 16px; margin: 0; }

.report-list { list-style: none; margin: 0; padding: 0; }
.report-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.report-badge {
  flex: none;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--success);
  background: var(--success-soft);
  border: 1px solid #cdeed9;
  border-radius: 6px;
  padding: 6px 7px;
}
.report-info { flex: 1; min-width: 0; }
.report-name { margin: 0; font-size: 14px; font-weight: 550; word-break: break-word; }
.report-meta { margin: 2px 0 0; font-size: 13px; }

/* Empty state */
.empty {
  text-align: center;
  padding: 44px 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-title { margin: 0 0 4px; font-weight: 600; font-size: 15px; }
.empty .muted { font-size: 14px; }

@media (max-width: 560px) {
  .feature-card { max-width: none; }
  .result { flex-direction: column; align-items: flex-start; }
  .report-item { flex-wrap: wrap; }
}

/* ===================== AR module ===================== */
:root { --warn: #b7791f; --warn-soft: #fdf6e3; --purple: #6d5bd0; --purple-soft: #f0edfb; }

.container { max-width: 1080px; }
/* The header chrome gets a bit more width than the content column so the full
   nav fits on one line in every language (Portuguese labels are the widest). */
.app-header .container { max-width: 1140px; }

/* Nav */
.main-nav { display: flex; gap: 2px; margin: 0 auto 0 20px; flex: 1; flex-wrap: wrap; }
.main-nav a {
  color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 550;
  padding: 8px 11px; border-radius: 8px; white-space: nowrap;
}
.main-nav a:hover { background: #f3f4f6; color: var(--text); }
.main-nav a.is-active { color: var(--primary); background: var(--primary-soft); }

/* Page head */
.page-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.breadcrumb { margin: 0 0 12px; font-size: 13px; }

/* Header right cluster + language switcher */
.header-right { display: flex; align-items: center; gap: 12px; flex: none; }
.lang-switch a { padding: 6px 9px; font-size: 12px; font-weight: 700; letter-spacing: .02em; }

/* Segmented control */
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: var(--surface); }
.segmented a { padding: 7px 14px; font-size: 13px; font-weight: 600; color: var(--muted); text-decoration: none; border-right: 1px solid var(--border); }
.segmented a:last-child { border-right: none; }
.segmented a.is-active { background: var(--primary); color: #fff; }

/* Metric cards */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 28px; }
.metric-grid-3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.metric-card {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--primary);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 6px;
}
.metric-card.metric-danger { border-left-color: var(--error); }
.metric-card.metric-warn { border-left-color: var(--warn); }
.metric-card.metric-credit { border-left-color: var(--purple); }
.metric-label { font-size: 12.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.metric-value { font-size: 24px; font-weight: 680; letter-spacing: -0.02em; }
.metric-link { font-size: 12.5px; color: var(--primary); text-decoration: none; margin-top: 2px; }
.metric-link:hover { text-decoration: underline; }

/* Panels + two column layout */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 820px) { .two-col { grid-template-columns: 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.panel-head h2 { font-size: 15px; margin: 0; }
.panel-body { padding: 18px; }

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { text-align: left; padding: 11px 18px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table thead th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: #fafbfc; }
.data-table.sticky thead th { position: sticky; top: 60px; z-index: 1; }
.data-table tbody tr:hover { background: #fafbfc; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.aging-table td { padding: 12px 18px; }

/* Badges */
.badge { display: inline-block; font-size: 11.5px; font-weight: 650; padding: 3px 9px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap; }
.badge-overdue { color: var(--error); background: var(--error-soft); border-color: #f6d4d1; }
.badge-open { color: var(--primary); background: var(--primary-soft); border-color: #d6ddff; }
.badge-credit { color: var(--purple); background: var(--purple-soft); border-color: #ded7f5; }
.badge-paid, .badge-import-completed, .badge-current { color: var(--success); background: var(--success-soft); border-color: #cdeed9; }
.badge-import-partial { color: var(--warn); background: var(--warn-soft); border-color: #f2e3bf; }
.badge-import-failed { color: var(--error); background: var(--error-soft); border-color: #f6d4d1; }
.badge-import-duplicate, .badge-import-pending { color: var(--muted); background: #f3f4f6; border-color: var(--border); }
.aging-label { font-weight: 600; }
.aging-90\+ { color: var(--error); }
.aging-61-90 { color: var(--warn); }

/* Filters */
.filter-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.filter-bar.wrap { flex-wrap: wrap; }
.search-field { position: relative; display: flex; align-items: center; flex: 1; min-width: 220px; }
.search-field svg { position: absolute; left: 12px; color: var(--muted); }
.search-field input { width: 100%; padding: 9px 12px 9px 34px; border: 1px solid var(--border); border-radius: 9px; font: inherit; font-size: 14px; background: var(--surface); }
.select-field { display: inline-flex; flex-direction: column; gap: 2px; }
.select-field select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px; font: inherit; font-size: 14px; background: var(--surface); }
.check-field { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; align-self: flex-end; padding-bottom: 8px; }
.search-field input:focus, .select-field select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

/* Pager */
.pager { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; gap: 12px; flex-wrap: wrap; }
.pager-btns { display: flex; align-items: center; gap: 10px; }
.btn.is-disabled { opacity: .5; pointer-events: none; }

/* Import controls */
.file-field input { font: inherit; font-size: 14px; margin-bottom: 12px; display: block; }
.stored-latest { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.stored-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.result-warn { background: var(--warn-soft); border: 1px solid #f2e3bf; }
.result-warn .result-icon { background: #f6ecc9; color: var(--warn); }
.error-details { margin-top: 10px; }
.error-details ul { margin: 8px 0 0; padding-left: 18px; }

/* Helpers */
.link { color: var(--primary); text-decoration: none; }
.link:hover { text-decoration: underline; }
.strong { font-weight: 600; }
.small { font-size: 12.5px; }
.text-danger { color: var(--error); }
.ellipsis { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spinner-sm { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; display: none; }
.spinner-sm.htmx-request { display: inline-block; }
.mt { margin-top: 14px; }

/* Customer page-head actions */
.head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Customer info panel (definition list) */
.info-grid { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; margin: 0; }
.info-grid dt { color: var(--muted); font-size: 13px; }
.info-grid dd { margin: 0; font-size: 14px; }

/* Customer create/edit form */
.stacked-form { display: flex; flex-direction: column; gap: 14px; max-width: 560px; }
.stacked-form .field { display: flex; flex-direction: column; gap: 4px; }
.stacked-form .field-label { font-size: 13px; color: var(--muted); }
.stacked-form input, .stacked-form select { padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; font: inherit; font-size: 14px; background: var(--surface); }
.stacked-form input:focus, .stacked-form select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ===================== Auth (login / sign-in) ===================== */
.auth-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1000px 520px at 50% -12%, var(--primary-soft) 0%, rgba(238, 242, 255, 0) 62%),
    linear-gradient(180deg, #f6f7f9 0%, #eceff5 100%);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px 26px;
  box-shadow: var(--shadow-md), 0 24px 56px -28px rgba(16, 24, 40, 0.22);
}

.brand-lg { justify-content: center; gap: 12px; margin-bottom: 22px; }
.brand-lg .brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  font-size: 20px;
  background: var(--primary-soft);
  border-radius: 11px;
}
.brand-lg .brand-name { font-size: 18px; }

.auth-title { font-size: 22px; font-weight: 680; letter-spacing: -0.02em; text-align: center; margin: 0 0 5px; }
.auth-subtitle { text-align: center; color: var(--muted); font-size: 14px; margin: 0 0 24px; }

.auth-error {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 13px;
  margin-bottom: 18px;
  font-size: 13.5px;
  color: var(--error);
  background: var(--error-soft);
  border: 1px solid #f6d4d1;
  border-radius: 10px;
}
.auth-error svg { flex: none; margin-top: 1px; }

.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form .field { display: flex; flex-direction: column; gap: 6px; }
.auth-form .field-label { font-size: 13px; font-weight: 550; color: var(--text); }
.auth-form input[type="email"],
.auth-form input[type="password"],
.auth-form input[type="text"] {
  width: 100%;
  padding: 11px 13px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.auth-form input::placeholder { color: #9aa1ab; }
.auth-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 92, 255, 0.15);
}

/* Password field: input + show/hide toggle */
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap input { padding-right: 46px; }
.pw-toggle {
  position: absolute;
  right: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.pw-toggle:hover { color: var(--text); background: #f3f4f6; }
.pw-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.pw-toggle .pw-eye-off { display: none; }
.pw-toggle.is-visible .pw-eye { display: none; }
.pw-toggle.is-visible .pw-eye-off { display: block; }

.auth-row { display: flex; align-items: center; justify-content: space-between; }
.auth-form .check-field { align-self: auto; padding-bottom: 0; font-size: 13.5px; color: var(--muted); }

.btn-block { width: 100%; padding: 12px 16px; font-size: 14.5px; margin-top: 2px; }

.auth-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.auth-foot .lang-label { font-size: 12.5px; color: var(--muted); }

@media (max-width: 420px) {
  .auth-body { padding: 16px; }
  .auth-card { padding: 28px 20px 20px; border-radius: 14px; }
}
