/* ============================================================
   ARCA Invoice Workbench — Integral / QC shared visual language
   Navy structure, teal actions, calm financial surfaces
   ============================================================ */

/* ---- Design Tokens ---- */
:root {
  --c-primary: #0f766e;
  --c-primary-hover: #0a5b55;
  --c-primary-light: #e9f5f2;
  --c-primary-50: rgba(15, 118, 110, 0.08);
  --c-primary-border: #b8ddd6;

  --c-navy: #102a43;
  --c-navy-700: #24445f;
  --c-heading: #102a43;
  --c-body: #152638;
  --c-muted: #66788a;
  --c-label: #152638;

  --c-success: #0f766e;
  --c-success-bg: #e9f5f2;
  --c-success-border: #b8ddd6;
  --c-warning: #d97706;
  --c-warning-bg: #fffbeb;
  --c-warning-border: #fde68a;
  --c-danger: #dc2626;
  --c-danger-bg: #fef2f2;
  --c-danger-border: #fecaca;

  --c-bg: #f4f7f7;
  --c-surface: #ffffff;
  --c-border: #dfe7ec;
  --c-border-light: #dfe7ec;
  --c-divider: #dfe7ec;

  --shadow-xs: 0 1px 2px rgba(16, 42, 67, 0.03);
  --shadow-sm: 0 1px 3px rgba(16, 42, 67, 0.05);
  --shadow-md: 0 4px 12px rgba(16, 42, 67, 0.06);
  --shadow-lg: 0 12px 28px rgba(16, 42, 67, 0.1);

  --radius-sm: 12px;
  --radius: 12px;
  --radius-md: 14px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Noto Sans SC',
    'Microsoft YaHei', 'PingFang SC', 'Segoe UI', sans-serif;
  --font-tabular: ui-monospace, 'SFMono-Regular', 'Cascadia Code', Consolas, monospace;

  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-body);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3, h4 { color: var(--c-heading); }

a { color: var(--c-primary); text-decoration: none; }
a:hover { color: var(--c-primary-hover); text-decoration: underline; }

img, svg { vertical-align: middle; }

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--c-primary);
  outline-offset: 3px;
}

header :focus-visible,
.intro-panel :focus-visible {
  outline-color: #99f6e4;
}

/* ---- Header ---- */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  min-height: 64px;
  background: var(--c-navy);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

header > div:first-child { display: flex; align-items: center; gap: 12px; }

header h1 {
  font-size: 16px;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

header > div:first-child p {
  display: block;
  color: rgba(255, 255, 255, 0.65);
  font-size: 12px;
  white-space: nowrap;
}

.header-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  display: flex;
  align-items: center;
  gap: 12px;
}

#currentUser {
  color: rgba(255, 255, 255, 0.76);
  font-size: 12px;
  font-weight: 500;
}

header a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  color: rgba(255, 255, 255, 0.9);
  font-size: 12px;
  font-weight: 500;
}

header a:hover {
  border-color: rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  text-decoration: none;
}

/* ---- Layout ---- */
main {
  width: min(1320px, calc(100vw - 48px));
  margin: 24px auto 40px;
}

/* App panel hidden by default; JS toggles to block after login */
#appPanel { display: none; }

/* ---- Module Navigation ---- */
.module-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  margin-bottom: 20px;
  padding: 6px;
  background: var(--c-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  border: 1px solid var(--c-border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}

.module-nav::-webkit-scrollbar { display: none; }

.module-tab {
  flex: 1;
  min-width: max-content;
  scroll-snap-align: start;
  height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--c-body);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition),
    color var(--transition), box-shadow var(--transition), transform var(--transition);
  white-space: nowrap;
  box-shadow: none;
  transform: none;
}

.module-tab:hover {
  background: var(--c-primary-50);
  color: var(--c-primary);
  box-shadow: none;
  transform: none;
}

.module-tab.active {
  background: var(--c-primary);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(15, 118, 110, 0.18);
}

.module-tab:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---- Module Pages ---- */
.module-page { display: none; }
.module-page.active { display: block; animation: fadeIn 150ms ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Panels ---- */
.panel {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-xs);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.panel:hover {
  border-color: var(--c-primary-border);
  box-shadow: var(--shadow-sm);
}

.panel h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--c-heading);
}

.panel h3 {
  margin: 20px 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--c-heading);
}

/* ---- Intro Panels ---- */
.intro-panel {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border: 0;
  color: #ffffff;
  padding: 24px 28px;
  position: relative;
  overflow: hidden;
}

.intro-panel::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -10%;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  pointer-events: none;
}

