:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --ink: #18201d;
  --muted: #68746f;
  --line: #dce2de;
  --accent: #126c55;
  --accent-2: #d06f2e;
  --danger: #b94242;
  --warning: #8a650c;
  --ok: #2f7558;
  --shadow: 0 12px 30px rgba(21, 33, 29, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.dark {
  --bg: #15191c;
  --surface: #1e2428;
  --surface-2: #262d31;
  --ink: #e8ecea;
  --muted: #9aa5a1;
  --line: #353d41;
  --accent: #4cc69e;
  --accent-2: #f0976a;
  --danger: #e57373;
  --warning: #e0b04c;
  --ok: #66c293;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
body.dark input, body.dark select, body.dark textarea {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--line);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.auth-screen.hidden,
.app-shell.auth-locked {
  display: none;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
  display: grid;
  gap: 14px;
}

.auth-card h1 {
  margin: 8px 0 0;
  font-size: 24px;
}

.auth-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.auth-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.auth-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.auth-status {
  min-height: 18px;
  font-size: 13px;
  color: var(--muted);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  background: #17221e;
  color: #f8fbf7;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f0c46a;
  color: #17221e;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.sidebar-footer {
  color: #aab7b2;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  background: transparent;
  color: #dfe8e4;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.11);
  color: #ffffff;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 32px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 11px 12px;
  min-height: 42px;
}

textarea {
  resize: vertical;
}

#searchInput {
  width: min(360px, 42vw);
}

.primary-button,
.secondary-button,
.danger-button,
.quiet-button,
.icon-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 10px 14px;
  white-space: nowrap;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.secondary-button {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--line);
}

.danger-button {
  background: #fff6f4;
  color: var(--danger);
  border-color: #efc6bd;
}

.quiet-button,
.icon-button {
  background: transparent;
  color: inherit;
  border-color: rgba(255, 255, 255, 0.18);
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.metric,
.panel,
.data-table,
.ticket-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric span,
.metric small,
.soft-label,
.panel-heading span {
  color: var(--muted);
}

.metric strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 25px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(280px, 0.8fr);
  gap: 20px;
}

.panel {
  padding: 18px;
}

.panel-heading,
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.section-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.property-list {
  display: grid;
  gap: 12px;
}

.property-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.card-actions {
  display: grid;
  align-content: start;
  gap: 8px;
}

.property-card h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.property-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.property-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.document-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.document-link {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 8px;
  padding: 6px 10px;
  background: #eef3ef;
  border: 1px solid var(--line);
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
}

.document-link:hover {
  border-color: var(--accent);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13px;
}

.pill.ok {
  background: #dcefe6;
  color: var(--ok);
}

.pill.warn {
  background: #fbefd0;
  color: var(--warning);
}

.pill.danger {
  background: #f6dada;
  color: var(--danger);
}

.task-list {
  display: grid;
  gap: 10px;
}

.task {
  padding: 12px;
  border-left: 3px solid var(--accent-2);
  background: #fbfcfa;
  border-radius: 6px;
}

.task strong {
  display: block;
  margin-bottom: 4px;
}

.task span {
  color: var(--muted);
  font-size: 13px;
}

.task-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.data-table {
  overflow: hidden;
}

.sync-panel {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sync-panel h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.sync-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.sync-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
}

.sync-status {
  color: var(--muted);
  font-size: 13px;
  min-height: 18px;
}

.sync-status.ok {
  color: var(--ok);
}

.sync-status.danger {
  color: var(--danger);
}

.payment-summary {
  display: block;
  width: 100%;
  margin-bottom: 16px;
}

