/* =============================================================================
   ER Solutions serviceplattform – designsystem
   Byggt för konsekvent utseende i Safari, Chrome och Edge.
   Tema styrs via <html data-theme="light|dark">.
============================================================================= */

/* ---------- Design-tokens ---------- */
:root {
    --brand:        #2563eb;
    --brand-dark:   #1d4ed8;
    --brand-soft:   #dbeafe;

    --bg:           #f1f5f9;
    --surface:      #ffffff;
    --surface-2:    #f8fafc;
    --border:       #e2e8f0;
    --text:         #0f172a;
    --text-soft:    #475569;
    --text-mut:     #94a3b8;

    --success:      #16a34a;
    --success-bg:   #dcfce7;
    --warning:      #d97706;
    --warning-bg:   #fef3c7;
    --danger:       #dc2626;
    --danger-bg:    #fee2e2;

    --radius:       14px;
    --radius-sm:    10px;
    --shadow:       0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-lg:    0 10px 30px rgba(15, 23, 42, .12);

    --sidebar-w:    248px;
    --topbar-h:     60px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html[data-theme="dark"] {
    --bg:         #0b1120;
    --surface:    #111827;
    --surface-2:  #0f172a;
    --border:     #1f2a3c;
    --text:       #e5edf7;
    --text-soft:  #a7b4c7;
    --text-mut:   #64748b;
    --brand-soft: #172554;
    --success-bg: #052e1a;
    --warning-bg: #3a2606;
    --danger-bg:  #3a0d0d;
    --shadow:     0 1px 3px rgba(0, 0, 0, .4);
    --shadow-lg:  0 12px 32px rgba(0, 0, 0, .5);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 700; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p  { margin: 0 0 .6em; }
a  { color: var(--brand); text-decoration: none; }
img { max-width: 100%; }

/* =============================================================================
   Applikationsskal
============================================================================= */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 20px;
    font-weight: 800; font-size: 1.05rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand img { height: 30px; width: auto; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 12px 20px; }

.nav-section {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
    color: var(--text-mut); font-weight: 700;
    padding: 16px 12px 6px;
}

.nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: var(--text-soft); font-weight: 600; font-size: .92rem;
    transition: background .15s, color .15s;
}
.nav-link i { width: 20px; text-align: center; font-size: 1rem; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--brand); color: #fff; }

.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); }
.sidebar-user { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sidebar-user strong { display: block; font-size: .9rem; }
.sidebar-user span { display: block; font-size: .76rem; color: var(--text-mut); }

.sidebar-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--brand); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; flex: 0 0 auto;
}
.sidebar-avatar.sm { width: 32px; height: 32px; font-size: .85rem; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.app-topbar {
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 14px;
    padding: 0 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 30;
}
.topbar-menu-btn {
    display: none;
    background: none; border: none; color: var(--text);
    font-size: 1.2rem; cursor: pointer; padding: 8px;
}
.topbar-title { font-weight: 700; font-size: 1.05rem; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.theme-toggle {
    background: var(--surface-2); border: 1px solid var(--border);
    color: var(--text-soft); width: 38px; height: 38px; border-radius: 50%;
    cursor: pointer; font-size: .95rem;
    -webkit-appearance: none; appearance: none;
    display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
}

.notif-count {
    position: absolute; top: -3px; right: -3px;
    background: var(--danger); color: #fff;
    font-size: .58rem; font-weight: 700; line-height: 1;
    min-width: 16px; height: 16px; padding: 0 4px;
    border-radius: 999px; display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--surface);
}

/* Företagsväljare i topbaren */
.company-switcher { position: relative; }
.company-switch-btn {
    display: flex; align-items: center; gap: 8px;
    max-width: 240px; padding: 8px 12px; border-radius: var(--radius-sm);
    background: var(--surface-2); border: 1px solid var(--border);
    color: var(--text); font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
    -webkit-appearance: none; appearance: none; line-height: 1.2;
}
.company-switch-btn span {
    max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.company-switch-btn .chevron { font-size: .7rem; color: var(--text-mut); transition: transform .15s; }
.company-switcher.open .company-switch-btn .chevron { transform: rotate(180deg); }
.company-switch-panel {
    display: none; position: absolute; right: 0; top: calc(100% + 8px);
    width: 300px; max-width: 82vw; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); padding: 12px; z-index: 60;
}
.company-switcher.open .company-switch-panel { display: block; }
.company-switch-panel input {
    width: 100%; margin-bottom: 8px; padding: 9px 11px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface-2); color: var(--text); font: inherit; font-size: .88rem;
    -webkit-appearance: none; appearance: none;
}
.company-switch-results { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.company-switch-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: var(--radius-sm);
    color: var(--text); font-size: .88rem; font-weight: 600;
}
.company-switch-item:hover { background: var(--surface-2); }
.company-switch-item i { width: 16px; text-align: center; color: var(--brand); }
.company-switch-item.is-reseller i { color: var(--brand); }        /* återförsäljare/företag */
.company-switch-item.is-customer i { color: #14b8a6; }             /* slutkund */
.company-switch-item span { display: flex; flex-direction: column; min-width: 0; }
.company-switch-item small { color: var(--text-mut); font-size: .74rem; font-weight: 500; }
.company-switch-hint { padding: 10px; color: var(--text-mut); font-size: .82rem; }

.app-content { padding: 26px; max-width: 1280px; width: 100%; margin: 0 auto; flex: 1; }

/* =============================================================================
   Sidhuvud, kort, knappar, badge
============================================================================= */
.page-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 16px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-header p { color: var(--text-soft); margin: 4px 0 0; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    margin-bottom: 20px;
}
.card > h1:last-child, .card > h2:last-child, .card > p:last-child { margin-bottom: 0; }

.section-heading {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 14px; flex-wrap: wrap; margin-bottom: 16px;
}
.section-heading p { color: var(--text-soft); margin: 2px 0 0; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px; border-radius: var(--radius-sm);
    background: var(--brand); color: #fff; border: 1px solid var(--brand);
    font-weight: 600; font-size: .9rem; cursor: pointer;
    text-align: center; transition: background .15s, transform .05s;
    white-space: nowrap;
}
.btn:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn:active { transform: translateY(1px); }
.btn.secondary {
    background: var(--surface); color: var(--text); border-color: var(--border);
}
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(.93); }
.btn.block { display: flex; width: 100%; }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; }