.intro-panel::after {
  content: '';
  position: absolute;
  bottom: -40%;
  right: 15%;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  pointer-events: none;
}

.intro-panel h2 {
  font-size: 20px;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 6px;
}

.intro-panel p {
  max-width: 640px;
  color: rgba(255, 255, 255, 0.8);
  line-height: 1.55;
  font-size: 13px;
}

.email-status-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  position: relative;
  z-index: 1;
}

.invoice-intro,
.email-intro,
.recon-intro,
.dashboard-intro {
  background: linear-gradient(135deg, var(--c-navy) 0%, var(--c-primary-hover) 100%);
}

.environment-badge {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: var(--radius);
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}

.environment-badge.production {
  background: rgba(185, 28, 28, 0.28);
}

.environment-badge.homologacion {
  background: rgba(233, 245, 242, 0.16);
}

.nota-field {
  display: block;
}

.nota-field.active {
  display: block;
}

.nota-field.inactive {
  opacity: 0.55;
}

/* Dashboard-specific panel styling */
.dashboard-panel {
  background: linear-gradient(135deg, var(--c-primary-light) 0%, var(--c-surface) 72%);
  border-color: var(--c-primary-border);
}

.dashboard-panel h3 {
  font-size: 15px;
  margin-top: 28px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--c-primary);
  color: var(--c-navy);
}

.dashboard-panel .field {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-xs);
  transition: transform var(--transition), box-shadow var(--transition);
}

.dashboard-panel .field:hover {
  border-color: var(--c-primary-border);
  box-shadow: var(--shadow-sm);
}

.dashboard-panel .field span {
  display: block;
  color: var(--c-muted);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.dashboard-panel .field strong {
  font-size: 22px;
  font-weight: 600;
  color: var(--c-navy);
  font-family: var(--font-tabular);
  font-variant-numeric: tabular-nums;
}

.dashboard-panel table {
  background: var(--c-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
}

.dashboard-panel th {
  background: var(--c-primary-light);
  color: var(--c-navy);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 12px 14px;
}

.dashboard-panel .total-row td { background: var(--c-primary-light); }
.dashboard-panel .year-sep { border-right: 2px solid var(--c-primary-border); }

/* ---- Layout Helpers ---- */
.panel-title,
.order-row,
.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-title {
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-title h2 { margin-bottom: 0; }

.order-row { gap: 12px; }
.order-row select { flex: 1; }

.actions {
  margin-top: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.candidate-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* ---- Grids ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.login-grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 16px;
  align-items: end;
}

.draft-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.compact-grid {
  margin-top: 16px;
  grid-template-columns: minmax(220px, 360px);
}

/* ---- Form Elements ---- */
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 500;
  font-size: 13px;
  color: var(--c-label);
}

.hint {
  margin-top: 12px;
  color: var(--c-muted);
  font-size: 12px;
}

.helper-text {
  margin-top: 0;
  margin-bottom: 12px;
  color: var(--c-muted);
  font-size: 12px;
  line-height: 1.55;
}

input, select, textarea {
  width: 100%;
  height: 40px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 0 12px;
  background: var(--c-surface);
  color: var(--c-heading);
  font: inherit;
  font-size: 13px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

input:disabled, select:disabled, textarea:disabled {
  background: var(--c-bg);
  color: var(--c-muted);
  cursor: not-allowed;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 0;
  flex: 0 0 18px;
  margin: 0;
  padding: 0;
  accent-color: var(--c-primary);
}

input::placeholder, textarea::placeholder { color: var(--c-muted); }

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236678aa' d='M2.5 4.5l3.5 3.5 3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}

textarea {
  min-height: 88px;
  height: auto;
  padding: 12px;
  resize: vertical;
  line-height: 1.5;
}

.wide-field { margin-top: 16px; }

/* File inputs */
input[type="file"] {
  height: auto;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  background: var(--c-bg);
}

input[type="file"]::file-selector-button {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  margin-right: 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  color: var(--c-body);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition),
    color var(--transition), box-shadow var(--transition), transform var(--transition);
}

input[type="file"]::file-selector-button:hover {
  background: var(--c-bg);
  border-color: var(--c-primary-border);
}

/* ---- Buttons ---- */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--c-primary);
  background: var(--c-primary);
  color: #ffffff;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--transition), border-color var(--transition),
    color var(--transition), box-shadow var(--transition), transform var(--transition);
  box-shadow: none;
  transform: none;
}

button:hover {
  background: var(--c-primary-hover);
  border-color: var(--c-primary-hover);
  box-shadow: 0 2px 6px rgba(15, 118, 110, 0.14);
  transform: none;
}

