/* CONDOMÍNIO PWA - Stylesheet (editorial / refined) */
:root {
  --bg: #f5f2ec; --bg-elev: #ffffff; --bg-sunken: #ebe6dd;
  --ink: #1a2332; --ink-soft: #4a5567; --ink-muted: #8892a6;
  --line: #d8d1c3; --line-soft: #e8e3d8;
  --accent: #1e3a5f; --accent-soft: #2d5282; --accent-bg: #e8eef5;
  --gold: #b8956a;
  --success: #4a7c59; --success-bg: #e3eee5;
  --warn: #c97c3f; --warn-bg: #f7ebd9;
  --danger: #b8413c; --danger-bg: #f5dcd9;
  --radius: 4px; --radius-lg: 8px;
  --shadow-sm: 0 1px 2px rgba(26,35,50,.06);
  --shadow: 0 2px 8px rgba(26,35,50,.08), 0 1px 2px rgba(26,35,50,.04);
  --shadow-lg: 0 8px 24px rgba(26,35,50,.12);
  --font-display: 'Fraunces', Georgia, serif;
  --font-sans: 'Inter', -apple-system, sans-serif;
  --header-h: 64px; --sidebar-w: 240px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font-sans); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1rem; }

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }

/* LOGIN */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at 20% 20%, rgba(30,58,95,.08), transparent 50%),
              radial-gradient(circle at 80% 80%, rgba(184,149,106,.08), transparent 50%), var(--bg); }
.login-card { width: 100%; max-width: 420px; background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 48px 36px; box-shadow: var(--shadow-lg); }
.login-brand { text-align: center; margin-bottom: 36px; }
.login-logo { width: 56px; height: 56px; margin: 0 auto 16px; color: var(--accent); }
.login-brand h1 { font-family: var(--font-display); font-size: 1.875rem; font-weight: 600; margin-bottom: 4px; }
.login-brand p { color: var(--ink-muted); font-size: 0.875rem; letter-spacing: 0.04em; text-transform: uppercase; }
.login-form { display: grid; gap: 20px; }
.login-form label { display: grid; gap: 6px; font-size: 0.875rem; }
.login-form label span { color: var(--ink-soft); font-weight: 500; }
.login-form input { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); transition: border-color .15s; }
.login-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.login-footer { margin-top: 24px; text-align: center; font-size: 0.75rem; color: var(--ink-muted); }
.error-msg { padding: 10px 12px; background: var(--danger-bg); color: var(--danger); border-radius: var(--radius); font-size: 0.875rem; }

/* BUTTONS */
.btn-primary { padding: 11px 16px; background: var(--accent); color: white; border-radius: var(--radius); font-weight: 500; transition: background .15s; }
.btn-primary:hover { background: var(--accent-soft); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { padding: 9px 14px; background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); font-weight: 500; transition: all .15s; }
.btn-secondary:hover { background: var(--bg-sunken); }
.btn-icon { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius); color: var(--ink-soft); transition: background .15s; }
.btn-icon:hover { background: var(--bg-sunken); }
.btn-danger { padding: 9px 14px; background: var(--danger); color: white; border-radius: var(--radius); font-weight: 500; }

/* HEADER */
.app-header { position: fixed; top: 0; left: 0; right: 0; height: var(--header-h); display: flex; align-items: center; gap: 16px; padding: 0 20px; background: var(--bg-elev); border-bottom: 1px solid var(--line); z-index: 100; }
.menu-toggle { display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius); color: var(--ink-soft); }
.menu-toggle:hover { background: var(--bg-sunken); }
.header-title { flex: 1; min-width: 0; }
.header-eyebrow { display: block; font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-muted); font-weight: 600; }
#view-title { font-size: 1.125rem; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-user { display: flex; align-items: center; gap: 12px; }
#user-name { font-size: 0.875rem; color: var(--ink-soft); }

/* SIDEBAR */
.sidebar { position: fixed; top: var(--header-h); left: 0; bottom: 0; width: var(--sidebar-w); background: var(--bg-elev); border-right: 1px solid var(--line); padding: 24px 12px; overflow-y: auto; z-index: 50; transform: translateX(-100%); transition: transform .25s ease; }
.sidebar.open { transform: translateX(0); }
.sidebar-section { margin-bottom: 24px; }
.sidebar-section h3 { font-family: var(--font-sans); font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-muted); padding: 0 12px 8px; margin: 0; }
.sidebar a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius); color: var(--ink-soft); font-size: 0.9375rem; margin-bottom: 2px; transition: all .15s; }
.sidebar a:hover { background: var(--bg-sunken); color: var(--ink); }
.sidebar a.active { background: var(--accent-bg); color: var(--accent); font-weight: 500; }

