* { box-sizing: border-box; }
body {
  margin: 0;
  padding: 16px;
  background: #f5f7fa;
  color: #2c3e50;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.5;
}
main { max-width: 1200px; margin: 0 auto; outline: none; }
.header { max-width: 1200px; margin: 0 auto 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.header h1 { margin: 0; font-size: 1.5rem; flex: 1 1 auto; }
.user { display: flex; align-items: center; gap: 12px; }
.user-name { color: #455a64; }
.nav { flex: 1 0 100%; display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  padding: 8px 16px; border-radius: 20px; background: #ecf0f1; color: #2c3e50;
  text-decoration: none; font-weight: 600;
}
.pill:hover { background: #dfe6e9; }
.pill[aria-current="page"] { background: #2471a3; color: #fff; }

.card { background: #fff; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); padding: 20px; margin-bottom: 16px; }
.card h2 { margin: 0 0 16px; padding-bottom: 8px; border-bottom: 2px solid #ecf0f1; font-size: 1.3rem; }

.btn {
  font: inherit; font-weight: 600; padding: 8px 16px; border: 1px solid #b0bec5; border-radius: 6px;
  background: #fff; color: #2c3e50; cursor: pointer;
}
.btn:hover { background: #ecf0f1; }
.btn.primary { background: #2471a3; border-color: #2471a3; color: #fff; }
.btn.primary:hover { background: #1b5a82; }

:focus-visible { outline: 3px solid #f39c12; outline-offset: 2px; }
.skip-link { position: absolute; left: -999px; top: 0; background: #fff; padding: 8px; z-index: 10; }
.skip-link:focus { left: 8px; top: 8px; }

.filter { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; max-width: 360px; }
.filter label { font-weight: 600; }
.filter input { font: inherit; padding: 8px 10px; border: 1px solid #90a4ae; border-radius: 6px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
caption { text-align: left; font-weight: 600; color: #455a64; padding-bottom: 8px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #ecf0f1; vertical-align: top; }
th { background: #f5f7fa; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
tbody tr:hover { background: #f9fbfc; }
a { color: #1b5a82; }

.billing table { font-size: 1.15rem; }
.billing td, .billing th { padding: 14px 12px; }

.hero { background: linear-gradient(135deg, #2471a3, #1abc9c); color: #fff; border-radius: 8px; padding: 28px 24px; margin-bottom: 16px; }
.hero h2 { margin: 0 0 8px; font-size: 1.7rem; }
.hero p { margin: 0; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat-card { background: #fff; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); padding: 20px; text-align: center; }
.stat-value { font-size: 2rem; font-weight: 700; color: #2471a3; }
.stat-label { color: #455a64; }
.quick-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.quick-link-card {
  display: block; background: #fff; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  padding: 20px; text-decoration: none; color: #2c3e50; text-align: center;
}
.quick-link-card:hover { box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15); }
.quick-link-card .icon { font-size: 2rem; }
.quick-link-card h3 { margin: 8px 0 4px; }
.quick-link-card p { margin: 0; color: #455a64; }

.state { text-align: center; padding: 32px 16px; background: #fff; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); }
.error-state { border-left: 4px solid #c0392b; }
.spinner {
  width: 32px; height: 32px; margin: 0 auto 8px; border: 4px solid #ecf0f1; border-top-color: #2471a3;
  border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

.landing { text-align: center; padding: 40px 20px; }

@media (max-width: 640px) {
  body { padding: 8px; }
  .header h1 { font-size: 1.25rem; }
  .pill { padding: 8px 12px; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { position: absolute; left: -9999px; }
  tr { border: 1px solid #ecf0f1; border-radius: 6px; margin-bottom: 12px; padding: 4px 0; }
  td, td.num { border: 0; text-align: left; padding: 6px 12px; white-space: normal; }
  td::before { content: attr(data-label); display: block; font-size: 0.85rem; font-weight: 600; color: #455a64; }
}

/* Wide desktop (1920 x 1080): use the width instead of a narrow centred column. */
@media (min-width: 1200px) {
  body { padding: 24px 40px; }
  main, .header { max-width: 1800px; }
}

/* Invoices description: two lines, ellipsis, full text in a tooltip on hover or keyboard focus. */
.clamp-wrap { position: relative; display: block; }
.clamp {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
  overflow: hidden; overflow-wrap: anywhere; cursor: default;
}
.col-description { min-width: 240px; max-width: 520px; }
.tip {
  display: none; position: fixed; z-index: 20; width: max-content; max-width: 440px;
  padding: 8px 12px; background: #263238; color: #fff; border-radius: 6px; font-size: 0.9rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); white-space: pre-wrap; overflow-wrap: anywhere;
}
.tip.show { display: block; }
@media (max-width: 640px) {
  .col-description { max-width: none; }
  .tip { max-width: calc(100vw - 16px); }
}

.pt-line { display: block; overflow-wrap: anywhere; }
.pt-tenant { font-size: 0.85em; line-height: 1.35; color: #455a64; }
.pt-tenant .row-link { font-weight: 400; }
.row-link { font-weight: 600; text-decoration: none; }
.row-link:hover, .row-link:focus-visible { text-decoration: underline; }
.billing .row-link { font-weight: inherit; }
.pdf-link { white-space: nowrap; }
.pdf-icon { width: 0.9em; height: 0.9em; margin-left: 0.35em; vertical-align: -0.1em; flex: none; }
.row-link:focus-visible, .chip-clear:focus-visible { outline: 3px solid #f39c12; outline-offset: 2px; border-radius: 2px; }
.filter-chip { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 0 0 12px; padding: 6px 12px; background: #e8f1f8; border-radius: 20px; font-weight: 600; }
.chip-clear { font-weight: 600; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 8px 12px; margin: 0 0 12px; }
.filter-chips .filter-chip { margin: 0; }

/* Tenancy dialog, form and actions. */
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 0 0 12px; }
.page-actions-bottom { margin: 16px 0 0; }
.saved-message { margin: 0 0 12px; font-weight: 600; color: #1e6f43; }
.saved-message:empty { display: none; }
.btn.small { padding: 4px 10px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.row-actions { display: inline-flex; flex-wrap: wrap; gap: 8px; }
.row-ended td, .row-ended .row-link { color: #5a6770; }
.btn.danger { background: #fff; border-color: #c0392b; color: #a5281b; }
.btn.danger:hover { background: #fdecea; }
.field-label { font-weight: 600; }
.readonly-value { margin: 0; padding: 8px 0; }
.end-view { display: flex; flex-direction: column; gap: 12px; }
.end-view p { margin: 0; }
.end-view .field { max-width: 16rem; }

.dialog { border: 0; border-radius: 8px; padding: 20px; width: min(640px, calc(100vw - 16px)); max-height: calc(100vh - 32px); overflow-y: auto; color: #2c3e50; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); }
.dialog::backdrop { background: rgba(38, 50, 56, 0.55); }
.dialog h2 { margin: 0 0 16px; padding-bottom: 8px; border-bottom: 2px solid #ecf0f1; font-size: 1.3rem; }
.dialog form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field[hidden] { display: none; }
.field.wide, .dialog form > .button-row { grid-column: 1 / -1; }
.field label { font-weight: 600; }
.field input:not([type="checkbox"]), .field select { font: inherit; padding: 8px 10px; border: 1px solid #90a4ae; border-radius: 6px; background: #fff; color: inherit; }
.field.check { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
.field.check .field-error { flex: 1 0 100%; }
.field.check input { width: 1.1rem; height: 1.1rem; }
.field-hint { margin: 0; font-size: 0.85rem; color: #455a64; }
.field-error { margin: 0; color: #c0392b; font-size: 0.9rem; font-weight: 600; }
.field-error:empty { display: none; }
.field [aria-invalid="true"] { border-color: #c0392b; border-width: 2px; }
.field input[aria-invalid="true"], .field select[aria-invalid="true"] { border: 2px solid #c0392b; }
.form-summary { margin: 0 0 12px; color: #c0392b; font-weight: 600; }
.form-summary:empty { display: none; }
.form-notice { margin: 0 0 12px; color: #2c3e50; font-weight: 600; }
.form-warning { margin: 0 0 12px; color: #8a5a00; }
.form-warning:empty { display: none; }
.button-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
@media (max-width: 640px) {
  .dialog form { grid-template-columns: minmax(0, 1fr); }
  .row-actions { padding-top: 4px; }
}
/* Phone menu and Billing cards. The one phone breakpoint is 640px (PHONE_MAX_WIDTH in js/logic/navigation.js). */
.menu-button, .menu-backdrop, .menu-panel { display: none; }
.billing-cards-wrap { display: none; }
@media (max-width: 640px) {
  .header { flex-wrap: nowrap; gap: 8px; }
  .header h1 { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
  .header .nav, .header .user { display: none; }
  .menu-button:not([hidden]) {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    width: 44px; height: 44px; min-height: 44px; padding: 0; border: 1px solid #b0bec5; border-radius: 6px;
    background: #fff; cursor: pointer;
  }
  .menu-bars, .menu-bars::before, .menu-bars::after { display: block; width: 22px; height: 3px; background: #2c3e50; border-radius: 2px; }
  .menu-bars { position: relative; }
  .menu-bars::before, .menu-bars::after { content: ""; position: absolute; left: 0; }
  .menu-bars::before { top: -7px; }
  .menu-bars::after { top: 7px; }
  .menu-backdrop:not([hidden]) { display: block; position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0, 0, 0, 0.4); z-index: 30; }
  .menu-panel:not([hidden]) {
    display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; width: min(80vw, 320px);
    overflow-y: auto; background: #fff; box-shadow: 2px 0 12px rgba(0, 0, 0, 0.3); z-index: 31; padding-top: 8px;
  }
  .menu-link { display: block; min-height: 44px; padding: 10px 16px; color: #2c3e50; font-weight: 600; text-decoration: none; }
  .menu-link:hover { background: #ecf0f1; }
  .menu-link[aria-current="page"] { background: #2471a3; color: #fff; }
  .menu-footer { margin-top: auto; padding: 16px; border-top: 1px solid #ecf0f1; display: flex; flex-direction: column; gap: 8px; }
  .menu-footer .btn { min-height: 44px; }
  body.menu-open { overflow: hidden; }
  .billing-table { display: none; }
  .billing-cards-wrap { display: block; }
  .card.billing { padding: 12px; }
  .billing caption { display: block; width: 100%; }
  .billing-caption { display: block; margin: 0 0 8px; font-weight: 600; color: #455a64; overflow-wrap: break-word; }
  .billing-cards { display: block; list-style: none; margin: 0; padding: 0; }
  .billing-card { padding: 10px 0; border-bottom: 1px solid #ecf0f1; font-size: 1.15rem; }
  .billing-card:last-child { border-bottom: 0; }
  .bc-invoice { margin-top: 4px; }
  .bc-figures { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0; }
  .bc-field { min-width: 0; }
  .bc-label { display: block; font-size: 0.8rem; color: #455a64; }
  .bc-value { display: block; font-size: 1.15rem; overflow-wrap: anywhere; }
}
@media (max-width: 640px) and (prefers-reduced-motion: no-preference) {
  .menu-panel:not([hidden]) { animation: menu-slide 0.15s ease-out; }
}
@keyframes menu-slide { from { transform: translateX(-100%); } to { transform: translateX(0); } }
