:root {
  --ink: #1c1830;
  --muted: #6b6780;
  --paper: #f7f6fb;
  --surface: #ffffff;
  --line: #e4e1ee;
  --primary: #7c3aed;
  --primary-dark: #6d28d9;
  --primary-soft: #ede9fe;
  --amber: #8a5a12;
  --amber-soft: #fff1cf;
  --shadow: 0 8px 30px rgba(46, 16, 101, 0.07);
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

a { color: var(--primary); }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .35rem; font-size: clamp(2rem, 4vw, 3rem); line-height: 1.08; letter-spacing: -.035em; }
h2 { font-size: 1.25rem; line-height: 1.3; }
h3 { font-size: 1.05rem; }

.skip-link { position: absolute; left: -9999px; top: .5rem; z-index: 10; padding: .7rem 1rem; background: #fff; }
.skip-link:focus { left: .5rem; }

.site-header { position: sticky; top: 0; z-index: 5; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); backdrop-filter: blur(10px); }
.header-inner { max-width: 1180px; margin: 0 auto; padding: .9rem 1.4rem; display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; }
.brand { color: var(--ink); font-size: 1.3rem; font-weight: 800; letter-spacing: -.03em; text-decoration: none; }
.main-nav { display: flex; align-items: center; gap: .35rem; }
.main-nav > a, .nav-button { display: inline-flex; padding: .65rem .75rem; color: #435049; background: transparent; border: 0; border-radius: .5rem; font: inherit; font-weight: 650; text-decoration: none; cursor: pointer; }
.main-nav > a:hover, .nav-button:hover { color: var(--primary); background: var(--primary-soft); }
.logout-form { margin: 0; }

.page-shell { max-width: 1180px; margin: 0 auto; padding: 3.5rem 1.4rem 5rem; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 1.5rem; margin-bottom: 2rem; }
.eyebrow { margin-bottom: .4rem; color: var(--primary); font-size: .8rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.muted { color: var(--muted); }
.back-link { display: inline-block; margin-bottom: 1rem; color: var(--muted); font-weight: 650; text-decoration: none; }
.back-link:hover, .text-link:hover { text-decoration: underline; }

.button { display: inline-flex; min-height: 46px; align-items: center; justify-content: center; padding: .72rem 1.05rem; border: 1px solid transparent; border-radius: .65rem; font: inherit; font-weight: 750; line-height: 1.2; text-decoration: none; cursor: pointer; }
.button-primary { color: #fff; background: var(--primary); }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { color: var(--primary); background: #fff; border-color: #D1C4E9; }
.button-secondary:hover { border-color: var(--primary); background: var(--primary-soft); }
.button-quiet { color: var(--muted); background: transparent; }
.button-wide { width: 100%; }

.messages { margin-bottom: 1.5rem; }
.message { padding: .9rem 1rem; border: 1px solid #D1C4E9; border-radius: .6rem; background: var(--primary-soft); color: var(--primary-dark); }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1.15rem; }
.apartment-card { display: flex; min-height: 290px; flex-direction: column; padding: 1.35rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 1rem; box-shadow: var(--shadow); text-decoration: none; transition: transform .15s ease, border-color .15s ease; }
.apartment-card:hover { transform: translateY(-2px); border-color: var(--primary); }
.card-topline { display: flex; align-items: flex-start; justify-content: space-between; gap: .8rem; }
.card-topline h2 { font-size: 1.5rem; }
.card-link { margin-top: auto; color: var(--primary); font-weight: 750; }
.status-pill { display: inline-flex; align-items: center; width: fit-content; padding: .28rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 800; white-space: nowrap; }
.status-rented { color: var(--primary-dark); background: var(--primary-soft); }
.status-free { color: #4a5560; background: #edf0f2; }
.status-warning { color: var(--amber); background: var(--amber-soft); }
.status-neutral { color: #4d5b54; background: #eef1ef; }
.summary-list, .detail-list { margin: .9rem 0 1.4rem; }
.summary-list div { padding: .6rem 0; border-bottom: 1px solid #edf0ed; }
.summary-list dt, .detail-list dt { color: var(--muted); font-size: .82rem; font-weight: 700; }
.summary-list dd, .detail-list dd { margin: .1rem 0 0; font-weight: 700; }
.empty-inline { color: var(--muted); }

.list-cards { display: grid; gap: .8rem; }
.list-card { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; padding: 1.2rem 1.35rem; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: .85rem; text-decoration: none; }
.list-card:hover { border-color: var(--primary); }
.list-card h2 { margin-bottom: .25rem; }
.list-card p { margin-bottom: 0; color: var(--muted); }
.list-card-meta { display: flex; align-items: flex-end; flex-direction: column; gap: .45rem; color: var(--muted); text-align: right; }

.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.2rem; }
.panel { padding: 1.5rem; background: #fff; border: 1px solid var(--line); border-radius: .9rem; box-shadow: 0 3px 18px rgba(24,50,39,.04); }
.panel-spaced { margin-top: 1.2rem; }
.detail-narrow { max-width: 760px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.2rem; margin-bottom: 1.2rem; }
.section-heading h2 { margin-bottom: .25rem; }
.section-heading p { margin-bottom: 0; }
.detail-list { margin-bottom: 0; }
.detail-list div { display: grid; grid-template-columns: minmax(125px, .65fr) 1.35fr; gap: 1rem; padding: .8rem 0; border-bottom: 1px solid #edf0ed; }
.detail-list div:last-child { border-bottom: 0; }
.detail-list dd { overflow-wrap: anywhere; }
.text-link { color: var(--primary); font-weight: 750; text-decoration: none; }
.meter-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; }
.meter-card { display: flex; justify-content: space-between; gap: 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: .7rem; }
.meter-card h3 { margin: .25rem 0; }
.meter-card p { margin: 0; color: var(--muted); }
.meter-type { color: var(--primary); font-size: .75rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.history-list { display: grid; gap: .5rem; }
.history-list a { display: grid; grid-template-columns: 1fr 1fr auto; align-items: center; gap: 1rem; padding: .85rem; color: var(--ink); background: #fafbfa; border-radius: .55rem; text-decoration: none; }

.document-create-actions, .document-actions { display: flex; flex-wrap: wrap; gap: .65rem; }
.document-create-actions { margin-bottom: 1.25rem; }
.document-create-actions form, .document-actions form { margin: 0; }
.document-list { display: grid; gap: 1rem; }
.document-card { padding: 1.15rem; border: 1px solid var(--line); border-radius: .75rem; background: #fafbfa; }
.document-card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.document-card-heading h3 { margin-bottom: .2rem; }
.document-card-heading p { margin-bottom: .75rem; }
.version-label { color: var(--muted); font-weight: 650; }
.document-meta { overflow-wrap: anywhere; color: var(--muted); font-size: .86rem; }
.document-meta code { font-size: .8em; }
.upload-correction { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .8rem; }
.upload-correction summary { color: var(--primary); font-weight: 750; cursor: pointer; }
.upload-form { display: grid; gap: .55rem; margin-top: .8rem; max-width: 600px; }
.upload-form label { font-weight: 700; }
.document-empty { margin: 1rem 0 0; }
.delivery-list { margin-top: .8rem; }
.delivery-list p { margin-bottom: .25rem; }

.settings-panel { max-width: 760px; }
.status-line { margin-bottom: 1rem; }
.inline-email-form { display: grid; grid-template-columns: minmax(220px, 1fr) auto; align-items: end; gap: .75rem; max-width: 680px; }
.settings-secondary-action { margin-top: .75rem; }

.empty-state { max-width: 680px; padding: 3rem 2rem; background: #fff; border: 1px dashed #bfcac4; border-radius: 1rem; text-align: center; }
.empty-state p { color: var(--muted); }

.form-page { max-width: 720px; margin: 0 auto; }
.stacked-form { display: grid; gap: 1.15rem; }
.form-row { display: grid; gap: .4rem; }
.form-row label { font-weight: 750; }
.form-control, .stacked-form input:not([type="hidden"]):not([type="checkbox"]) { width: 100%; min-height: 48px; padding: .7rem .8rem; color: var(--ink); background: #fff; border: 1px solid #c9c3da; border-radius: .55rem; font: inherit; }
textarea.form-control { min-height: 110px; resize: vertical; }
.form-control:focus, .stacked-form input:focus { outline: 3px solid rgba(124,58,237,.16); border-color: var(--primary); }
.checkbox-row { grid-template-columns: auto 1fr; align-items: center; }
.form-checkbox { width: 22px; height: 22px; accent-color: var(--primary); }
.form-actions { display: flex; gap: .65rem; padding-top: .4rem; }
.form-errors, .field-error { color: #8b2525; }
.form-errors { padding: .8rem; background: #fff0ef; border-radius: .5rem; }
.form-errors p { margin: 0; }
.help-text { color: var(--muted); font-size: .88rem; }
.required-mark { color: var(--primary); }

.form-page-wide { max-width: 960px; }
.page-lead { margin-bottom: 1.6rem; }
.new-tenant-form { display: grid; gap: 1.2rem; }
.form-section-heading { display: flex; align-items: flex-start; gap: .9rem; margin-bottom: 1.3rem; }
.form-section-heading h2 { margin-bottom: .15rem; }
.form-section-heading p { margin: 0; }
.step-badge { display: inline-flex; flex: 0 0 auto; width: 34px; height: 34px; align-items: center; justify-content: center; color: #fff; background: var(--primary); border-radius: 999px; font-weight: 800; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.05rem 1.2rem; }
.panel-actions { display: flex; flex-wrap: wrap; gap: .65rem; margin-top: 1.3rem; }
.form-actions-sticky { position: sticky; bottom: 0; padding: 1rem 0; background: linear-gradient(to top, var(--paper) 70%, rgba(247,246,251,0)); }

.auth-card { max-width: 440px; margin: 4rem auto; padding: 2rem; background: #fff; border: 1px solid var(--line); border-radius: 1rem; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 2.2rem; }

@media (max-width: 850px) {
  .header-inner { align-items: flex-start; flex-direction: column; gap: .7rem; }
  .main-nav { width: 100%; overflow-x: auto; padding-bottom: .15rem; }
  .main-nav > a, .nav-button { white-space: nowrap; }
  .card-grid, .meter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .page-shell { padding: 2rem 1rem 4rem; }
  .header-inner { padding: .8rem 1rem; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .page-heading > .button { width: 100%; }
  .card-grid, .detail-grid, .meter-grid, .form-grid { grid-template-columns: 1fr; }
  .panel-actions { flex-direction: column; }
  .panel-actions .button { width: 100%; }
  .apartment-card { min-height: 250px; }
  .list-card { align-items: flex-start; flex-direction: column; }
  .list-card-meta { align-items: flex-start; text-align: left; }
  .section-heading { align-items: stretch; flex-direction: column; }
  .section-heading .button { width: 100%; }
  .detail-list div { grid-template-columns: 1fr; gap: .15rem; }
  .history-list a { grid-template-columns: 1fr; gap: .25rem; }
  .document-card-heading { flex-direction: column; }
  .document-create-actions, .document-actions { flex-direction: column; }
  .document-create-actions .button, .document-actions .button, .document-actions form { width: 100%; }
  .form-actions { flex-direction: column; }
  .form-actions .button { width: 100%; }
  .inline-email-form { grid-template-columns: 1fr; }
  .inline-email-form .button, .settings-secondary-action .button { width: 100%; }
}
