:root {
    color-scheme: light;
    --bg: #f4f6f9;
    --card: #fff;
    --text: #101828;
    --muted: #667085;
    --line: #e9edf2;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --button: #f2f4f7;
    --button-hover: #e4e7ec;
    --danger: #b42318;
    --shadow: 0 2px 12px rgba(16, 24, 40, .10);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.center-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}
.login-card {
    width: min(100%, 420px);
    padding: 32px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--card);
    box-shadow: var(--shadow);
}
.login-card h1 { margin: 4px 0 8px; font-size: 28px; }
.login-card > p:not(.portal-name) { margin: 0 0 24px; color: var(--muted); }
.portal-name {
    margin: 0 0 5px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
}
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 7px; font-weight: 600; }
.form-group input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #d0d5dd;
    border-radius: 10px;
    outline: none;
    background: #fff;
}
.form-group input:focus,
.rename-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.primary-button {
    width: 100%;
    padding: 12px 16px;
    border: 0;
    border-radius: 10px;
    color: #fff;
    background: var(--primary);
    font-weight: 700;
}
.primary-button:hover { background: var(--primary-hover); }
.primary-button:disabled { opacity: .65; cursor: wait; }
.error { min-height: 21px; margin: 12px 0 0; color: var(--danger); font-size: 14px; }