.table-link { font-weight: 600; font-size: .88rem; }

.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: 999px;
    font-size: .74rem; font-weight: 700;
    background: var(--surface-2); color: var(--text-soft);
    border: 1px solid var(--border);
}
.badge.success { background: var(--success-bg); color: var(--success); border-color: transparent; }
.badge.warning { background: var(--warning-bg); color: var(--warning); border-color: transparent; }
.badge.danger  { background: var(--danger-bg);  color: var(--danger);  border-color: transparent; }

/* Alerts */
.alert-card { border-left: 4px solid var(--brand); }
.alert-card.error-card   { border-left-color: var(--danger);  background: var(--danger-bg); }
.alert-card.success-card { border-left-color: var(--success); background: var(--success-bg); }
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; background: var(--surface-2); }
.alert.error { background: var(--danger-bg); color: var(--danger); }

/* =============================================================================
   Formulär
============================================================================= */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid .full, .form-grid label.full, .detail-item.full { grid-column: 1 / -1; }

.form-grid label, form label {
    display: flex; flex-direction: column; gap: 6px;
    font-weight: 600; font-size: .86rem; color: var(--text-soft);
}
.form-grid label > span { color: var(--text); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="time"], input[type="search"], select, textarea {
    width: 100%;
    padding: 10px 12px;
    font: inherit; font-size: .92rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    -webkit-appearance: none; appearance: none;
}
textarea { min-height: 92px; resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px;
}

.checkbox-label {
    flex-direction: row !important; align-items: center; gap: 10px;
}
.checkbox-label input { width: auto; }

.form-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 4px; }

/* =============================================================================
   Statistik / KPI
============================================================================= */
.stats-grid, .dashboard-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px; margin-bottom: 22px;
}
.stat-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
    border-top: 3px solid var(--border);
}
.stat-card span { display: block; color: var(--text-soft); font-size: .82rem; font-weight: 600; }
.stat-card strong { display: block; font-size: 1.6rem; margin-top: 4px; }
.stat-card.success { border-top-color: var(--success); }
.stat-card.warning { border-top-color: var(--warning); }
.stat-card.danger  { border-top-color: var(--danger); }

