/* Premavo — mobile-first fire safety portal styles.
   Extends @core/ui/styles.css. Load after /core/styles.css. */

:root {
    --brand: #0d9488;          /* primary teal (buttons, links, active nav) */
    --brand-dark: #0f766e;     /* deep teal — headers, active text */
    --brand-light: #ecfdf5;    /* pale emerald — active nav background */
    --accent-red: #dc2626;     /* red accent (alerts, violations) */
    --status-ok: #16a34a;
    --status-warn: #d97706;
    --status-fail: #dc2626;
    --status-ok-bg: #f0fdf4;
    --status-warn-bg: #fffbeb;
    --status-fail-bg: #fef2f2;
    --nav-h: 56px;
    --header-h: 60px;
}

/* ---- Reset & base ---- */
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f4f4f5; color: #18181b; font-size: 16px; }

/* ---- View switching ---- */
.view { display: none; }
.view.active { display: flex; flex-direction: column; min-height: 100vh; }

/* ---- Login view ---- */
#view-login { align-items: center; justify-content: center; background: #f9fafb; min-height: 100vh; padding: 24px 16px; }
.login-card { background: white; border-radius: 16px; padding: 32px 24px; width: 100%; max-width: 380px; box-shadow: 0 4px 24px rgba(0,0,0,.08); }
.login-brand { text-align: center; margin-bottom: 28px; }
.login-brand .flame { width: 44px; height: 44px; color: var(--brand); display: block; margin: 0 auto 8px; }
.login-brand h1 { font-size: 24px; font-weight: 700; color: var(--brand); margin: 0; }
.login-brand p { color: #6b7280; font-size: 14px; margin: 4px 0 0; }

/* ---- Buildings list view ---- */
#view-buildings { background: #f4f4f5; }
.app-bar { display: flex; align-items: center; justify-content: space-between; background: var(--brand-dark); color: white; padding: 0 16px; height: var(--header-h); flex-shrink: 0; }
.app-bar .app-title { font-size: 18px; font-weight: 700; }
.app-bar .app-user { font-size: 13px; opacity: .85; }

.buildings-list { padding: 16px; flex: 1; }
.buildings-list h2 { font-size: 17px; font-weight: 600; color: #374151; margin: 0 0 12px; }
.building-card { background: white; border-radius: 12px; padding: 16px; margin-bottom: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.07); cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 12px; transition: box-shadow .15s; }
.building-card:active { box-shadow: 0 0 0 2px var(--brand); }
.building-card .bc-info { flex: 1; min-width: 0; }
.building-card .bc-name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.building-card .bc-address { font-size: 13px; color: #6b7280; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.building-card .bc-badges { display: flex; gap: 6px; flex-shrink: 0; }
.building-card .bc-arrow { color: #9ca3af; font-size: 18px; flex-shrink: 0; }
.add-building-btn { width: 100%; margin-top: 4px; }

/* ---- Status badges ---- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.compliant  { background: var(--status-ok-bg);   color: var(--status-ok); }
.badge.issues     { background: var(--status-warn-bg);  color: var(--status-warn); }
.badge.unknown    { background: #f3f4f6; color: #6b7280; }
.badge.pass       { background: var(--status-ok-bg);   color: var(--status-ok); }
.badge.fail       { background: var(--status-fail-bg); color: var(--status-fail); }
.badge.ok         { background: var(--status-ok-bg);   color: var(--status-ok); }
.badge.attention  { background: var(--status-warn-bg);  color: var(--status-warn); }
.badge.overdue    { background: var(--status-fail-bg); color: var(--status-fail); }
.badge.open       { background: var(--status-fail-bg); color: var(--status-fail); }
.badge.resolved   { background: var(--status-ok-bg);   color: var(--status-ok); }
.badge.alert      { background: var(--status-fail-bg); color: var(--status-fail); font-size: 11px; padding: 2px 8px; }

/* ---- Building view ---- */
#view-building { background: #f4f4f5; }
.building-header { background: var(--brand-dark); color: white; padding: 0 16px; height: var(--header-h); display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.building-header .back-btn { background: none; border: none; color: white; font-size: 22px; cursor: pointer; padding: 4px; line-height: 1; opacity: .9; flex-shrink: 0; }
.building-header .bh-info { flex: 1; min-width: 0; }
.building-header .bh-name { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.building-header .bh-status { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.building-header .bh-status .badge { background: rgba(255,255,255,.2); color: white; font-size: 11px; }

/* ---- Module menu (big thumb-friendly buttons on the building dashboard) ---- */
.module-menu { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.module-menu .mm-btn { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; background: white; border: none; border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.07); cursor: pointer; transition: box-shadow .15s; }
.module-menu .mm-btn:active { box-shadow: 0 0 0 2px var(--brand); }
.module-menu .mm-icon { font-size: 22px; width: 44px; height: 44px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; background: var(--brand-light); border-radius: 10px; }
.module-menu .mm-label { flex: 1; font-size: 16px; font-weight: 600; color: #111; }
.module-menu .mm-arrow { color: #9ca3af; font-size: 20px; flex-shrink: 0; }

/* ---- Module content ---- */
.module-content { flex: 1; overflow-y: auto; padding: 16px; }

/* ---- Dashboard module ---- */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat-card { background: white; border-radius: 10px; padding: 14px; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.stat-card .stat-n { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-card .stat-l { font-size: 12px; color: #6b7280; margin-top: 4px; }
.stat-card.danger .stat-n { color: var(--status-fail); }
.stat-card.warn .stat-n   { color: var(--status-warn); }
.stat-card.ok .stat-n     { color: var(--status-ok); }

.alert-list { background: white; border-radius: 10px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.06); margin-bottom: 14px; }
.alert-list h3 { font-size: 14px; font-weight: 600; color: #374151; margin: 0 0 10px; }
.alert-item { display: flex; align-items: flex-start; gap: 8px; padding: 6px 0; border-bottom: 1px solid #f3f4f6; font-size: 14px; }
.alert-item:last-child { border-bottom: none; padding-bottom: 0; }
.alert-item .ai-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.no-alerts { color: #6b7280; font-size: 14px; text-align: center; padding: 8px 0; }

.dashboard-meta { background: white; border-radius: 10px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.06); margin-bottom: 14px; }
.dashboard-meta h3 { font-size: 14px; font-weight: 600; color: #374151; margin: 0 0 10px; }
.meta-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid #f3f4f6; font-size: 14px; }
.meta-row:last-child { border-bottom: none; }
.meta-row .mr-label { color: #6b7280; }
.meta-row .mr-val { font-weight: 500; }

.qr-section { background: white; border-radius: 10px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.06); text-align: center; margin-bottom: 14px; }
.qr-section h3 { font-size: 14px; font-weight: 600; margin: 0 0 10px; }
.qr-section img, .qr-section svg { max-width: 180px; height: auto; }

/* ---- Generic card & section ---- */
.section-card { background: white; border-radius: 10px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.06); margin-bottom: 12px; }
.section-card h3 { font-size: 15px; font-weight: 600; color: #111; margin: 0 0 12px; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-header h3 { margin: 0; }

/* ---- Lists ---- */
.item-list { list-style: none; padding: 0; margin: 0; }
.item-list li { padding: 11px 0; border-bottom: 1px solid #f3f4f6; font-size: 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.item-list li:last-child { border-bottom: none; padding-bottom: 0; }
.item-list .il-main { flex: 1; min-width: 0; }
.item-list .il-title { font-weight: 500; }
.item-list .il-sub { font-size: 12px; color: #6b7280; margin-top: 2px; }
.item-list .il-actions { display: flex; gap: 6px; flex-shrink: 0; }
.empty-state { text-align: center; padding: 24px 0; color: #9ca3af; font-size: 14px; }

/* ---- Forms ---- */
.form-card { background: white; border-radius: 10px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.06); margin-bottom: 12px; }
.form-card h3 { font-size: 15px; font-weight: 600; margin: 0 0 14px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 500; color: #374151; margin-bottom: 5px; }
.field input, .field select, .field textarea { width: 100%; padding: 11px 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 15px; background: white; color: #111; appearance: none; -webkit-appearance: none; }
.field textarea { min-height: 72px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(13,148,136,.15); }
.field .hint { font-size: 12px; color: #9ca3af; margin-top: 4px; }

/* ---- Result toggle (pass/fail) ---- */
.result-toggle { display: flex; gap: 8px; }
.result-toggle label { flex: 1; }
.result-toggle input[type=radio] { display: none; }
.result-toggle .rt-btn { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 11px; border: 2px solid #e5e7eb; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; color: #6b7280; transition: all .15s; }
.result-toggle input:checked + .rt-btn.pass-btn { border-color: var(--status-ok); background: var(--status-ok-bg); color: var(--status-ok); }
.result-toggle input:checked + .rt-btn.fail-btn { border-color: var(--status-fail); background: var(--status-fail-bg); color: var(--status-fail); }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 20px; border: none; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; transition: opacity .15s; text-decoration: none; }
.btn:active { opacity: .8; }
.btn.primary { background: var(--brand); color: white; }
.btn.secondary { background: #f3f4f6; color: #374151; }
.btn.danger { background: var(--status-fail-bg); color: var(--status-fail); }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 6px; }
.btn.full { width: 100%; }
.btn.ghost { background: none; border: 1px solid #e5e7eb; color: #374151; }

/* ---- Error text ---- */
.err { color: var(--status-fail); font-size: 13px; min-height: 18px; margin-top: 6px; }

/* ---- Table ---- */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { text-align: left; font-size: 12px; font-weight: 600; color: #6b7280; padding: 6px 8px 8px; border-bottom: 2px solid #e5e7eb; }
.data-table td { padding: 10px 8px; border-bottom: 1px solid #f3f4f6; vertical-align: top; }
.data-table tr:last-child td { border-bottom: none; }

/* ---- Register cards ---- */
.register-card { background: white; border-radius: 10px; padding: 16px; margin-bottom: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.06); cursor: pointer; display: flex; align-items: center; gap: 12px; }
.register-card .rc-icon { font-size: 28px; flex-shrink: 0; }
.register-card .rc-info { flex: 1; min-width: 0; }
.register-card .rc-name { font-weight: 600; font-size: 15px; }
.register-card .rc-meta { font-size: 12px; color: #6b7280; margin-top: 3px; }
.register-card .rc-arrow { color: #9ca3af; font-size: 18px; }

/* ---- Collapsible form ---- */
.collapsible-form { display: none; }
.collapsible-form.open { display: block; }

/* ---- Report ---- */
.report-section { margin-bottom: 20px; }
.report-section h4 { font-size: 13px; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: .04em; margin: 0 0 10px; }
.report-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.rs-item { background: white; border-radius: 8px; padding: 12px; text-align: center; }
.rs-item .rs-n { font-size: 24px; font-weight: 700; }
.rs-item .rs-l { font-size: 11px; color: #6b7280; margin-top: 2px; }

/* ---- Spinner ---- */
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid #e5e7eb; border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 32px; color: #6b7280; font-size: 14px; }

/* ---- Toast ---- */
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #18181b; color: white; padding: 10px 20px; border-radius: 8px; font-size: 14px; font-weight: 500; z-index: 999; opacity: 0; transition: opacity .2s; pointer-events: none; white-space: nowrap; max-width: 90vw; }
#toast.show { opacity: 1; }

/* ---- Install app banner ---- */
.install-banner {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 998;
    background: #fff; border-top: 1px solid #e3e8ef; box-shadow: 0 -4px 20px rgba(16,24,40,.1);
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.install-banner-icon { font-size: 20px; flex-shrink: 0; }
.install-banner-text { flex: 1; min-width: 160px; font-size: 13.5px; color: #1f2937; }
.install-banner-actions { display: flex; gap: 8px; flex-shrink: 0; }
@media (prefers-color-scheme: dark) {
    .install-banner { background: #18181b; border-top-color: #27272a; }
    .install-banner-text { color: #e4e4e7; }
}

/* ---- Portfolio dashboard (marries the multi-property overview into the spec) ---- */
.portfolio { padding: 16px; flex: 1; overflow-y: auto; }
.portfolio section { margin-bottom: 24px; }
.portfolio h2 { font-size: 17px; font-weight: 600; color: #374151; margin: 0 0 12px; }

.portfolio-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 22px; }
.pf-stat { background: white; border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.07); border-left: 4px solid #cbd5e1; }
.pf-stat .pf-n { font-size: 30px; font-weight: 700; line-height: 1; color: #1e293b; }
.pf-stat .pf-l { font-size: 12px; color: #6b7280; margin-top: 6px; }
.pf-stat.upcoming { border-left-color: var(--brand); }
.pf-stat.upcoming .pf-n { color: var(--brand); }
.pf-stat.danger   { border-left-color: var(--accent-red); }
.pf-stat.danger .pf-n { color: var(--accent-red); }
.pf-stat.warn     { border-left-color: var(--status-warn); }
.pf-stat.warn .pf-n   { color: var(--status-warn); }
.pf-stat.ok       { border-left-color: var(--status-ok); }
.pf-stat.ok .pf-n     { color: var(--status-ok); }

.recent-activity .act-item { display: flex; align-items: center; gap: 12px; background: white; border-radius: 10px; padding: 12px 14px; margin-bottom: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.recent-activity .act-icon { font-size: 18px; flex-shrink: 0; }
.recent-activity .act-main { flex: 1; min-width: 0; }
.recent-activity .act-title { font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-activity .act-sub { font-size: 12px; color: #6b7280; margin-top: 2px; }

/* ---- Responsive: desktop ---- */
@media (min-width: 640px) {
    .module-content { max-width: 720px; margin: 0 auto; }
    .dashboard-grid { grid-template-columns: repeat(4, 1fr); }
    .report-summary { grid-template-columns: repeat(4, 1fr); }
    .portfolio { max-width: 920px; margin: 0 auto; width: 100%; }
    .portfolio-stats { grid-template-columns: repeat(4, 1fr); }
    .module-menu { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
}

/* ============================================================
   Admin app shell: desktop sidebar + responsive dashboard panels
   ============================================================ */
#view-buildings.active { flex-direction: row; align-items: stretch; }

.sidebar { width: 220px; flex-shrink: 0; background: var(--brand-dark); color: #cbd5e1; display: flex; flex-direction: column; }
.sidebar .sb-brand { padding: 18px; font-size: 18px; font-weight: 700; color: #fff; display: flex; align-items: center; gap: 8px; }
.sidebar nav { display: flex; flex-direction: column; padding: 6px 0; }
.sidebar nav button { display: flex; align-items: center; gap: 10px; background: none; border: none; color: #cbd5e1; padding: 12px 18px; font-size: 14px; font-weight: 500; cursor: pointer; text-align: left; border-left: 3px solid transparent; }
.sidebar nav button:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav button.active { background: rgba(255,255,255,.10); color: #fff; border-left-color: #fff; font-weight: 600; }
.sidebar .sb-icon { width: 20px; text-align: center; }

.shell-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.section-nav { display: none; }

@media (max-width: 899px) {
    #view-buildings.active { flex-direction: column; }
    .sidebar { display: none; }
    .section-nav { display: flex; overflow-x: auto; background: #fff; border-bottom: 1px solid #e5e7eb; scrollbar-width: none; }
    .section-nav::-webkit-scrollbar { display: none; }
    .section-nav button { flex-shrink: 0; padding: 12px 16px; border: none; background: none; font-size: 14px; font-weight: 500; color: #6b7280; cursor: pointer; white-space: nowrap; border-bottom: 3px solid transparent; }
    .section-nav button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
}

/* ---- Dashboard ---- */
.dash { padding: 16px; flex: 1; overflow-y: auto; }
.dash-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.dash-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.dash h2 { font-size: 18px; font-weight: 700; margin: 0 0 14px; color: #111; }

.panel { background: #fff; border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.panel > h3 { font-size: 14px; font-weight: 600; margin: 0 0 12px; color: #374151; display: flex; justify-content: space-between; align-items: center; }
.panel .panel-link { font-size: 12px; color: var(--brand); cursor: pointer; font-weight: 500; }
.panel.span2 { grid-column: 1 / -1; }

.quick-actions { display: flex; flex-direction: column; gap: 8px; }
.quick-actions .btn { justify-content: flex-start; width: 100%; }

@media (min-width: 900px) {
    .dash { max-width: 1120px; }
    .dash-stats { grid-template-columns: repeat(4, 1fr); }
    .dash-grid { grid-template-columns: 1fr 1fr; align-items: start; }
}

/* ---- Extra status badges (inspection / task workflow) ---- */
.badge.due_today,
.badge.urgent          { background: var(--status-warn-bg); color: var(--status-warn); }
.badge.scheduled       { background: #eff6ff; color: var(--brand); }
.badge.needs_follow_up,
.badge.failed          { background: var(--status-fail-bg); color: var(--status-fail); }
.badge.in_compliance,
.badge.passed,
.badge.done            { background: var(--status-ok-bg); color: var(--status-ok); }
.badge.normal          { background: #f3f4f6; color: #6b7280; }
.badge.scheduled-soft  { background: #eff6ff; color: var(--brand); }

/* task list with checkbox affordance */
.task-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid #f3f4f6; }
.task-row:last-child { border-bottom: none; }
.task-row .tk-check { width: 22px; height: 22px; border-radius: 6px; border: 2px solid #d1d5db; flex-shrink: 0; cursor: pointer; display: flex; align-items: center; justify-content: center; background: #fff; color: var(--status-ok); font-size: 14px; }
.task-row .tk-check.done { background: var(--status-ok); border-color: var(--status-ok); color: #fff; }
.task-row.done .tk-main { text-decoration: line-through; color: #9ca3af; }
.task-row .tk-main { flex: 1; min-width: 0; }
.task-row .tk-title { font-size: 14px; font-weight: 500; }
.task-row .tk-sub { font-size: 12px; color: #6b7280; margin-top: 2px; }
