:root {
  --bg: #080b0a;
  --surface: #101513;
  --surface-2: #151b18;
  --surface-3: #1b231f;
  --border: rgba(255,255,255,.08);
  --border-strong: rgba(255,255,255,.14);
  --text: #f2f7f4;
  --muted: #84918a;
  --muted-2: #aeb8b2;
  --primary: #b94cff;
  --primary-soft: rgba(185,76,255,.15);
  --green: #49f992;
  --yellow: #f4c95d;
  --red: #ff6b6b;
  --blue: #79a7ff;
  --shadow: 0 24px 70px rgba(0,0,0,.28);
  --radius: 18px;
  --radius-sm: 12px;
  --sidebar-width: 252px;
}

* { box-sizing: border-box; }
html { color-scheme: dark; scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; max-width: 100%; overflow-x: hidden; background: radial-gradient(circle at 80% 0%, rgba(185,76,255,.075), transparent 30%), var(--bg); color: var(--text); font-family: "Rubik", system-ui, sans-serif; font-size: 14px; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
a { color: inherit; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; max-width: 100%; overflow-x: clip; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; width: var(--sidebar-width); display: flex; flex-direction: column; padding: 24px 16px 18px; background: rgba(13,17,15,.93); border-right: 1px solid var(--border); backdrop-filter: blur(20px); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 10px 25px; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; color: #fff; background: var(--primary); box-shadow: 0 0 35px rgba(185,76,255,.26); }
.brand-mark svg { width: 27px; height: 27px; }
.brand strong { display: block; font-size: 18px; letter-spacing: -.03em; }
.brand span { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.main-nav { display: grid; gap: 6px; }
.nav-item { width: 100%; min-height: 45px; display: flex; align-items: center; gap: 13px; padding: 0 13px; border: 0; border-radius: 11px; background: transparent; color: var(--muted-2); cursor: pointer; text-align: left; transition: .2s ease; }
.nav-item svg { width: 20px; height: 20px; flex: 0 0 auto; }
.nav-item:hover { background: rgba(255,255,255,.045); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }
.sidebar-footer { margin-top: auto; display: grid; gap: 10px; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 11px; border: 1px solid var(--border); border-radius: 13px; background: rgba(255,255,255,.025); cursor: pointer; text-align: left; }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--surface-3); color: var(--primary); font-weight: 700; font-size: 12px; }
.user-copy { min-width: 0; flex: 1; }
.user-copy strong, .user-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-copy strong { font-size: 12px; }
.user-copy small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.chevron { color: var(--muted); font-size: 20px; }

.main-content { min-width: 0; max-width: calc(100% - var(--sidebar-width)); min-height: 100vh; margin-left: var(--sidebar-width); padding: 0 34px 52px; overflow-x: clip; }
.topbar { min-height: 108px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar-copy { display: flex; align-items: center; gap: 12px; }
.eyebrow { margin: 0 0 7px; color: var(--primary); font-size: 10px; font-weight: 700; letter-spacing: .17em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(25px, 3vw, 34px); line-height: 1; letter-spacing: -.045em; }
h2 { margin-bottom: 0; font-size: 19px; letter-spacing: -.035em; }
h3 { font-size: 16px; }
.topbar-actions, .table-tools { display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 100%; }
.table-tools { flex-wrap: wrap; }
.button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 15px; border: 1px solid transparent; border-radius: 11px; cursor: pointer; text-decoration: none; font-weight: 600; font-size: 12px; transition: .18s ease; }
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--primary); color: #fff; box-shadow: 0 10px 30px rgba(185,76,255,.18); }
.button-primary:hover { background: #c96dff; }
.button-secondary { border-color: var(--border); background: var(--surface-2); color: var(--text); }
.button-secondary:hover, .button-ghost:hover { border-color: var(--border-strong); background: var(--surface-3); }
.button-ghost { border-color: var(--border); background: transparent; color: var(--muted-2); }
.button-danger { background: rgba(255,107,107,.14); color: #ff8d8d; border-color: rgba(255,107,107,.23); }
.button-danger-text { padding-left: 0; background: transparent; color: var(--red); }
.button-icon { font-size: 17px; line-height: 1; }
.icon-button { width: 38px; height: 38px; display: inline-grid; place-items: center; padding: 0; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); cursor: pointer; transition: .18s ease; }
.icon-button:hover { border-color: var(--border-strong); background: var(--surface-3); }
.icon-button svg { width: 19px; height: 19px; }
.mobile-menu { display: none; }

.view { display: none; min-width: 0; max-width: 100%; animation: fadeIn .25s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.card { border: 1px solid var(--border); border-radius: var(--radius); background: linear-gradient(145deg, rgba(255,255,255,.028), rgba(255,255,255,.012)); box-shadow: 0 1px 0 rgba(255,255,255,.025) inset; }
.month-toolbar { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px 18px; }
.month-control { display: flex; align-items: center; gap: 14px; min-width: 0; }
.period-control { min-width: 0; }
.toolbar-label { display: block; color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .16em; }
.month-title { padding: 0; border: 0; background: transparent; color: var(--text); font-size: 17px; font-weight: 600; cursor: default; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }
.period-picker { display: grid; grid-template-columns: minmax(118px, 1fr) minmax(82px, auto); align-items: center; gap: 7px; margin-top: 5px; min-width: 0; }
.period-picker-compact { margin-top: 0; flex: 0 1 270px; }
.period-select { width: 100%; min-width: 0; height: 38px; padding: 0 30px 0 11px; border: 1px solid var(--border); border-radius: 10px; background-color: var(--surface-2); color: var(--text); outline: 0; font-size: 11px; font-weight: 500; transition: border-color .15s ease, box-shadow .15s ease; }
.period-select:focus { border-color: rgba(185,76,255,.58); box-shadow: 0 0 0 3px rgba(185,76,255,.09); }
.period-year { min-width: 82px; }
.toolbar-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 13px rgba(73,249,146,.7); }
.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.metric-card { min-height: 145px; padding: 19px; }
.metric-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted-2); font-size: 11px; }
.metric-icon { width: 29px; height: 29px; display: grid; place-items: center; border-radius: 9px; font-weight: 700; }
.metric-icon.neutral { background: rgba(121,167,255,.1); color: var(--blue); }
.metric-icon.positive { background: rgba(73,249,146,.1); color: var(--green); }
.metric-icon.warning { background: rgba(244,201,93,.1); color: var(--yellow); }
.metric-icon.danger { background: rgba(255,107,107,.1); color: var(--red); }
.metric-card > strong { display: block; margin-top: 18px; font-size: clamp(22px, 2.4vw, 30px); letter-spacing: -.045em; }
.metric-card > small { display: block; margin-top: 8px; color: var(--muted); font-size: 10px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 14px; margin-top: 14px; }
.table-card { min-width: 0; overflow: hidden; }
.section-heading { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 17px 20px; border-bottom: 1px solid var(--border); }
.section-heading.compact { border-bottom: 0; padding-bottom: 0; }
.section-heading .eyebrow { margin-bottom: 5px; }
.search-field { min-width: 0; max-width: 100%; flex: 1 1 215px; height: 38px; display: flex; align-items: center; gap: 8px; padding: 0 11px; border: 1px solid var(--border); border-radius: 10px; background: rgba(255,255,255,.025); color: var(--muted); }
.search-field.wide { width: min(330px, 100%); min-width: 0; max-width: 100%; }
.search-field svg { width: 16px; height: 16px; flex: 0 0 auto; }
.search-field input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 11px; }
.search-field input::placeholder { color: #68736d; }
.select-control { max-width: 100%; height: 38px; padding: 0 32px 0 11px; border: 1px solid var(--border); border-radius: 10px; background-color: var(--surface-2); color: var(--muted-2); outline: 0; font-size: 11px; }
.table-wrapper { position: relative; width: 100%; max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th { padding: 12px 15px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; text-align: left; }
td { padding: 14px 15px; border-bottom: 1px solid rgba(255,255,255,.055); color: var(--muted-2); font-size: 11px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: rgba(255,255,255,.018); }
.align-right { text-align: right; }
.check-column { width: 58px; text-align: center; }
.client-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.client-cell > span:last-child { min-width: 0; }
.client-avatar { width: 31px; height: 31px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 9px; background: var(--surface-3); color: var(--primary); font-weight: 700; font-size: 10px; }
.client-cell strong, .client-cell small { display: block; max-width: 165px; overflow: hidden; text-overflow: ellipsis; }
.client-cell strong { color: var(--text); font-size: 11px; }
.client-cell small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 0 9px; border-radius: 999px; font-size: 9px; font-weight: 600; }
.status-badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.status-paid { background: rgba(73,249,146,.1); color: var(--green); }
.status-pending { background: rgba(244,201,93,.1); color: var(--yellow); }
.status-overdue { background: rgba(255,107,107,.1); color: var(--red); }
.status-inactive { background: rgba(132,145,138,.1); color: var(--muted); }
.status-active { background: rgba(121,167,255,.1); color: var(--blue); }
.payment-check { appearance: none; width: 19px; height: 19px; display: inline-grid; place-items: center; border: 1px solid var(--border-strong); border-radius: 6px; background: transparent; cursor: pointer; vertical-align: middle; }
.payment-check:checked { border-color: var(--primary); background: var(--primary); }
.payment-check:checked::after { content: "✓"; color: #fff; font-size: 12px; font-weight: 800; }
.row-more { width: 31px; height: 31px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; letter-spacing: 1px; }
.row-more:hover { background: var(--surface-3); color: var(--text); }
.side-insight { padding-bottom: 18px; }
.progress-ring-wrap { display: grid; place-items: center; padding: 22px 0 17px; }
.progress-ring { --progress: 0deg; width: 132px; aspect-ratio: 1; display: grid; place-items: center; border-radius: 50%; background: conic-gradient(var(--primary) var(--progress), var(--surface-3) 0); position: relative; }
.progress-ring::before { content: ""; position: absolute; inset: 11px; border-radius: 50%; background: #111613; box-shadow: inset 0 0 0 1px var(--border); }
.progress-ring > div { position: relative; z-index: 1; text-align: center; }
.progress-ring strong, .progress-ring span { display: block; }
.progress-ring strong { font-size: 25px; letter-spacing: -.05em; }
.progress-ring span { margin-top: 3px; color: var(--muted); font-size: 9px; }
.insight-list { display: grid; gap: 12px; padding: 0 20px; }
.insight-list > div { display: grid; grid-template-columns: 8px 1fr auto; align-items: center; gap: 9px; color: var(--muted-2); font-size: 11px; }
.insight-list strong { color: var(--text); }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; }
.positive-bg { background: var(--green); }.warning-bg { background: var(--yellow); }.danger-bg { background: var(--red); }
.insight-callout { display: flex; align-items: flex-start; gap: 9px; margin: 19px 16px 0; padding: 12px; border: 1px solid rgba(185,76,255,.16); border-radius: 12px; background: rgba(185,76,255,.065); }
.insight-callout p { margin: 0; color: var(--muted-2); font-size: 9px; line-height: 1.55; }
.callout-icon { color: var(--primary); }
.empty-state { padding: 48px 20px; text-align: center; }
.empty-icon { width: 44px; height: 44px; display: grid; place-items: center; margin: 0 auto 13px; border-radius: 13px; background: var(--primary-soft); color: var(--primary); font-size: 20px; }
.empty-state h3 { margin-bottom: 7px; }
.empty-state p { margin-bottom: 0; color: var(--muted); font-size: 11px; }

.section-page-heading { display: flex; min-width: 0; max-width: 100%; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.section-page-heading > * { min-width: 0; max-width: 100%; }
.charges-page-heading { align-items: center; }
.charges-filters { flex: 1 1 620px; justify-content: flex-end; }
.charges-filters .search-field { flex: 1 1 210px; }
.charges-filters .select-control { flex: 0 1 125px; }
.section-page-heading h2 { font-size: 25px; }
.section-page-heading p:not(.eyebrow) { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.client-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.client-card { padding: 18px; }
.client-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.client-card-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.client-card-avatar { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 12px; background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.client-card h3 { margin: 0 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client-card-company { color: var(--muted); font-size: 10px; }
.client-card-details { display: grid; gap: 9px; margin: 18px 0; padding: 14px 0; border-block: 1px solid var(--border); }
.client-card-details a, .client-card-details span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted-2); font-size: 10px; text-decoration: none; }
.client-card-details a:hover { color: var(--primary); }
.client-card-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.client-card-footer span { color: var(--muted); font-size: 9px; }
.client-card-footer strong { font-size: 12px; }
.type-badge { display: inline-flex; padding: 5px 8px; border-radius: 7px; background: rgba(121,167,255,.09); color: var(--blue); font-size: 9px; }

.client-card-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; margin-top: 14px; }
.button-danger-outline { border-color: rgba(255,107,107,.2); background: transparent; color: #ff8d8d; }
.button-danger-outline:hover { border-color: rgba(255,107,107,.36); background: rgba(255,107,107,.09); }
.amount-detail, .service-meta { display: block; margin-top: 4px; color: var(--muted); font-size: 8px; font-weight: 500; }
.service-name { color: var(--muted-2); }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: none; place-items: center; padding: 20px; background: rgba(0,0,0,.72); backdrop-filter: blur(7px); }
.modal-backdrop.open { display: grid; animation: modalFade .18s ease; }
@keyframes modalFade { from { opacity: 0; } to { opacity: 1; } }
.modal { width: min(680px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; padding: 22px; border: 1px solid var(--border-strong); border-radius: 20px; background: #111613; box-shadow: var(--shadow); }
.modal-small { width: min(560px, 100%); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.modal-close { font-size: 25px; line-height: 1; }
.form-grid { display: grid; gap: 14px; }
.two-columns { grid-template-columns: repeat(2, minmax(0,1fr)); }
.field { display: grid; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field > span { color: var(--muted-2); font-size: 10px; font-weight: 500; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); outline: 0; transition: border-color .15s ease, box-shadow .15s ease; }
.field input, .field select { height: 42px; padding: 0 12px; }
.field textarea { padding: 11px 12px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: rgba(185,76,255,.58); box-shadow: 0 0 0 3px rgba(185,76,255,.09); }
.money-input { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); overflow: hidden; }
.money-input:focus-within { border-color: rgba(185,76,255,.58); box-shadow: 0 0 0 3px rgba(185,76,255,.09); }
.money-input span { padding-left: 12px; color: var(--muted); }
.money-input input { border: 0; box-shadow: none !important; }
.form-divider { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 21px 0 14px; padding-top: 19px; border-top: 1px solid var(--border); }
.form-divider span { font-weight: 600; }
.form-divider small { color: var(--muted); font-size: 9px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.modal-actions.spread { justify-content: space-between; }
.modal-actions.spread > div { display: flex; gap: 10px; }
.payment-summary { margin-bottom: 16px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.payment-summary strong, .payment-summary span { display: block; }
.payment-summary strong { margin-bottom: 5px; }
.payment-summary span { color: var(--muted); font-size: 10px; }
.settings-stack { display: grid; gap: 12px; }
.settings-item { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.settings-item strong { display: block; margin-bottom: 5px; font-size: 11px; }
.settings-item p { margin: 0; color: var(--muted); font-size: 9px; line-height: 1.5; }
.danger-zone { border-color: rgba(255,107,107,.15); }
.file-button input { display: none; }
.toast-region { position: fixed; z-index: 200; right: 20px; bottom: 20px; display: grid; gap: 8px; }
.toast { min-width: 260px; max-width: 360px; padding: 13px 15px; border: 1px solid var(--border-strong); border-radius: 12px; background: #171e1a; box-shadow: var(--shadow); font-size: 11px; animation: toastIn .25s ease; }
.toast.success { border-color: rgba(73,249,146,.2); }.toast.error { border-color: rgba(255,107,107,.3); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.mobile-overlay { display: none; }

@media (max-width: 1180px) {
  .charges-page-heading { align-items: stretch; flex-direction: column; }
  .charges-filters { width: 100%; flex: 0 0 auto; justify-content: flex-start; }
  .charges-filters .search-field { width: auto; }
}

@media (max-width: 800px) {
  .responsive-table { display: block; width: 100%; white-space: normal; }
  .responsive-table thead { display: none; }
  .responsive-table tbody { display: grid; gap: 10px; padding: 10px; }
  .responsive-table tr { display: block; padding: 4px 12px; border: 1px solid var(--border); border-radius: 13px; background: rgba(255,255,255,.018); }
  .responsive-table td { width: 100%; display: grid; grid-template-columns: minmax(84px, .72fr) minmax(0, 1.28fr); align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.055); white-space: normal; text-align: right; }
  .responsive-table td::before { content: attr(data-label); color: var(--muted); font-size: 8px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; text-align: left; }
  .responsive-table td:last-child { border-bottom: 0; }
  .responsive-table .client-cell { justify-content: flex-end; text-align: left; }
  .responsive-table .client-cell strong, .responsive-table .client-cell small { max-width: min(46vw, 185px); }
  .responsive-table .check-column { width: 100%; text-align: right; }
  .responsive-table .align-right { text-align: right; }
  .responsive-table .actions-cell { display: flex; justify-content: flex-end; padding-top: 6px; }
  .responsive-table .actions-cell::before { display: none; }
  .responsive-table .type-badge, .responsive-table .status-badge { justify-self: end; }
}

@media (max-width: 1120px) {
  .metrics-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .side-insight { display: grid; grid-template-columns: 1fr 180px 1fr; align-items: center; padding: 14px; }
  .side-insight .section-heading { padding: 0 8px; }
  .progress-ring-wrap { padding: 0; }
  .insight-callout { margin: 0; }
  .client-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 860px) {
  .sidebar { transform: translateX(-102%); transition: transform .22s ease; box-shadow: 20px 0 60px rgba(0,0,0,.35); }
  .sidebar.open { transform: none; }
  .mobile-overlay { position: fixed; inset: 0; z-index: 20; display: block; pointer-events: none; opacity: 0; background: rgba(0,0,0,.55); transition: opacity .2s ease; }
  .mobile-overlay.open { pointer-events: auto; opacity: 1; }
  .main-content { max-width: 100%; margin-left: 0; padding-inline: 20px; }
  .mobile-menu { display: inline-grid; }
  .topbar { min-height: 95px; }
  .topbar-actions .button-secondary { display: none; }
  .section-heading, .section-page-heading { align-items: stretch; flex-direction: column; }
  .table-tools { width: 100%; }
  .search-field { flex: 1 1 220px; }
  .charges-filters { justify-content: flex-start; }
}

@media (max-width: 640px) {
  .main-content { padding-inline: 14px; padding-bottom: 35px; }
  .topbar { align-items: flex-end; padding: 17px 0; }
  .topbar-actions .button { width: 42px; padding: 0; font-size: 0; }
  .topbar-actions .button-icon { font-size: 20px; }
  .month-toolbar { align-items: stretch; flex-direction: column; }
  .month-control { width: 100%; justify-content: space-between; }
  .period-control { flex: 1; }
  .toolbar-meta { padding-left: 0; }
  .metrics-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 126px; }
  .side-insight { display: block; }
  .progress-ring-wrap { padding: 22px 0 17px; }
  .insight-callout { margin: 19px 2px 0; }
  .client-grid { grid-template-columns: 1fr; }
  .two-columns { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .modal { padding: 18px; }
  .modal-actions.spread { align-items: stretch; flex-direction: column-reverse; }
  .modal-actions.spread > div { display: grid; grid-template-columns: 1fr 1fr; }
  .settings-item { align-items: stretch; flex-direction: column; }
  .table-tools { align-items: stretch; flex-direction: column; }
  .table-tools > *, .charges-filters .search-field, .charges-filters .select-control { flex: 0 0 auto; }
  .charges-filters .period-picker-compact { width: 100%; flex: 0 0 auto; }
  .search-field, .search-field.wide, .select-control { width: 100%; height: 38px; }
  .section-heading { padding: 17px 14px; }
  th, td { padding-inline: 12px; }
  .toast-region { left: 14px; right: 14px; bottom: 14px; }
  .toast { min-width: 0; max-width: none; }
}


@media (max-width: 430px) {
  .main-content { padding-inline: 10px; }
  .topbar { gap: 10px; }
  .topbar-copy { min-width: 0; }
  .topbar-copy > div:last-child { min-width: 0; }
  .topbar h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .month-toolbar { padding: 12px; }
  .month-control { display: grid; grid-template-columns: 38px minmax(0,1fr) 38px; gap: 8px; }
  .period-picker { grid-template-columns: minmax(0,1fr); }
  .period-picker-compact { grid-template-columns: minmax(0,1fr); }
  .metric-card { padding: 16px; }
  .section-page-heading h2 { font-size: 22px; }
  .client-card { padding: 15px; }
  .client-card-actions { grid-template-columns: 1fr; }
  .modal-backdrop { padding: 8px; }
  .modal { max-height: calc(100dvh - 16px); padding: 16px; border-radius: 16px; }
  .modal-actions, .modal-actions.spread > div { grid-template-columns: 1fr; }
  .modal-actions:not(.spread) { display: grid; }
  .modal-actions .button { width: 100%; }
  .responsive-table tbody { padding: 8px; }
  .responsive-table tr { padding-inline: 10px; }
  .responsive-table td { grid-template-columns: minmax(72px, .65fr) minmax(0, 1.35fr); gap: 8px; }
  .responsive-table .client-cell strong, .responsive-table .client-cell small { max-width: 47vw; }
}

/* Estado de conexão com Cloudflare D1 */
.app-status-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 8, 15, 0.92);
  backdrop-filter: blur(14px);
}

.app-status-overlay.hidden { display: none; }

.app-status-card {
  width: min(100%, 460px);
  display: grid;
  justify-items: center;
  gap: 18px;
  padding: 34px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.45);
}

.app-status-card strong {
  display: block;
  color: var(--text);
  font-size: 1.08rem;
}

.app-status-card p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.cloud-spinner {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(185, 76, 255, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: cloud-spin 0.8s linear infinite;
}

.app-status-overlay.is-error .cloud-spinner {
  animation: none;
  border: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 87, 108, 0.12);
}

.app-status-overlay.is-error .cloud-spinner::before {
  content: '!';
  color: var(--danger);
  font-size: 24px;
  font-weight: 700;
}

#monthSummaryText[data-sync-status="error"] { color: var(--danger); }
#monthSummaryText[data-sync-status="syncing"] { opacity: 0.78; }

@keyframes cloud-spin { to { transform: rotate(360deg); } }

@media (max-width: 480px) {
  .app-status-overlay { padding: 16px; }
  .app-status-card { padding: 28px 20px; border-radius: 20px; }
}

/* Autenticação e gestão de usuários */
.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 14% 15%, rgba(185,76,255,.16), transparent 29%),
    radial-gradient(circle at 88% 85%, rgba(185,76,255,.08), transparent 30%),
    var(--bg);
}
.auth-layout {
  width: min(1080px, 100%);
  min-height: 650px;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, .95fr);
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 28px;
  background: rgba(14,18,16,.92);
  box-shadow: 0 40px 120px rgba(0,0,0,.42);
}
.auth-brand-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 42px;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background:
    linear-gradient(145deg, rgba(185,76,255,.12), transparent 52%),
    rgba(255,255,255,.014);
}
.auth-brand-panel::after {
  content: "";
  position: absolute;
  right: -110px;
  bottom: -120px;
  width: 360px;
  height: 360px;
  border: 1px solid rgba(185,76,255,.16);
  border-radius: 50%;
  box-shadow: 0 0 0 45px rgba(185,76,255,.025), 0 0 0 90px rgba(185,76,255,.018);
}
.auth-brand { position: relative; z-index: 1; padding: 0; }
.auth-presentation { position: relative; z-index: 1; max-width: 480px; }
.auth-presentation h1 { max-width: 470px; font-size: clamp(34px, 4.8vw, 58px); line-height: 1.03; }
.auth-presentation > p:not(.eyebrow) { margin: 22px 0 0; color: var(--muted-2); font-size: 13px; line-height: 1.7; }
.auth-feature-list { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 30px; }
.auth-feature-list span { padding: 8px 10px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted-2); background: rgba(255,255,255,.025); font-size: 9px; }
.auth-form-panel { display: grid; place-items: center; padding: 38px; }
.auth-card { width: min(100%, 390px); display: grid; gap: 16px; }
.auth-card-heading { margin-bottom: 8px; }
.auth-card-heading h2 { font-size: 29px; }
.auth-card-heading > p:not(.eyebrow) { margin: 10px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.auth-submit { width: 100%; min-height: 46px; margin-top: 4px; }
.text-button { border: 0; background: transparent; color: var(--primary); cursor: pointer; font-size: 10px; font-weight: 600; }
.text-button:hover { text-decoration: underline; }
.password-field { position: relative; }
.password-field input { padding-right: 46px; }
.password-toggle { position: absolute; top: 50%; right: 7px; width: 34px; height: 34px; transform: translateY(-50%); border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; }
.password-toggle:hover { background: rgba(255,255,255,.045); color: var(--text); }
.field-hint { display: block; margin: -4px 0 0; color: var(--muted); font-size: 9px; line-height: 1.45; }
.form-message { margin: 0; padding: 10px 12px; border-radius: 10px; font-size: 10px; line-height: 1.45; }
.form-message.error { border: 1px solid rgba(255,107,107,.2); background: rgba(255,107,107,.08); color: #ff9b9b; }
.form-message.success { border: 1px solid rgba(73,249,146,.2); background: rgba(73,249,146,.07); color: var(--green); }
.auth-config-error { width: min(100%, 420px); padding: 22px; border: 1px solid rgba(255,107,107,.22); border-radius: 16px; background: rgba(255,107,107,.07); }
.auth-config-error strong { display: block; margin-bottom: 8px; color: #ff9b9b; }
.auth-config-error p { margin: 0; color: var(--muted-2); font-size: 11px; line-height: 1.6; }

.user-menu {
  position: fixed;
  z-index: 90;
  width: 220px;
  display: grid;
  padding: 7px;
  border: 1px solid var(--border-strong);
  border-radius: 13px;
  background: #151b18;
  box-shadow: var(--shadow);
}
.user-menu button { min-height: 39px; padding: 0 11px; border: 0; border-radius: 9px; background: transparent; color: var(--muted-2); cursor: pointer; text-align: left; font-size: 10px; }
.user-menu button:hover { background: rgba(255,255,255,.045); color: var(--text); }
.user-menu .danger-menu-item { color: #ff8d8d; }
.user-card[aria-expanded="true"] { border-color: rgba(185,76,255,.35); background: var(--primary-soft); }

.user-management-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.managed-user-card { min-width: 0; padding: 18px; }
.managed-user-head { display: grid; grid-template-columns: 43px minmax(0,1fr) auto; align-items: center; gap: 12px; }
.managed-user-avatar, .account-avatar { display: grid; place-items: center; border-radius: 12px; background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.managed-user-avatar { width: 43px; height: 43px; }
.managed-user-head h3 { margin: 0 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.managed-user-head p { margin: 0; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 9px; white-space: nowrap; }
.managed-user-meta { display: grid; gap: 5px; margin: 17px 0; padding: 13px 0; border-block: 1px solid var(--border); color: var(--muted-2); font-size: 9px; }
.managed-user-meta span:last-child { color: var(--muted); }
.managed-user-actions { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.managed-user-actions .button:last-child { grid-column: 1 / -1; }
.button:disabled { opacity: .48; cursor: not-allowed; transform: none !important; }
.modal-description { margin: 0 0 18px; color: var(--muted-2); font-size: 10px; line-height: 1.55; }
.account-summary { display: flex; align-items: center; gap: 15px; padding: 18px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); }
.account-avatar { width: 54px; height: 54px; flex: 0 0 auto; font-size: 15px; }
.account-summary strong, .account-summary span, .account-summary small { display: block; }
.account-summary strong { margin-bottom: 5px; }
.account-summary span { color: var(--muted-2); font-size: 10px; }
.account-summary small { margin-top: 6px; color: var(--primary); font-size: 9px; }

.cloud-spinner { border-top-color: var(--primary); }
.app-status-overlay.is-error .cloud-spinner::before, #monthSummaryText[data-sync-status="error"] { color: var(--red); }

@media (max-width: 1050px) {
  .auth-layout { grid-template-columns: 1fr 420px; }
  .auth-brand-panel { padding: 34px; }
  .user-management-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 800px) {
  .auth-screen { padding: 14px; }
  .auth-layout { min-height: 0; grid-template-columns: 1fr; }
  .auth-brand-panel { min-height: 240px; padding: 28px; border-right: 0; border-bottom: 1px solid var(--border); }
  .auth-presentation h1 { max-width: 620px; font-size: clamp(28px, 7vw, 44px); }
  .auth-presentation > p:not(.eyebrow), .auth-feature-list { display: none; }
  .auth-form-panel { padding: 30px 24px; }
}

@media (max-width: 640px) {
  .user-management-grid { grid-template-columns: 1fr; }
  .managed-user-actions { grid-template-columns: 1fr; }
  .managed-user-actions .button:last-child { grid-column: auto; }
}

@media (max-width: 430px) {
  .auth-screen { padding: 0; place-items: stretch; }
  .auth-layout { min-height: 100dvh; border: 0; border-radius: 0; }
  .auth-brand-panel { min-height: 190px; padding: 24px 20px; }
  .auth-presentation h1 { font-size: 28px; }
  .auth-form-panel { align-items: start; padding: 26px 20px 34px; }
  .auth-card-heading h2 { font-size: 25px; }
  .user-menu { left: 12px !important; right: 12px; bottom: 12px !important; width: auto; }
}