.dashboard-kpi-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 14px;
}
.dashboard-kpi-icon {
    width: 46px; height: 46px; border-radius: 12px; flex: 0 0 auto;
    display: flex; align-items: center; justify-content: center;
    background: var(--brand-soft); color: var(--brand); font-size: 1.15rem;
}
.dashboard-kpi-card span { display: block; color: var(--text-soft); font-size: .8rem; font-weight: 600; }
.dashboard-kpi-card strong { display: block; font-size: 1.5rem; }
.dashboard-kpi-card.success .dashboard-kpi-icon { background: var(--success-bg); color: var(--success); }
.dashboard-kpi-card.warning .dashboard-kpi-icon { background: var(--warning-bg); color: var(--warning); }
.dashboard-kpi-card.danger  .dashboard-kpi-icon { background: var(--danger-bg);  color: var(--danger); }

/* =============================================================================
   Detaljlistor, textblock, action-rader
============================================================================= */
.detail-list {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px;
}
.detail-list.compact { gap: 10px; }
.detail-item span { display: block; color: var(--text-soft); font-size: .78rem; font-weight: 600; }
.detail-item strong { display: block; font-size: .98rem; margin-top: 2px; word-break: break-word; }

.text-block { margin: 14px 0; }
.text-block strong { display: block; color: var(--text-soft); font-size: .8rem; margin-bottom: 4px; }

.action-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.dashboard-list { display: flex; flex-direction: column; gap: 10px; }
.dashboard-list-item {
    display: flex; justify-content: space-between; gap: 12px;
    padding: 12px 14px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--surface-2);
}
.dashboard-list-item strong { display: block; }
.dashboard-list-item span { display: block; color: var(--text-soft); font-size: .82rem; }
.dashboard-list-item small { color: var(--text-mut); font-size: .76rem; }

/* =============================================================================
   Kort-listor (kunder, skärmar, mallar, historik)
============================================================================= */
.customer-card-list, .screen-card-list, .template-card-list,
.history-card-list, .template-step-list, .screen-job-list, .screen-history-list {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px;
}

.customer-list-card, .screen-list-card, .template-list-card,
.history-list-card, .template-step-card, .screen-job-card,
.screen-history-card, .service-active-job-card, .service-screen-result-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 12px;
}
.template-list-card.active { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }

.customer-list-header, .screen-list-header, .template-list-header,
.history-list-header, .template-step-header, .screen-job-header,
.screen-history-header, .service-screen-result-header, .screen-profile-header {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
.customer-list-header h2, .screen-list-header h3 { margin: 0; }
.customer-list-header p, .screen-list-header p, .template-list-header p,
.service-screen-result-header p { color: var(--text-soft); font-size: .84rem; margin: 2px 0 0; }

.customer-meta-grid, .screen-meta-grid, .template-step-meta,
.deviation-meta-grid, .history-meta-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px;
}
.customer-meta-grid span, .screen-meta-grid span, .template-step-meta span {
    display: block; color: var(--text-soft); font-size: .74rem; font-weight: 600;
}
.customer-meta-grid strong, .screen-meta-grid strong, .template-step-meta strong { font-size: .92rem; }

.customer-address, .screen-address { border-top: 1px solid var(--border); padding-top: 10px; }
.customer-address span, .screen-address span { color: var(--text-soft); font-size: .76rem; font-weight: 600; }

.customer-actions, .screen-list-actions, .template-step-actions,
.history-list-actions, .screen-job-actions {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
}
.screen-list-actions form { margin: 0; }

.template-layout-grid, .service-overview-grid, .screen-profile-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px;
}
.template-description { color: var(--text-soft); font-size: .88rem; }

/* =============================================================================
   Progressbar
============================================================================= */
.progress-bar { background: var(--surface-2); border-radius: 999px; height: 10px; overflow: hidden; border: 1px solid var(--border); }
.progress-bar.small { height: 7px; }
.progress-fill { height: 100%; background: var(--brand); border-radius: 999px; transition: width .3s; }