.sidebar-backdrop { position: fixed; inset: var(--header-h) 0 0 0; background: rgba(26,35,50,.4); z-index: 49; opacity: 0; pointer-events: none; transition: opacity .25s; }
.sidebar-backdrop.active { opacity: 1; pointer-events: auto; }

body.is-condomino .admin-only { display: none; }
body:not(.is-condomino) .condomino-only { display: none; }

@media (min-width: 1024px) {
  .sidebar { transform: translateX(0); }
  .sidebar-backdrop { display: none; }
  .menu-toggle { display: none; }
  .view-container { margin-left: var(--sidebar-w); }
}

/* VIEW */
.view-container { margin-top: var(--header-h); padding: 24px 20px 80px; min-height: calc(100vh - var(--header-h)); }
@media (min-width: 768px) { .view-container { padding: 32px 32px 80px; } }

.loading-spinner { display: grid; place-items: center; padding: 60px 0; }
.loading-spinner div { width: 32px; height: 32px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* CARDS */
.card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm); }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 28px; }
.kpi-card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px 20px; position: relative; overflow: hidden; }
.kpi-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--accent); }
.kpi-card.success::before { background: var(--success); }
.kpi-card.warn::before { background: var(--warn); }
.kpi-card.danger::before { background: var(--danger); }
.kpi-card.gold::before { background: var(--gold); }
.kpi-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-muted); font-weight: 600; }
.kpi-value { font-family: var(--font-display); font-size: 1.875rem; font-weight: 600; margin-top: 6px; color: var(--ink); }
.kpi-meta { font-size: 0.8125rem; color: var(--ink-soft); margin-top: 4px; }

.section-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 28px 0 16px; }
.section-header h2 { font-family: var(--font-display); font-size: 1.375rem; }

/* TABLES */
.table-wrapper { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table thead { background: var(--bg-sunken); border-bottom: 1px solid var(--line); }
.data-table th { text-align: left; padding: 10px 14px; font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); }
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.data-table tbody tr:hover { background: var(--bg-sunken); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .actions { text-align: right; white-space: nowrap; }

/* BADGES */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 500; background: var(--bg-sunken); color: var(--ink-soft); }
.badge.success { background: var(--success-bg); color: var(--success); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.accent { background: var(--accent-bg); color: var(--accent); }
.badge.gold { background: rgba(184,149,106,.18); color: var(--gold); }

/* FORMS */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.form-group { display: grid; gap: 6px; }
.form-group label { font-size: 0.8125rem; color: var(--ink-soft); font-weight: 500; }
.form-group input, .form-group select, .form-group textarea {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); transition: border-color .15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.form-group textarea { min-height: 80px; resize: vertical; font-family: inherit; }
.form-actions { margin-top: 20px; display: flex; gap: 10px; justify-content: flex-end; }

/* MODAL */
.modal-backdrop { position: fixed; inset: 0; background: rgba(26,35,50,.5); display: grid; place-items: center; padding: 16px; z-index: 200; animation: fadeIn .15s; }
@keyframes fadeIn { from { opacity: 0 } }
/* O modal inteiro faz scroll quando o conteudo ultrapassa a altura do ecra,
   garantindo que os botoes do fundo (Guardar / Cancelar) sao sempre alcancaveis. */
.modal { background: var(--bg-elev); border-radius: var(--radius-lg); width: 100%; max-width: 640px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: slideUp .2s; overflow-y: auto; }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0 } }
.modal-header { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-header h2 { font-size: 1.125rem; }
.modal-body { padding: 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }

/* TOASTS */
.toast-container { position: fixed; top: calc(var(--header-h) + 16px); right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 300; pointer-events: none; }
.toast { padding: 12px 16px; background: var(--bg-elev); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); font-size: 0.875rem; max-width: 320px; pointer-events: auto; animation: slideIn .2s; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0 } }

/* EMPTY STATE */
.empty-state { text-align: center; padding: 48px 20px; color: var(--ink-muted); }
.empty-state svg { margin: 0 auto 14px; opacity: 0.4; }
.empty-state p { font-size: 0.9375rem; }

/* UTILITIES */
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.text-muted { color: var(--ink-muted); }
.text-soft { color: var(--ink-soft); }
.text-mono { font-variant-numeric: tabular-nums; }
.text-right { text-align: right; }
.text-sm { font-size: 0.875rem; }
.font-display { font-family: var(--font-display); }

@media (max-width: 640px) {
  .view-container { padding: 16px 14px 80px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-card { padding: 14px; }
  .kpi-value { font-size: 1.5rem; }
  .data-table th, .data-table td { padding: 10px 8px; font-size: 0.8125rem; }
  #user-name { display: none; }
}
