﻿:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #64748b;
  --line: #d9e2ec;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --blue: #2563eb;
  --amber: #d97706;
  --red: #dc2626;
  --green: #15803d;
  --shadow: 0 16px 40px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px 1fr; }
.sidebar { background: #102a43; color: #fff; padding: 18px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand, .login-brand { display: flex; align-items: center; gap: 12px; font-weight: 800; letter-spacing: 0; }
.brand { padding: 8px 10px 22px; font-size: 1.15rem; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 8px; background: #d9f99d; color: #14532d; flex: 0 0 auto; }
.sidebar .nav-link { color: rgba(255,255,255,.82); display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; margin-bottom: 2px; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.09); color: #fff; }
.mobile-header, .mobile-drawer, .mobile-drawer-backdrop { display: none; }
.main { min-width: 0; }
.topbar { min-height: 86px; padding: 18px 28px; display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,.86); border-bottom: 1px solid var(--line); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 10; }
.topbar h1 { font-size: 1.55rem; margin: 2px 0 0; font-weight: 800; letter-spacing: 0; }
.page-kicker { color: var(--muted); font-size: .84rem; }
.user-menu { display: flex; align-items: center; gap: 8px; }
.content { padding: 24px 28px 42px; }

.dashboard-grid { display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: 16px; }
.metric-card, .form-card, .table-panel, .info-panel, .chart-panel, .alert-card, .empty-state { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.metric-card { padding: 18px; border-top: 4px solid var(--primary); }
.metric-card h2, .chart-panel h2, .form-card h2, .info-panel h2 { font-size: 1rem; font-weight: 800; margin: 0; letter-spacing: 0; }
.metric-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.metric-main { font-size: 1.65rem; font-weight: 800; margin-top: 14px; }
.metric-sub { color: var(--muted); font-size: .88rem; margin-bottom: 12px; }
.metric-list { display: grid; gap: 8px; margin: 0; }
.metric-list div { display: flex; justify-content: space-between; gap: 12px; border-top: 1px solid #edf2f7; padding-top: 8px; }
.metric-list dt { color: var(--muted); font-weight: 600; }
.metric-list dd { margin: 0; text-align: right; font-weight: 700; }
.status-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--green); display: inline-block; }
.status-verde { border-top-color: var(--green); }
.status-amarelo { border-top-color: var(--amber); }
.status-vermelho { border-top-color: var(--red); }
.status-amarelo .status-dot { background: var(--amber); }
.status-vermelho .status-dot { background: var(--red); }
.total-card { border-top-color: var(--blue); }
.info-strip { display: flex; flex-wrap: wrap; gap: 14px; padding: 14px 16px; border: 1px solid var(--line); background: #fff; border-radius: 8px; margin: 16px 0; color: var(--muted); }
.info-strip span { display: inline-flex; align-items: center; gap: 6px; }
.charts-grid { display: grid; grid-template-columns: repeat(2, minmax(280px, 1fr)); gap: 16px; }
.chart-panel { padding: 16px; min-height: 320px; }
.chart-panel.wide { grid-column: 1 / -1; }
.chart-panel canvas { width: 100% !important; max-height: 260px; }

.form-card, .info-panel { padding: 18px; }
.form-card.narrow { max-width: 520px; }
.table-panel { overflow: hidden; }
.table-panel .table { margin: 0; }
.table thead th { color: #475569; background: #f8fafc; font-size: .82rem; text-transform: uppercase; letter-spacing: 0; }
.actions-row { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 14px; }
.filter-bar { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 14px; box-shadow: var(--shadow); }
.section-title { font-size: 1rem; font-weight: 800; margin: 24px 0 10px; }
.alert-card { padding: 16px; display: flex; justify-content: space-between; gap: 12px; border-left: 5px solid var(--blue); }
.alert-card p { margin: 4px 0 0; color: var(--muted); }
.alert-card span { color: var(--muted); white-space: nowrap; }
.severity-amarelo { border-left-color: var(--amber); }
.severity-vermelho { border-left-color: var(--red); }
.severity-verde { border-left-color: var(--green); }
.empty-state { padding: 30px; color: var(--muted); text-align: center; }

.login-body { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #e0f2fe, #f8fafc 52%, #ecfccb); padding: 18px; }
.login-panel { width: min(430px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 28px; box-shadow: var(--shadow); }
.login-brand { margin-bottom: 22px; }
.login-brand strong { display: block; font-size: 1.25rem; }
.login-brand small { color: var(--muted); }

.btn { border-radius: 8px; }
.form-control, .form-select { border-radius: 8px; }
.badge { border-radius: 6px; }
.invoice-close-form {
  overflow: hidden;
}

.invoice-close-form .section-title {
  margin: 28px 0 14px;
}

.invoice-meter-panel,
.form-card > .table-panel.mb-3 {
  box-sizing: border-box;
  padding: 16px;
  width: 100%;
}

.invoice-meter-panel .row,
.form-card > .table-panel.mb-3 .row {
  margin-left: 0;
  margin-right: 0;
}

.invoice-meter-panel .row > [class*="col-"],
.form-card > .table-panel.mb-3 .row > [class*="col-"] {
  min-width: 0;
  padding-left: 8px;
  padding-right: 8px;
}

.invoice-meter-panel .form-control,
.invoice-meter-panel .form-select,
.form-card > .table-panel.mb-3 .form-control,
.form-card > .table-panel.mb-3 .form-select {
  max-width: 100%;
}

.invoice-meter-panel h3,
.form-card > .table-panel.mb-3 h3 {
  line-height: 1.2;
}

@media (max-width: 1180px) {
  .dashboard-grid { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
}

@media (max-width: 767.98px) {
  body { min-width: 0; }
  body.mobile-drawer-open { overflow: hidden; }
  .app-shell { display: block; min-height: 100dvh; }
  .sidebar, .topbar { display: none; }
  .main { min-width: 0; }

  .mobile-header {
    display: block;
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255,255,255,.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(8px);
    padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  }
  .mobile-header-bar { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 8px; }
  .mobile-menu-toggle, .mobile-drawer-close {
    width: 44px;
    min-width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    display: inline-grid;
    place-items: center;
  }
  .mobile-menu-toggle i, .mobile-drawer-close i { font-size: 1.35rem; line-height: 1; }
  .mobile-brand { min-width: 0; display: inline-flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 800; }
  .mobile-brand .brand-mark { width: 34px; height: 34px; }
  .mobile-brand span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-user-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; min-width: 0; }
  .mobile-user-actions .badge { max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-page-title { padding-top: 8px; }
  .mobile-page-title h1 { margin: 2px 0 0; font-size: 1.28rem; line-height: 1.2; font-weight: 800; overflow-wrap: anywhere; }

  .mobile-drawer-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 110;
    background: rgba(15, 23, 42, .48);
  }
  .mobile-drawer {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 120;
    width: min(86vw, 320px);
    height: 100dvh;
    padding: calc(10px + env(safe-area-inset-top)) 12px calc(14px + env(safe-area-inset-bottom));
    background: #102a43;
    color: #fff;
    transform: translateX(-100%);
    transition: transform .18s ease;
    overflow-y: auto;
    box-shadow: 16px 0 40px rgba(15, 23, 42, .24);
  }
  .mobile-drawer.is-open { transform: translateX(0); }
  .mobile-drawer-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
  .mobile-drawer .brand { padding: 4px 0; }
  .mobile-drawer-close { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.18); color: #fff; }
  .mobile-drawer .nav { display: grid; gap: 4px; }
  .mobile-drawer .nav-link { color: rgba(255,255,255,.84); display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 10px 12px; border-radius: 8px; }
  .mobile-drawer .nav-link:hover, .mobile-drawer .nav-link.is-active { background: rgba(255,255,255,.12); color: #fff; }

  .content { padding: 14px max(12px, env(safe-area-inset-right)) calc(26px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .dashboard-grid, .charts-grid { grid-template-columns: 1fr; gap: 12px; }
  .chart-panel.wide { grid-column: auto; }
  .metric-card, .form-card, .info-panel, .chart-panel, .table-panel, .empty-state { border-radius: 8px; box-shadow: 0 10px 24px rgba(15, 23, 42, .07); }
  .metric-card, .form-card, .info-panel, .chart-panel { padding: 14px; }
  .metric-main { font-size: 1.45rem; overflow-wrap: anywhere; }
  .metric-sub { font-size: .84rem; }
  .metric-list div { align-items: flex-start; gap: 10px; }
  .metric-list dt { flex: 1 1 auto; min-width: 0; }
  .metric-list dd { flex: 0 1 58%; min-width: 0; overflow-wrap: anywhere; }
  .info-strip { margin: 12px 0; padding: 12px; gap: 10px; }
  .info-strip span { width: 100%; align-items: flex-start; }
  .chart-panel { min-height: 290px; }
  .chart-panel canvas { height: 240px !important; max-height: none; }

  .actions-row, .mobile-actions { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
  .actions-row .btn, .mobile-actions .btn { width: 100%; justify-content: center; }
  .filter-bar { padding: 12px; margin-bottom: 12px; }
  .filter-bar > [class*="col-"] { width: 100%; flex: 0 0 100%; }
  .filter-bar .d-flex { flex-direction: column; align-items: stretch; }
  .filter-bar .btn { width: 100%; justify-content: center; }
  .pagination { justify-content: center; flex-wrap: wrap; gap: 4px; }
  .page-link { min-height: 44px; display: inline-flex; align-items: center; }

  .form-control, .form-select, textarea, input, select { font-size: 16px; }
  .form-control, .form-select { min-height: 44px; }
  textarea.form-control { min-height: 92px; }
  .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: normal; }
  .btn-sm { min-height: 44px; }
  .form-card .row > [class*="col-"], .info-panel .row > [class*="col-"] { width: 100%; }
  .form-card .d-flex.justify-content-end, .info-panel .d-flex.justify-content-end { flex-direction: column; align-items: stretch; }
  .form-card .d-flex.justify-content-end .btn, .info-panel .d-flex.justify-content-end .btn { width: 100%; }
  .modal-footer { flex-direction: column; align-items: stretch; }
  .modal-footer .btn { width: 100%; }

  .invoice-meter-panel,
  .form-card > .table-panel.mb-3 { padding: 14px 12px; }
  .invoice-meter-panel > .d-flex { flex-direction: column; align-items: flex-start !important; gap: 6px; }
  .invoice-meter-panel h3 { font-size: 1.22rem; }
  .section-title { margin: 18px 0 10px; }
  .alert-card { flex-direction: column; }
  .alert-card span { white-space: normal; }
  .login-body { align-items: stretch; padding: calc(16px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom)); }
  .login-panel { align-self: center; padding: 22px 18px; }

  .table-panel { overflow: visible; }
  .table-responsive { overflow: visible; }
  .mobile-card-table { width: 100%; border-collapse: separate; border-spacing: 0; }
  .mobile-card-table thead { display: none; }
  .mobile-card-table tbody, .mobile-card-table tfoot { display: block; }
  .mobile-card-table tr { display: block; margin: 0 0 12px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
  .mobile-card-table td, .mobile-card-table th { min-width: 0; border: 0 !important; padding: 7px 0 !important; text-align: left !important; vertical-align: top; }
  .mobile-card-table td:not(.mobile-card-empty), .mobile-card-table tfoot th:not(.mobile-card-total-title) { display: grid; grid-template-columns: minmax(104px, 42%) minmax(0, 1fr); gap: 10px; align-items: start; }
  .mobile-card-table td::before, .mobile-card-table tfoot th::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: .76rem;
    line-height: 1.25;
    font-weight: 800;
    text-transform: uppercase;
  }
  .mobile-card-table td > *, .mobile-card-table th > * { min-width: 0; }
  .mobile-card-table .mobile-card-empty { display: block; padding: 22px 12px !important; text-align: center !important; }
  .mobile-card-table .mobile-card-empty::before, .mobile-card-table td[data-label=""]::before, .mobile-card-table .mobile-card-total-title::before { content: none; }
  .mobile-card-table .mobile-actions-cell { display: block !important; }
  .mobile-card-table .mobile-actions-cell::before { display: block; margin-bottom: 8px; }
  .mobile-card-table .mobile-actions-cell .btn, .mobile-card-table .mobile-actions-cell button { width: 100%; margin-bottom: 6px; }
  .mobile-card-table .mobile-actions-cell form { width: 100%; display: grid !important; gap: 8px; }
  .mobile-card-table .mobile-actions-cell form .form-control { width: 100%; }
  .mobile-card-table tfoot tr { background: #f8fafc; border-color: rgba(15, 118, 110, .28); }
  .mobile-card-table .mobile-card-total-title { display: block; color: var(--ink); font-weight: 800; }
}

@media print {
  .sidebar, .topbar, .mobile-header, .mobile-drawer, .mobile-drawer-backdrop, .actions-row, .filter-bar, .btn { display: none !important; }
  .app-shell { display: block; }
  .content { padding: 0; }
  .table-panel, .form-card, .info-panel { box-shadow: none; border: 0; }
}