/* =============================================================================
   Foton
============================================================================= */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.photo-section { display: flex; gap: 10px; flex-wrap: wrap; }
.photo-thumb {
    display: block; border-radius: var(--radius-sm); overflow: hidden;
    border: 1px solid var(--border); aspect-ratio: 4 / 3; background: var(--surface-2);
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* =============================================================================
   Tabell (skärmmodeller m.m.)
============================================================================= */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-soft); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }

/* =============================================================================
   Avvikelser
============================================================================= */
.deviation-list { display: flex; flex-direction: column; gap: 14px; }
.deviation-card {
    background: var(--surface); border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 12px;
}
.deviation-card.is-open { border-left-color: var(--danger); }
.deviation-card.is-progress { border-left-color: var(--warning); }
.deviation-card.is-resolved { border-left-color: var(--success); opacity: .92; }
.deviation-header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.deviation-header p { color: var(--text-soft); font-size: .84rem; margin: 2px 0 0; }
.deviation-description strong { display: block; color: var(--text-soft); font-size: .8rem; margin-bottom: 3px; }
.deviation-text { color: var(--danger); }
.deviation-resolved { font-size: .82rem; color: var(--success); font-weight: 600; }
.deviation-update-form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; border-top: 1px solid var(--border); padding-top: 14px; }
.deviation-update-form .full { grid-column: 1 / -1; }
.deviation-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.step-deviation-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.step-deviation-box { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border-left: 3px solid var(--border); }
.step-deviation-box.is-open { border-left-color: var(--danger); }
.step-deviation-box.is-progress { border-left-color: var(--warning); }
.step-deviation-header { display: flex; justify-content: space-between; gap: 8px; align-items: center; }

.service-warning-note {
    background: var(--warning-bg); border-radius: var(--radius-sm);
    padding: 12px 14px; margin: 10px 0;
}
.service-warning-note strong { display: block; color: var(--warning); font-size: .82rem; }
.service-warning-note p { margin: 4px 0 0; font-size: .86rem; }

/* =============================================================================
   Utför service
============================================================================= */
.service-start-actions, .service-quick-filters { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.service-quick-filters button {
    padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text-soft); font-weight: 600; font-size: .82rem; cursor: pointer;
}
.service-quick-filters button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.service-search-form { display: flex; gap: 10px; }
.service-search-form input { flex: 1; }
.service-location-status { margin-top: 10px; color: var(--text-soft); font-size: .86rem; }
.service-qr-box { margin-top: 14px; padding: 14px; border: 1px dashed var(--border); border-radius: var(--radius-sm); text-align: center; }
#serviceQrReader { max-width: 320px; margin: 0 auto; }
.service-screen-result-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.service-active-job-list, .service-route-list { display: flex; flex-direction: column; gap: 12px; }
.service-route-item, .service-active-job-card {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}
.service-route-item strong, .service-active-job-card strong { display: block; }
.service-route-item span, .service-active-job-card span { display: block; color: var(--text-soft); font-size: .82rem; }
.service-active-job-card small { color: var(--text-mut); font-size: .76rem; }
.service-route-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.service-next-job-box { background: var(--brand-soft); border-radius: var(--radius-sm); padding: 10px 12px; }
.service-next-job-box strong { display: block; font-size: .8rem; }
.service-next-job-box span { display: block; font-size: .82rem; color: var(--text-soft); }
.service-risk-box { display: flex; flex-direction: column; gap: 4px; }
.service-risk-box span { background: var(--danger-bg); color: var(--danger); font-size: .78rem; font-weight: 600; padding: 5px 10px; border-radius: var(--radius-sm); }

/* =============================================================================
   Login
============================================================================= */
.login-body { background: linear-gradient(135deg, #1e3a8a, #2563eb 60%, #3b82f6); min-height: 100vh; }
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 36px 30px; width: 100%; max-width: 400px; }
.login-logo { text-align: center; margin-bottom: 18px; }
.login-logo img { height: 46px; }
.login-heading { text-align: center; margin-bottom: 22px; }
.login-heading h1 { margin: 0; }
.login-heading p { color: var(--text-soft); margin: 4px 0 0; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .86rem; }
.login-button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 12px; border: none; border-radius: var(--radius-sm);
    background: var(--brand); color: #fff; font-weight: 700; font-size: .95rem; cursor: pointer;
}
.login-button:hover { background: var(--brand-dark); }
.login-error {
    display: flex; align-items: center; gap: 8px;
    background: var(--danger-bg); color: var(--danger);
    padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: .88rem;
}