button:active { transform: translateY(1px); }

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* Danger */
button.danger {
  background: var(--c-danger);
  border-color: var(--c-danger);
}

button.danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
  box-shadow: 0 2px 6px rgba(220, 38, 38, 0.14);
}

/* Secondary / Ghost */
button.secondary {
  background: var(--c-surface);
  color: var(--c-body);
  border-color: var(--c-border);
}

button.secondary:hover {
  background: var(--c-bg);
  color: var(--c-primary);
  border-color: var(--c-primary-border);
  box-shadow: var(--shadow-sm);
}

/* Small */
button.small {
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

#uploadPreviews {
  margin: 8px 0 4px;
}

.preview-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  color: var(--c-muted);
}

.preview-row button.small {
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
}

/* Header buttons */
header button {
  height: 34px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.85);
  font-size: 12px;
  border-radius: var(--radius);
}

header button:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow: none;
}

/* ---- Field Cards (for draft / summary data) ---- */
.field {
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--c-surface);
  transition: border-color var(--transition);
}

.field:hover { border-color: var(--c-primary-border); }

.field span {
  display: block;
  color: var(--c-muted);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.field strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--c-heading);
  word-break: break-word;
}

/* ---- Metric Grid (for health check / dashboard cards) ---- */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
  margin: 16px 0;
}

.metric-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  transition: background-color var(--transition), border-color var(--transition),
    color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.metric-card:hover {
  border-color: var(--c-primary-border);
  box-shadow: var(--shadow-sm);
}

.metric-card span {
  display: block;
  color: var(--c-muted);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.metric-card strong {
  font-size: 28px;
  font-weight: 700;
  color: var(--c-navy);
  font-family: var(--font-tabular);
  font-variant-numeric: tabular-nums;
}

/* ---- Tables ---- */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 16px;
  font-size: 13px;
}

th, td {
  border-bottom: 1px solid var(--c-divider);
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--c-navy);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--c-primary-light);
  white-space: nowrap;
}

tbody tr:hover { background: var(--c-bg); }

.num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-tabular);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 240px;
}

.action-hint {
  align-items: center;
  color: var(--c-muted);
  display: inline-flex;
  font-size: 14px;
  min-height: 34px;
  padding: 0 8px;
}

.table-input {
  min-width: 100px;
  height: 34px;
  font-size: 12px;
  padding: 0 8px;
}

.settlement-entry-cell {
  min-width: 280px;
}

.settlement-entry-fields {
  display: grid;
  gap: 10px;
  min-width: 260px;
}

.settlement-entry-fields label {
  display: grid;
  gap: 6px;
}

.settlement-entry-fields label span {
  color: var(--c-muted);
  font-size: 11px;
  font-weight: 700;
}

.settlement-entry-fields .table-input {
  height: 34px;
  min-width: 0;
  width: 100%;
}

/* Table wrapper for horizontal scroll on mobile */
.panel {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.panel table {
  min-width: 100%;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
}

/* ---- Summary Strip ---- */
.summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0 12px;
}

.summary-strip span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--c-border);
  background: var(--c-bg);
  border-radius: var(--radius-full);
  padding: 5px 12px;
  color: var(--c-body);
  font-size: 12px;
  font-weight: 500;
}

/* ---- Code / Pre ---- */
pre {
  overflow: auto;
  background: var(--c-navy);
  color: #e9f5f2;
  border-radius: var(--radius-md);
  padding: 16px;
  line-height: 1.6;
  font-family: var(--font-tabular);
  font-size: 12px;
  margin-top: 16px;
  max-height: 400px;
}

/* ---- Smart Dashboard Elements ---- */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin: 0 0 24px;
}

.kpi-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
  animation: kpiEnter 250ms ease-out both;
}

.kpi-card:nth-child(2) { animation-delay: 0.08s; }
.kpi-card:nth-child(3) { animation-delay: 0.16s; }

@keyframes kpiEnter {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.kpi-card:hover {
  border-color: var(--c-primary-border);
  box-shadow: var(--shadow-sm);
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
}

.kpi-card.kpi-blue::before { background: var(--c-navy); }
.kpi-card.kpi-amber::before { background: var(--c-warning); }
.kpi-card.kpi-green::before { background: var(--c-primary); }

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--c-muted);
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--c-navy);
  font-family: var(--font-tabular);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.kpi-sub {
  font-size: 11px;
  color: var(--c-muted);
  margin-top: 4px;
  font-weight: 500;
}

/* Mini bar chart */
.chart-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
}

.chart-bar-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-navy);
  min-width: 36px;
}