.summary-card {
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-card span,
.summary-card small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.summary-card strong {
  display: block;
  margin: 5px 0 4px;
  font-size: 18px;
}

.summary-card.danger strong {
  color: var(--danger);
}

.row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.8fr 0.8fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.row.header {
  background: #eef3ef;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}

.row:last-child {
  border-bottom: 0;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.payment-property-list {
  display: grid;
  gap: 14px;
}

.payment-property-card {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.payment-property-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.payment-property-heading h3 {
  margin: 0 0 4px;
  font-size: 17px;
}

.payment-property-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.payment-totals {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.payment-totals span {
  display: grid;
  gap: 3px;
  min-width: 110px;
  padding: 8px 10px;
  background: #f7f9f6;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
}

.payment-totals strong {
  color: var(--ink);
  font-size: 15px;
}

.payment-item-list {
  display: grid;
  gap: 8px;
}

.payment-item {
  display: grid;
  grid-template-columns: 1fr 110px 100px 110px auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.payment-item strong,
.payment-item small {
  display: block;
}

.payment-item small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.kanban {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 16px;
}

.kanban-column {
  min-height: 360px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.kanban-column h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.ticket-card {
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: none;
}

.ticket-card p {
  margin: 6px 0 12px;
  color: var(--muted);
}

.history-list {
  display: grid;
  gap: 14px;
}

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

.history-card h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.history-card p {
  color: var(--muted);
  margin: 0 0 12px;
}

.history-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.history-meta span {
  display: grid;
  gap: 3px;
  padding: 10px;
  background: #f7f9f6;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
}

.history-meta strong {
  color: var(--ink);
  font-size: 14px;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.25);
}

dialog::backdrop {
  background: rgba(13, 18, 16, 0.5);
}

.dialog-card {
  padding: 22px;
}

.dialog-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 14px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0;
  margin: 18px 0 0;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 14px;
    gap: 14px;
  }

  .nav {
    grid-template-columns: repeat(11, minmax(0, 1fr));
    overflow-x: auto;
  }

  .nav-item {
    text-align: center;
    padding: 10px;
  }

  .sidebar-footer {
    display: none;
  }

  .topbar,
  .topbar-actions,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  #searchInput {
    width: 100%;
  }

  .metrics-grid,
  .payment-summary,
  .content-grid,
  .kanban,
  .history-meta,
  .sync-form {
    grid-template-columns: 1fr;
  }

  .payment-property-heading {
    flex-direction: column;
  }

  .payment-totals {
    justify-content: flex-start;
  }

  .payment-item {
    grid-template-columns: 1fr;
  }

  .row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .row.header {
    display: none;
  }
}

@media (max-width: 560px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    font-size: 15px;
    line-height: 1.45;
  }

  .auth-screen {
    min-height: 100svh;
    padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
    align-items: start;
  }

  .auth-card {
    margin-top: 22px;
    padding: 18px;
    gap: 12px;
  }

  .auth-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .auth-actions button {
    width: 100%;
  }

  .app-shell {
    min-height: 100svh;
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    padding-bottom: calc(74px + env(safe-area-inset-bottom));
  }

  .sidebar {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    display: block;
    padding: 7px 8px max(7px, env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.22);
  }

  .sidebar .brand {
    display: none;
  }

  .nav {
    display: flex;
    gap: 6px;
    margin: 0;
    padding: 0 2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    flex: 0 0 58px;
    min-width: 58px;
    max-width: 58px;
    min-height: 54px;
    padding: 6px 2px;
    border-radius: 14px;
    font-size: 0;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
  }

  .nav-item::first-letter {
    font-size: 22px;
    line-height: 1;
  }

  .main {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    padding: max(14px, env(safe-area-inset-top)) 12px 18px;
  }

  h1 {
    font-size: 24px;
    line-height: 1.16;
  }

  h2 {
    font-size: 18px;
  }

  .topbar {
    gap: 12px;
    margin-bottom: 16px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 48px;
    gap: 8px;
    width: 100%;
  }

  #searchInput {
    grid-column: 1 / -1;
  }

  #darkModeToggle {
    width: 48px;
    min-width: 48px;
    padding: 0 !important;
  }

  #waStatusBtn {
    min-width: 0;
    width: 100%;
    text-align: center;
  }

  #addPropertyBtn {
    grid-column: 1 / -1;
    min-width: 0;
    width: 100%;
    text-align: center;
  }

  .section-heading,
  .panel-heading,
  .payment-property-heading {
    gap: 10px;
  }

  .section-actions,
  .row-actions,
  .card-actions,
  menu {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .section-actions > *,
  .row-actions > *,
  .card-actions > *,
  menu > *,
  .sync-form > * {
    width: 100%;
    min-width: 0;
  }

  .primary-button,
  .secondary-button,
  .danger-button,
  .quiet-button {
    min-height: 48px;
    padding: 12px 14px;
    white-space: normal;
    line-height: 1.2;
  }

  input,
  select,
  textarea {
    width: 100%;
    max-width: 100%;
    min-height: 48px;
    font-size: 16px;
  }

  img,
  svg,
  canvas,
  table {
    max-width: 100%;
  }

  code {
    white-space: normal;
    word-break: break-word;
  }

  .metrics-grid {
    gap: 12px;
  }

  .metric,
  .panel,
  .payment-property-card,
  .history-card,
  .sync-panel {
    padding: 14px;
  }

  .metric strong {
    font-size: 21px;
  }

  .property-card {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .property-meta,
  .document-list,
  .payment-totals,
  .task-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .payment-totals span {
    width: 100%;
  }

  .data-table {
    border: 0;
    background: transparent;
    box-shadow: none;
    overflow: visible;
  }

  .row {
    grid-template-columns: 1fr !important;
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    gap: 8px;
    padding: 14px;
    min-width: 0;
  }

  .payment-item {
    grid-template-columns: 1fr !important;
    align-items: stretch;
    min-width: 0;
  }

  .content-grid,
  .metrics-grid,
  .kanban,
  .history-meta {
    grid-template-columns: 1fr;
  }

  .panel,
  .metric,
  .payment-property-card,
  .history-card,
  .summary-card,
  .task,
  .empty-state {
    min-width: 0;
    max-width: 100%;
  }

  .panel-heading,
  .section-heading,
  .payment-property-heading {
    align-items: stretch;
  }

  .payment-property-heading,
  .payment-totals {
    display: grid;
    grid-template-columns: 1fr;
  }

  .payment-totals {
    justify-content: stretch;
  }

  .payment-property-card svg,
  #revenueChart svg,
  #incomeDistChart svg {
    min-width: 0 !important;
    height: auto;
  }

  .payment-property-card > div[style*="grid-template-columns"],
  #centralizareContent div[style*="grid-template-columns"],
  #indexPeriodsTable div[style*="grid-template-columns"],
  #meterReadingsTable div[style*="grid-template-columns"],
  #expenseList div[style*="grid-template-columns"] {
    display: grid !important;
    grid-template-columns: 1fr !important;
    align-items: stretch !important;
  }

  #calendarGrid {
    overflow-x: hidden;
    padding-bottom: 4px;
  }

  #calendarGrid table,
  #calendarGrid .calendar-grid {
    min-width: 0;
  }

  #calendarGrid > div[style*="grid-template-columns"] {
    grid-template-columns: repeat(7, minmax(0, 1fr)) !important;
    gap: 3px !important;
  }

  #calendarGrid > div[style*="grid-template-columns"] > div {
    min-width: 0 !important;
    padding: 6px 3px !important;
    font-size: 11px !important;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  dialog {
    width: calc(100vw - 20px);
    max-height: calc(100svh - 20px);
    margin: auto;
  }

  .dialog-card {
    max-height: calc(100svh - 20px);
    overflow-y: auto;
    padding: 16px;
  }

  .dialog-heading {
    position: sticky;
    top: -16px;
    z-index: 1;
    padding: 12px 0;
    background: var(--surface);
  }
}