/* =============================================================================
   Mobil bottennavigation + backdrop
============================================================================= */
.app-bottom-nav { display: none; }
.sidebar-backdrop { display: none; }

/* =============================================================================
   Karta (Leaflet)
============================================================================= */
.map-fullscreen-page { position: relative; }
#screensMap {
    width: 100%; height: calc(100vh - 150px); min-height: 460px;
    border-radius: var(--radius); border: 1px solid var(--border); z-index: 1;
}
.map-floating-panel {
    position: absolute; top: 16px; right: 16px; width: 290px; max-width: calc(100% - 32px);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); padding: 16px; z-index: 600;
}
.map-floating-form { display: flex; flex-direction: column; gap: 12px; }
.map-floating-form label { display: flex; flex-direction: column; gap: 6px; font-size: .82rem; font-weight: 600; color: var(--text-soft); }
.map-floating-count { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); }
.map-floating-count strong { font-size: 1.3rem; color: var(--brand); }
.map-filter-actions { display: flex; flex-direction: column; gap: 8px; }
.map-floating-legend { display: flex; gap: 14px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.map-floating-legend > div { display: flex; align-items: center; gap: 6px; font-size: .8rem; }
.map-legend-marker { width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-size: .7rem; }
.map-legend-marker.ok { background: var(--success); }
.map-legend-marker.warning { background: var(--warning); }
.map-legend-marker.danger { background: var(--danger); }
.map-nearest-panel { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.map-nearest-panel a, #nearestList a { display: block; padding: 6px 0; font-size: .85rem; }
.map-mobile-toggle { display: none; }
.custom-screen-marker { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4); border: 2px solid #fff; }
.custom-screen-marker.ok { background: var(--success); }
.custom-screen-marker.warning { background: var(--warning); }
.custom-screen-marker.danger { background: var(--danger); }
.map-popup { display: flex; flex-direction: column; gap: 2px; font-size: .82rem; min-width: 180px; }
.map-popup strong { font-size: .95rem; }
.map-popup-actions { display: flex; gap: 10px; margin-top: 8px; }
.map-popup-actions a { font-weight: 600; color: var(--brand); }

@media (max-width: 640px) {
    .map-floating-panel { display: none; top: auto; bottom: 16px; left: 16px; right: 16px; width: auto; }
    .map-floating-panel.open { display: block; }
    .map-mobile-toggle {
        display: flex; position: absolute; right: 16px; bottom: 16px; z-index: 601;
        width: 48px; height: 48px; border-radius: 50%; background: var(--brand); color: #fff;
        border: none; align-items: center; justify-content: center; font-size: 1.1rem; box-shadow: var(--shadow-lg);
    }
    #screensMap { height: calc(100vh - 120px); }
}

/* =============================================================================
   Responsivt
============================================================================= */
@media (max-width: 960px) {
    .app-sidebar {
        position: fixed; left: 0; top: 0; height: 100vh;
        transform: translateX(-100%); transition: transform .25s ease;
        box-shadow: var(--shadow-lg);
    }
    .app-sidebar.open { transform: translateX(0); }
    .topbar-menu-btn { display: inline-flex; }
    .sidebar-backdrop.show {
        display: block; position: fixed; inset: 0;
        background: rgba(15, 23, 42, .45); z-index: 35;
    }
    .app-content { padding: 18px 16px calc(72px + env(safe-area-inset-bottom)); }

    .app-bottom-nav {
        display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 36;
        background: var(--surface); border-top: 1px solid var(--border);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .bottom-link {
        flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
        padding: 8px 4px; color: var(--text-mut); font-size: .66rem; font-weight: 600;
    }
    .bottom-link i { font-size: 1.1rem; }
    .bottom-link.active { color: var(--brand); }
}

@media (max-width: 640px) {
    .form-grid, .deviation-update-form { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: stretch; }
    h1 { font-size: 1.3rem; }
    .app-content { max-width: 100%; }
    .customer-card-list, .screen-card-list, .template-card-list,
    .history-card-list, .service-screen-result-list, .template-layout-grid,
    .service-overview-grid, .screen-profile-grid { grid-template-columns: 1fr; }
}

/* Skärmläsare / fokus-hjälp */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