.chart-bar-track {
  flex: 1;
  height: 22px;
  background: var(--c-bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  gap: 4px;
}

.chart-bar-fill {
  height: 100%;
  border-radius: var(--radius-sm);
  transition: none;
  min-width: 1px;
}

.chart-bar-fill.fill-blue { background: linear-gradient(90deg, var(--c-navy), var(--c-primary)); }
.chart-bar-fill.fill-amber { background: linear-gradient(90deg, var(--c-warning), #f59e0b); }

.chart-bar-amount {
  font-size: 12px;
  color: var(--c-body);
  font-family: var(--font-tabular);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Debt level bars */
.debt-level {
  display: flex;
  align-items: center;
  gap: 8px;
}

.debt-bar-track {
  flex: 1;
  height: 6px;
  background: var(--c-bg);
  border-radius: var(--radius-full);
  overflow: hidden;
  min-width: 60px;
}

.debt-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: none;
}

.debt-bar-fill.fill-green { background: var(--c-primary); }
.debt-bar-fill.fill-yellow { background: #f59e0b; }
.debt-bar-fill.fill-orange { background: var(--c-warning); }
.debt-bar-fill.fill-red { background: var(--c-danger); }

.debt-pct {
  font-size: 11px;
  font-weight: 600;
  min-width: 32px;
  text-align: right;
  font-family: var(--font-tabular);
  font-variant-numeric: tabular-nums;
}

/* Customer rank row */
.customer-rank-row td:first-child {
  font-weight: 600;
  color: var(--c-navy);
}

@media (max-width: 768px) {
  .kpi-strip { grid-template-columns: 1fr; }
  .kpi-value { font-size: 20px; }
  .chart-bar-amount { font-size: 11px; }
}

/* ---- Status ---- */
#status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--c-primary-light);
  border: 1px solid var(--c-primary-border);
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 500;
  color: var(--c-primary);
}

/* ---- Empty States ---- */
.draft-empty {
  padding: 28px 16px;
  color: var(--c-muted);
  text-align: center;
  font-size: 13px;
  border: 1px dashed var(--c-border);
  border-radius: var(--radius-md);
  margin-top: 12px;
}

/* ---- Pagination ---- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
  font-size: 13px;
  color: var(--c-muted);
}

.pagination button:disabled { opacity: 0.3; }

/* ---- Toast Notice ---- */
.notice {
  position: fixed;
  right: 24px;
  bottom: 80px;
  z-index: 100;
  max-width: min(420px, calc(100vw - 48px));
  padding: 14px 20px;
  border-radius: var(--radius-md);
  background: var(--c-navy);
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
}

.notice.ok,
.notice.busy,
.notice.error {
  opacity: 1;
  transform: translateY(0);
}

.notice.ok    { background: var(--c-success); }
.notice.busy  { background: var(--c-primary); }
.notice.error { background: var(--c-danger); }

/* ---- Login Page (Standalone) ---- */
#loginPanel.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 24px);
  padding: 24px;
  max-width: none;
  margin: 0;
  background:
    radial-gradient(ellipse at 25% 0%, rgba(15, 118, 110, 0.08) 0%, transparent 55%),
    radial-gradient(ellipse at 75% 100%, rgba(16, 42, 67, 0.06) 0%, transparent 55%);
}

.login-card {
  width: 100%;
  max-width: 320px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 28px 24px 24px;
  box-shadow: var(--shadow-md);
  text-align: center;
  animation: loginEnter 250ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes loginEnter {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.login-welcome { margin-bottom: 20px; }

.login-logo {
  display: block;
  max-width: 140px;
  height: auto;
  margin: 0 auto 12px;
  animation: logoFade 250ms ease-out 0.1s both;
}

@keyframes logoFade {
  from { opacity: 0; transform: translateY(4px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-subtitle {
  font-size: 12px;
  color: var(--c-muted);
  font-weight: 400;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: left;
}

.login-form label {
  display: block;
  width: 100%;
}

.login-form input {
  width: 100%;
  height: 40px;
  font-size: 13px;
  margin-top: 2px;
}

.login-form button {
  width: 100%;
  height: 44px;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius);
  letter-spacing: 0.01em;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* ---- Tablet (<= 960px) ---- */
@media (max-width: 960px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .draft-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ---- Mobile (<= 768px) ---- */
@media (max-width: 768px) {
  main {
    width: calc(100vw - 24px);
    margin: 16px auto 100px;
  }

  header {
    flex-wrap: wrap;
    padding: 10px 16px;
    min-height: 56px;
    gap: 10px;
  }

  header h1 { font-size: 14px; }
  header > div:first-child p { display: none; }

  .module-nav {
    gap: 4px;
    margin-bottom: 16px;
    padding: 6px;
    border-radius: var(--radius-md);
  }

  .module-tab {
    height: 38px;
    padding: 0 10px;
    font-size: 12px;
  }

  .panel {
    padding: 16px;
    border-radius: var(--radius-md);
  }

  #loginPanel.login-page {
    min-height: 100vh;
    min-height: 100dvh;
    padding: 16px;
  }

  .login-card {
    padding: 24px 20px 20px;
  }

  .grid,
  .login-grid,
  .draft-grid {
    grid-template-columns: 1fr;
  }

  .panel-title,
  .order-row,
  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .panel-title {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
  }

  .actions button { width: 100%; }

  .intro-panel {
    flex-direction: column;
    align-items: flex-start;
    min-height: 72px;
    padding: 20px;
    gap: 16px;
  }
  .intro-panel h2 { font-size: 18px; }
  .email-status-actions { justify-content: flex-start; }

  .metric-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .metric-card strong { font-size: 22px; }

  .notice {
    right: 12px;
    left: 12px;
    bottom: 72px;
    max-width: none;
  }

  .summary-strip {
    gap: 8px;
  }

  .summary-strip span { font-size: 11px; padding: 3px 8px; }
}

/* ---- Small mobile (<= 480px) ---- */
@media (max-width: 480px) {
  main { width: calc(100vw - 16px); margin: 12px auto 96px; }

  .module-nav {
    border-radius: var(--radius-md);
    gap: 4px;
    padding: 4px;
  }

  .module-tab {
    height: 34px;
    padding: 0 8px;
    font-size: 11px;
    border-radius: var(--radius-sm);
  }

  .panel {
    padding: 14px;
    border-radius: var(--radius-md);
  }

  .metric-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .metric-card { padding: 12px; }
  .metric-card strong { font-size: 20px; }

  header h1 { font-size: 13px; }
}

/* ============================================================================
   税票台账（只读视图） —— C 阶段新增
   金额列只显示后端整数最小单位；.minor-raw 展示原始整数与精度，便于核对。
   ============================================================================ */
.table-scroll {
  width: 100%;
  margin-top: 16px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-scroll table {
  min-width: 100%;
  margin-top: 0;
  border: 0;
  border-radius: 0;
}

.panel .amount {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.panel .amount .minor-raw {
  display: block;
  font-size: 10px;
  color: var(--c-muted);
  font-weight: 400;
}

.panel .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.ledger-login-required {
  padding: 16px;
  margin-top: 12px;
  border: 1px solid var(--c-warning-border);
  background: var(--c-warning-bg);
  color: #8a5a00;
  border-radius: var(--radius-md);
  font-size: 13px;
}

.tag-warn {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border: 1px solid var(--c-warning-border);
  border-radius: var(--radius-full);
  background: var(--c-warning-bg);
  color: #8a5a00;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.inline-check {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--c-muted);
}

.inline-check input[type="checkbox"],
.order-document-row input[type="checkbox"] {
  margin: 0;
}

/* Keep document selection compact, readable and scoped to the selected order. */
#integralDocumentsPanel[hidden] { display: none !important; }
#integralDocumentsPanel { margin: 16px 0; padding: 18px; border: 1px solid var(--c-border); border-radius: var(--radius-md); }
.order-documents-order { font-weight: 600; color: var(--c-heading); }
.order-document-row { display: flex; align-items: flex-start; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--c-border); }
.order-document-row:last-child { border-bottom: 0; }
.order-document-info { min-width: 0; display: flex; flex-direction: column; gap: 6px; overflow-wrap: anywhere; }
.order-document-info span { font-size: 12px; color: var(--c-muted); }

/* ---- Manual Reconciliation & Extended Ledger UI ---- */
.recon-bucket-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 4px;
}
.recon-bucket-btn {
  background: var(--c-surface);
  color: var(--c-heading);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.recon-bucket-btn.active {
  background: var(--c-primary);
  color: #ffffff;
  border-color: var(--c-primary);
}
.tag-success, .tag-info, .tag-danger {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
}
.tag-success { background: var(--c-success-bg); color: var(--c-success); border: 1px solid var(--c-success-border); }
.tag-info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.tag-danger { background: var(--c-danger-bg); color: var(--c-danger); border: 1px solid var(--c-danger-border); }
.file-chip {
  display: inline-block;
  margin: 2px 4px 2px 0;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--c-primary-light);
  border: 1px solid var(--c-primary-border);
  font-size: 12px;
}

/* ---- Reduced Motion ---- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }

  .module-page.active,
  .kpi-card,
  .login-card,
  .login-logo {
    animation: none !important;
  }

  button:active,
  .notice {
    transform: none !important;
  }
}