.page { padding: 32px 18px; }
.container { width: min(100%, 980px); margin: 0 auto; }
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.logout-button,
.instruction-button,
.back-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 13px;
    border: 1px solid #d0d5dd;
    border-radius: 9px;
    color: #344054;
    background: #fff;
    font-weight: 600;
    text-decoration: none;
}
.logout-button:hover,
.instruction-button:hover,
.back-button:hover { background: #f9fafb; }
.clients-card {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--card);
    box-shadow: var(--shadow);
}
.card-header { padding: 20px; border-bottom: 1px solid var(--line); }
.card-header h1 { margin: 0; font-size: 24px; }
.client-row {
    min-height: 88px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 52px 52px;
    align-items: center;
    gap: 8px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
}
.client-row:last-child { border-bottom: 0; }
.client-row.is-saving { opacity: .7; }
.client-name-wrap { min-width: 0; display: flex; align-items: center; gap: 16px; }
.avatar {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #cbd2dc;
    background: #f8fafc;
}
.client-name-slot { min-width: 0; flex: 1 1 auto; }
.client-number { color: var(--muted); font-size: 12px; font-weight: 800; line-height: 1.3; }
.client-address { margin-top: 5px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.client-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.client-name-button {
    display: block;
    width: 100%;
    margin: 2px -6px -4px;
    padding: 4px 6px;
    border: 0;
    border-radius: 7px;
    color: inherit;
    background: transparent;
    text-align: left;
}
.client-name-button.is-empty { color: var(--muted); font-style: italic; }
.client-name-button:hover { color: var(--primary); background: #f8fafc; }
.client-name-button:focus-visible { outline: 3px solid rgba(37, 99, 235, .18); outline-offset: 1px; }
.icon-button,
.rename-button {
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 7px;
    color: #667085;
    background: var(--button);
}
.icon-button { width: 36px; height: 36px; color: #98a2b3; }
.rename-button { width: 32px; height: 32px; }
.icon-button:hover:not(:disabled),
.rename-button:hover:not(:disabled) { color: #344054; background: var(--button-hover); }
.icon-button:disabled,
.rename-button:disabled { opacity: .35; cursor: not-allowed; }
.empty-state { padding: 48px 20px; color: var(--muted); text-align: center; }

.rename-editor {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 7px;
}
.rename-input {
    min-width: 0;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #98a2b3;
    border-radius: 8px;
    outline: none;
    background: #fff;
}
.rename-actions { display: flex; gap: 5px; }
.rename-save { color: #067647; }
.rename-cancel { color: var(--danger); }
.rename-error {
    grid-column: 1 / -1;
    color: var(--danger);
    font-size: 12px;
    line-height: 1.35;
}
.rename-error:empty { display: none; }

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    background: rgba(16, 24, 40, .62);
}
.modal {
    width: min(100%, 560px);
    max-height: calc(100vh - 20px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .28);
}
@supports (height: 100dvh) { .modal { max-height: calc(100dvh - 20px); } }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
}
.modal-title { margin: 0; font-size: 18px; }
.close-button {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: var(--button);
    font-size: 22px;
    line-height: 1;
}
.qr-content {
    min-height: 0;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 12px;
    background: #fff;
}
.qr-image {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: calc(100vh - 235px);
    object-fit: contain;
    -webkit-touch-callout: default;
    user-select: auto;
}
@supports (height: 100dvh) { .qr-image { max-height: calc(100dvh - 235px); } }
.qr-loading { margin: 24px 0; color: var(--muted); font-size: 14px; text-align: center; }
.qr-share-button {
    flex: 0 0 auto;
    margin-top: 12px;
    padding: 10px 14px;
    border: 0;
    border-radius: 9px;
    color: #fff;
    background: var(--primary);
    font-weight: 700;
}
.qr-share-button:hover:not(:disabled) { background: var(--primary-hover); }
.qr-share-button:disabled { opacity: .55; cursor: wait; }
.qr-hint { width: 100%; margin: 10px 0 0; color: var(--muted); font-size: 13px; line-height: 1.4; text-align: center; }
.qr-error { margin: 18px; color: var(--danger); text-align: center; }

.instruction-container { width: min(100%, 900px); }
.instruction-topbar { margin-bottom: 14px; }
.instruction-card {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--card);
    box-shadow: var(--shadow);
}
.instruction-header { padding: 34px 36px 24px; border-bottom: 1px solid var(--line); }
.instruction-header h1 { margin: 4px 0 10px; font-size: clamp(28px, 5vw, 40px); line-height: 1.12; }
.instruction-header p:last-child { max-width: 700px; margin: 0; color: var(--muted); font-size: 17px; line-height: 1.6; }
.instruction-kicker { margin: 0; color: var(--primary); font-size: 13px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.security-note {
    margin: 24px 36px 0;
    padding: 14px 16px;
    border: 1px solid #fedf89;
    border-radius: 10px;
    color: #7a2e0e;
    background: #fffaeb;
    line-height: 1.55;
}
.device-nav { display: flex; flex-wrap: wrap; gap: 8px; padding: 22px 36px 4px; }
.device-nav a { padding: 8px 12px; border-radius: 999px; color: #3538cd; background: #eff4ff; font-weight: 700; text-decoration: none; }
.device-nav a:hover { background: #e0e7ff; }
.device-section { margin: 0 36px; padding: 30px 0; border-bottom: 1px solid var(--line); scroll-margin-top: 20px; }
.device-section h2,
.troubleshooting h2 { margin: 0 0 14px; font-size: 24px; }
.device-section p,
.device-section li,
.troubleshooting li { line-height: 1.65; }
.device-section ol,
.troubleshooting ul { margin: 0 0 18px; padding-left: 24px; }
.device-section li + li,
.troubleshooting li + li { margin-top: 8px; }
.device-tip { padding-left: 13px; border-left: 3px solid #84adff; color: var(--muted); }
.external-link { color: var(--primary); font-weight: 700; text-decoration: none; }
.external-link:hover { text-decoration: underline; }
.command-grid { display: grid; gap: 10px; margin: 16px 0 20px; }
.command-grid div { display: grid; gap: 7px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; }
.command-grid span { color: var(--muted); font-size: 13px; font-weight: 700; }
code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.command-grid code { overflow-wrap: anywhere; color: #101828; }
pre { overflow-x: auto; padding: 16px; border-radius: 10px; color: #f2f4f7; background: #101828; line-height: 1.55; }
.troubleshooting { margin: 0 36px; padding: 30px 0; }
.instruction-source { border-top: 1px solid var(--line); padding: 22px 36px 28px; color: var(--muted); background: #f8fafc; line-height: 1.5; }

.admin-page { min-height: 100vh; }
.admin-container { width: min(100%, 1180px); margin: 0 auto; }
.admin-topbar,
.admin-section-heading,
.company-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.admin-topbar { margin-bottom: 20px; }
.admin-topbar h1,
.admin-section-heading h2,
.company-header h3 { margin: 0; }
.admin-card {
    margin-bottom: 18px;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--card);
    box-shadow: var(--shadow);
}
.admin-card h2,
.admin-card h3,
.admin-card h4 { margin-top: 0; }
.bootstrap-card { border-color: #fedf89; background: #fffaeb; }
.bootstrap-card > p { color: #7a2e0e; line-height: 1.5; }
.admin-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
    gap: 14px;
}
.admin-company-form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.admin-form label {
    display: grid;
    gap: 7px;
    color: #344054;
    font-size: 14px;
    font-weight: 700;
}
.admin-form input,
.admin-form textarea,
.admin-config-row input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d0d5dd;
    border-radius: 9px;
    outline: none;
    color: var(--text);
    background: #fff;
}
.admin-form textarea { resize: vertical; }
.admin-form input:focus,
.admin-form textarea:focus,
.admin-config-row input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.admin-wide { grid-column: 1 / -1; }
.admin-inline-button { width: auto; min-width: 180px; justify-self: start; }
.secondary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 13px;
    border: 1px solid #d0d5dd;
    border-radius: 9px;
    color: #344054;
    background: #fff;
    font-weight: 700;
}
.secondary-button:hover:not(:disabled) { background: #f9fafb; }
.secondary-button:disabled { opacity: .6; cursor: wait; }
.danger-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid #fda29b;
    border-radius: 9px;
    background: #fff;
    color: var(--danger);
    cursor: pointer;
    font-weight: 800;
}
.danger-button:hover:not(:disabled) { background: #fff4f2; }
.danger-button:disabled { opacity: .6; cursor: wait; }
.admin-card details summary { cursor: pointer; font-weight: 800; }
.admin-card details[open] summary { margin-bottom: 18px; }
.admin-section { margin-top: 28px; }
.admin-section-heading { margin-bottom: 14px; }
.admin-section-heading p,
.company-meta,
.field-hint,
.empty-inline { margin: 5px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.company-list { display: grid; gap: 18px; }
.company-card { margin: 0; }
.company-header { margin: -2px 0 20px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.company-header > div { min-width: 0; }
.company-header .endpoint-button { flex: 0 0 auto; }
.endpoint-modal-form { grid-template-columns: minmax(0, 1fr); align-items: stretch; gap: 12px; overflow: auto; padding: 18px; }
.endpoint-modal-hint { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.endpoint-modal-form label { margin-top: 4px; }
.endpoint-modal-form .form-message { margin: 0; }
.endpoint-modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; }
.endpoint-modal-actions .primary-button { width: auto; }
.admin-password-row {
    grid-template-columns: minmax(0, 1fr) auto minmax(180px, 1fr);
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}
.upload-block,
.configs-block { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.upload-block input[type="file"] {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 12px;
    border: 1px dashed #98a2b3;
    border-radius: 10px;
    background: #f8fafc;
}
.form-message { min-height: 20px; margin-top: 8px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.form-message.is-error,
.row-status.is-error { color: var(--danger); }
.form-message.is-success { color: #067647; }
.admin-config-row {
    display: grid;
    grid-template-columns: 70px minmax(210px, 1fr) minmax(210px, 1fr) minmax(220px, auto);
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-top: 1px solid var(--line);
}
.config-number { font-weight: 800; }
.config-name-field { min-width: 0; display: grid; gap: 6px; }
.config-name-label { color: #475467; font-size: 12px; font-weight: 800; }
.config-name-controls { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.config-flags { color: var(--muted); font-size: 12px; font-weight: 700; }
.config-file-actions { min-width: 0; display: grid; gap: 7px; }
.config-action-buttons { display: flex; flex-wrap: wrap; gap: 7px; }
.config-action-status { min-height: 16px; }
.compact-button { min-height: 36px; padding: 7px 10px; font-size: 13px; }
.row-status { color: #067647; font-size: 12px; }

.location-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
    padding: 14px 0;
}
.tenant-location-tabs { padding: 14px 20px; border-bottom: 1px solid var(--line); }
.location-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 8px 13px;
    border: 1px solid #d0d5dd;
    border-radius: 10px;
    color: #344054;
    background: #fff;
    font-weight: 700;
    white-space: nowrap;
}
.location-tab:hover { background: #f8fafc; }
.location-tab.is-active { border-color: var(--primary); color: #1945a1; background: #eff6ff; }
.location-tab:focus-visible,
.admin-nav-button:focus-visible { outline: 3px solid rgba(37, 99, 235, .3); outline-offset: 2px; }
.location-flag { width: 24px; height: 18px; flex: 0 0 auto; border: 1px solid #d0d5dd; border-radius: 3px; object-fit: cover; }
.admin-workspace { display: grid; grid-template-columns: 250px minmax(0, 1fr); align-items: start; gap: 20px; }
.admin-sidebar {
    position: sticky;
    top: 16px;
    max-height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--card);
    box-shadow: var(--shadow);
}
.admin-sidebar-title { margin: 0; padding: 17px 17px 11px; color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.admin-company-nav { min-height: 0; overflow-y: auto; padding: 0 8px 8px; }
.admin-sidebar-actions { display: grid; gap: 4px; padding: 9px 8px; border-top: 1px solid var(--line); }
.admin-nav-button {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 11px 10px;
    border: 0;
    border-radius: 9px;
    color: #344054;
    background: transparent;
    text-align: left;
    font-weight: 700;
}
.admin-nav-button:hover { background: #f8fafc; }
.admin-nav-button.is-active { color: #1945a1; background: #eff6ff; }
.admin-nav-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-nav-count { flex: 0 0 auto; color: var(--muted); font-size: 12px; }
.admin-nav-empty { margin: 4px 10px 14px; color: var(--muted); font-size: 13px; }
.admin-main { min-width: 0; }
.admin-main .admin-section { margin-top: 0; }
.admin-location-section { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.admin-location-heading h4 { margin: 0; }
.location-details { margin-top: 8px; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; }
.location-details h4 { margin-bottom: 12px; }
.location-form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.location-form button { justify-self: start; }
.location-create-details { margin-top: 12px; padding: 13px 16px; border: 1px solid var(--line); border-radius: 10px; }
.location-create-details summary { cursor: pointer; font-weight: 800; }
.location-create-details[open] summary { margin-bottom: 16px; }
.admin-location-actions { margin-top: 16px; }
.admin-form select,
.admin-config-row select {
    width: 100%;
    min-height: 42px;
    padding: 9px 12px;
    border: 1px solid #d0d5dd;
    border-radius: 9px;
    color: var(--text);
    background: #fff;
}
.admin-form select:focus,
.admin-config-row select:focus { outline: 3px solid rgba(37, 99, 235, .15); border-color: var(--primary); }
.config-move { display: flex; align-items: center; gap: 7px; }
.config-move select { max-width: 190px; min-height: 36px; font-size: 13px; }

@media (max-width: 900px) {
    .admin-workspace { grid-template-columns: 210px minmax(0, 1fr); gap: 12px; }
    .location-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .admin-workspace { display: block; }
    .admin-sidebar { position: static; max-height: none; margin-bottom: 14px; }
    .admin-company-nav { display: flex; gap: 4px; overflow-x: auto; padding: 0 8px 8px; }
    .admin-company-nav .admin-nav-button { width: auto; flex: 0 0 auto; max-width: 190px; }
    .admin-sidebar-actions { grid-template-columns: 1fr 1fr; }
    .admin-sidebar-actions .admin-nav-button { justify-content: center; font-size: 12px; }
    .admin-company-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .admin-config-row {
        grid-template-columns: 58px minmax(0, 1fr);
        gap: 8px;
    }
    .config-name-field,
    .config-file-actions { grid-column: 2; }
}

@media (max-width: 560px) {
    .page { padding: 14px 8px; }
    .topbar { align-items: stretch; }
    .instruction-button { flex: 1; }
    .login-card { padding: 24px 20px; }
    .card-header { padding: 18px 14px; }
    .client-row { grid-template-columns: minmax(0, 1fr) 44px 44px; padding: 14px 12px; }
    .client-name-wrap { gap: 10px; }
    .rename-editor { gap: 5px; }
    .rename-input { padding: 8px; }
    .rename-button { width: 30px; height: 30px; }
    .modal-header { padding: 12px 14px; }
    .modal-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
    .qr-content { padding: 8px; }
    .qr-image { max-width: calc(100vw - 40px); max-height: calc(100vh - 235px); }
    .qr-share-button { width: min(100%, 320px); margin-top: 10px; }
    .qr-hint { margin-top: 7px; padding: 0 4px; font-size: 12px; }
    .instruction-header { padding: 26px 20px 20px; }
    .security-note { margin: 18px 20px 0; }
    .device-nav { padding: 18px 20px 0; }
    .device-section,
    .troubleshooting { margin: 0 20px; padding: 24px 0; }
    .instruction-source { padding: 20px; }
    .admin-page { padding: 14px 8px; }
    .admin-topbar { align-items: flex-start; }
    .admin-card { padding: 17px 14px; }
    .company-header { align-items: flex-start; flex-direction: column; }
    .company-header .endpoint-button { width: 100%; }
    .endpoint-modal-form { padding: 14px; }
    .endpoint-modal-actions { flex-direction: column-reverse; }
    .endpoint-modal-actions button { width: 100%; }
    .admin-form,
    .admin-company-form,
    .admin-password-row { grid-template-columns: 1fr; }
    .admin-wide { grid-column: auto; }
    .admin-inline-button { width: 100%; }
    .admin-config-row {
        grid-template-columns: 58px minmax(0, 1fr);
        gap: 8px;
    }
    .config-flags,
    .config-name-field,
    .config-file-actions,
    .row-status { grid-column: 2; }
    .tenant-location-tabs { padding: 12px 14px; flex-wrap: nowrap; overflow-x: auto; }
    .admin-workspace { display: block; }
    .admin-sidebar { position: static; max-height: none; margin-bottom: 14px; }
    .admin-company-nav { display: flex; gap: 4px; overflow-x: auto; padding: 0 8px 8px; }
    .admin-company-nav .admin-nav-button { width: auto; flex: 0 0 auto; max-width: 190px; }
    .admin-sidebar-actions { grid-template-columns: 1fr 1fr; }
    .admin-sidebar-actions .admin-nav-button { justify-content: center; font-size: 12px; }
    .location-form { grid-template-columns: 1fr; }
    .location-details { padding: 13px; }
    .location-tabs { flex-wrap: nowrap; overflow-x: auto; }
    .config-move { flex-wrap: wrap; }
}
