:root {
  --bg: #eef2f5;
  --surface: #ffffff;
  --surface-2: #f7fafc;
  --text: #17202a;
  --muted: #64748b;
  --line: #d8e0e8;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --accent: #b45309;
  --danger: #b91c1c;
  --radius: 8px;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.12);
  font-family: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
textarea { min-height: 96px; resize: vertical; }

.hidden, [hidden] { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(680px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--primary);
  color: white;
  font-weight: 800;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 22px; }
h2 { margin-bottom: 0; font-size: 24px; }
h3 { margin-bottom: 0; font-size: 18px; }

.eyebrow {
  margin-bottom: 4px;
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.muted, .helper { color: var(--muted); }
.helper { margin: 0; font-size: 13px; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px;
  background: #fbfcfd;
  border-right: 1px solid var(--line);
  overflow: auto;
}

.nav-list {
  display: grid;
  gap: 8px;
  margin: 28px 0;
}

.nav-link {
  border: 0;
  border-radius: var(--radius);
  padding: 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-weight: 700;
}

.nav-link.active,
.nav-link:hover {
  background: #dff3ef;
  color: var(--primary-dark);
}

.side-panel,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.side-panel { padding: 14px; }

.main-content {
  min-width: 0;
  padding: 24px;
}

.topbar,
.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 20px;
}

.topbar-actions,
.actions,
.filters {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.panel {
  padding: 18px;
  margin-bottom: 18px;
}

.panel-subsection {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  scroll-margin-top: 18px;
}

.view { display: none; }
.view.active { display: block; }

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

.form-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  color: var(--text);
  padding: 10px 11px;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(15, 118, 110, .18);
  border-color: var(--primary);
}

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

.full { grid-column: 1 / -1; }
.full-width { width: 100%; }

.primary-button,
.ghost-button,
.icon-button {
  border-radius: var(--radius);
  border: 1px solid transparent;
  min-height: 40px;
  padding: 9px 13px;
  font-weight: 800;
}

.primary-button {
  background: var(--primary);
  color: white;
}

.primary-button:hover { background: var(--primary-dark); }

.danger-button {
  min-height: 40px;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 9px 13px;
  background: #fee2e2;
  color: var(--danger);
  font-weight: 800;
}

.danger-button:hover {
  background: #fecaca;
}

.ghost-button,
.icon-button {
  background: white;
  border-color: var(--line);
  color: var(--text);
}

.ghost-button:hover { border-color: var(--primary); color: var(--primary-dark); }
.icon-button { width: 38px; padding: 0; }

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

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

.work-layout,
.reports-layout {
  display: grid;
  grid-template-columns: minmax(360px, .8fr) minmax(0, 1.2fr);
  gap: 18px;
  align-items: start;
}

.reports-layout {
  grid-template-columns: 360px minmax(0, 1fr);
}

.reports-layout .panel:last-child { grid-column: 1 / -1; }

.billing-reports-layout .form-grid.compact {
  grid-template-columns: 1fr;
}

.billing-reports-layout .actions {
  align-items: stretch;
}

.billing-reports-layout .actions button {
  flex: 1 1 150px;
}

.informe-layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.informe-layout .form-grid.compact {
  grid-template-columns: 1fr;
}

.informe-layout .actions {
  justify-content: flex-start;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  margin-top: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px 9px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  color: #334155;
  background: var(--surface-2);
  font-size: 12px;
  text-transform: uppercase;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.mini-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface-2);
}

.company-compact-card {
  padding: 12px;
}

.company-compact-card h3 {
  font-size: 16px;
  margin-bottom: 4px;
}

.company-compact-card.is-selected {
  border-color: var(--primary);
  background: #ecfdf5;
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  background: #e2e8f0;
  color: #334155;
  font-size: 12px;
  font-weight: 800;
}

.badge.ok { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.danger { background: #fee2e2; color: var(--danger); }

.report-sheet {
  margin-top: 16px;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  min-height: 360px;
}

.report-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 2px solid var(--text);
  padding-bottom: 16px;
  margin-bottom: 18px;
}

.report-logo {
  max-width: 130px;
  max-height: 70px;
  object-fit: contain;
}

.letterhead {
  border-bottom: 2px solid var(--text);
  padding-bottom: 14px;
  margin-bottom: 22px;
}

.letterhead-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.letterhead-info {
  color: var(--text);
  line-height: 1.45;
  white-space: normal;
}

.formal-informe {
  max-width: 820px;
  margin: 0 auto;
  line-height: 1.55;
}

.formal-informe table {
  margin: 18px 0 24px;
}

.document-closing {
  margin-top: 34px;
  break-inside: avoid;
}

.signature-block {
  display: flex;
  justify-content: center;
  margin: 8px 0 18px;
}

.signature-image {
  width: min(280px, 70%);
  height: auto;
  object-fit: contain;
}

.document-footer {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  line-height: 1.45;
}

.report-total {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
  font-size: 18px;
}

.modal {
  border: 0;
  padding: 0;
  background: transparent;
}

.modal::backdrop { background: rgba(15, 23, 42, .55); }

.modal-card {
  width: min(820px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  padding: 18px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

@media print {
  @page {
    size: A4;
    margin: 10mm;
  }

  html, body { margin: 0; padding: 0; background: white; }

  body.print-client .sidebar,
  body.print-client .topbar,
  body.print-client .view,
  body.print-informe .sidebar,
  body.print-informe .topbar,
  body.print-informe .view {
    display: none !important;
  }

  body.print-client .app-shell,
  body.print-informe .app-shell {
    display: block !important;
    min-height: 0;
  }

  body.print-client .main-content,
  body.print-informe .main-content {
    display: block !important;
    padding: 0;
  }

  body.print-client #reports-view,
  body.print-informe #informes-view {
    display: block !important;
  }

  body.print-client .reports-layout,
  body.print-informe .informe-layout {
    display: block !important;
  }

  body.print-client #reports-view .panel,
  body.print-informe #informes-view .panel {
    display: none !important;
  }

  body.print-client #reports-view .print-client-panel,
  body.print-informe #informes-view .print-informe-panel {
    display: block !important;
    border: 0;
    padding: 0;
    margin: 0;
  }

  body.print-client #client-report,
  body.print-informe #informe-sheet {
    border: 0;
    border-radius: 0;
    margin: 0;
    padding: 0;
    min-height: 0;
  }

  .document-footer {
    position: static;
    margin-top: 18px;
    border-top: 1px solid #888;
    color: #333;
  }
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
  }
  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 18px 0;
  }
  .nav-link {
    text-align: center;
    min-height: 44px;
  }
  .work-layout,
  .reports-layout,
  .informe-layout,
  .form-grid.compact,
  .stats-grid { grid-template-columns: 1fr; }
}
