:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-soft: #eef4f2;
    --ink: #172033;
    --muted: #637083;
    --line: #dce3ec;
    --accent: #0f8f7a;
    --accent-dark: #0b6f61;
    --blue: #2563eb;
    --amber: #b7791f;
    --red: #c2413a;
    --shadow: 0 16px 40px rgba(22, 32, 51, 0.08);
    --radius: 8px;
    --sidebar: #172033;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
}

button,
input,
select,
textarea {
    font: inherit;
}

svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}

.auth-body,
.install-body {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 28px;
    background:
        linear-gradient(130deg, rgba(15, 143, 122, 0.12), transparent 32%),
        linear-gradient(330deg, rgba(37, 99, 235, 0.10), transparent 34%),
        var(--bg);
}

.auth-shell,
.install-shell {
    width: min(100%, 980px);
    display: grid;
    grid-template-columns: minmax(260px, 0.78fr) minmax(320px, 1fr);
    min-height: 620px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.install-shell {
    grid-template-columns: 0.85fr 1.15fr;
}

.auth-panel,
.install-panel {
    padding: 36px;
    color: #fff;
    background: #172033;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.auth-panel h1,
.install-panel h1 {
    margin: 20px 0 12px;
    font-size: clamp(2rem, 3vw, 3rem);
    line-height: 1.02;
}

.auth-panel p,
.install-panel p {
    color: rgba(255, 255, 255, 0.74);
    line-height: 1.7;
}

.brand-mark {
    display: inline-grid;
    width: 44px;
    height: 44px;
    place-items: center;
    border-radius: var(--radius);
    background: #0f8f7a;
    color: #fff;
    font-weight: 800;
}

.auth-form,
.install-form {
    padding: 36px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 18px;
}

.install-form {
    justify-content: flex-start;
    overflow: auto;
}

.form-title {
    margin: 0;
    font-size: 1.55rem;
}

.form-subtitle {
    margin: -8px 0 10px;
    color: var(--muted);
    line-height: 1.55;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.field {
    display: grid;
    gap: 7px;
}

.field.full {
    grid-column: 1 / -1;
}

.field span,
.field label,
.field > strong {
    color: #3d4a5c;
    font-size: 0.86rem;
    font-weight: 700;
}

.field input,
.field textarea,
.field select {
    min-width: 0;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
    padding: 12px 13px;
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.field textarea {
    min-height: 132px;
    resize: vertical;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
    border-color: rgba(15, 143, 122, 0.8);
    box-shadow: 0 0 0 4px rgba(15, 143, 122, 0.13);
}

.checkbox-line {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 0.92rem;
}

.checkbox-line input {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

.button,
.link-button,
.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    min-height: 42px;
    padding: 0 16px;
    color: #fff;
    background: var(--accent);
    font-size: 0.93rem;
    font-weight: 760;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.button:hover,
.link-button:hover {
    background: var(--accent-dark);
}

.button:active,
.link-button:active {
    transform: translateY(1px);
}

.button.secondary,
.link-button.secondary,
.icon-button.secondary {
    background: #fff;
    color: var(--ink);
    border-color: var(--line);
}

.button.blue,
.link-button.blue {
    background: var(--blue);
}

.auth-alt {
    color: var(--muted);
    font-size: 0.95rem;
}

.auth-alt a {
    color: var(--accent-dark);
    font-weight: 760;
}

.flash-stack {
    display: grid;
    gap: 10px;
}

.flash {
    border-radius: var(--radius);
    padding: 12px 14px;
    line-height: 1.45;
    border: 1px solid var(--line);
    background: #fff;
}

.flash.success {
    border-color: rgba(15, 143, 122, 0.35);
    color: #0b6f61;
    background: #ebf8f5;
}

.flash.error {
    border-color: rgba(194, 65, 58, 0.35);
    color: var(--red);
    background: #fff0ee;
}

.app-body {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 264px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 24px;
    color: #fff;
    background: var(--sidebar);
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 850;
    font-size: 1.05rem;
}

.sidebar-brand .brand-mark {
    width: 38px;
    height: 38px;
}

.nav-stack {
    display: grid;
    gap: 8px;
}

.nav-button {
    width: 100%;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: rgba(255, 255, 255, 0.72);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 12px;
    cursor: pointer;
    text-align: left;
    font-size: 0.94rem;
    font-weight: 720;
}

.nav-button.active,
.nav-button:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.10);
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 12px;
}

.user-card {
    display: grid;
    gap: 3px;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.06);
}

.user-card strong {
    font-size: 0.92rem;
}

.user-card span {
    color: rgba(255, 255, 255, 0.64);
    font-size: 0.82rem;
    overflow-wrap: anywhere;
}

.logout-button {
    width: 100%;
    background: transparent;
    color: rgba(255, 255, 255, 0.78);
    border-color: rgba(255, 255, 255, 0.18);
}

.workspace {
    min-width: 0;
    padding: 28px;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 22px;
}

.topbar h1 {
    margin: 0;
    font-size: clamp(1.9rem, 3vw, 2.55rem);
    line-height: 1.06;
}

.topbar p {
    max-width: 740px;
    margin: 9px 0 0;
    color: var(--muted);
    line-height: 1.6;
}

.stat-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
}

.stat span {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 720;
}

.stat strong {
    display: block;
    margin-top: 8px;
    font-size: 1.7rem;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.creator-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 380px);
    gap: 18px;
}

.creator-form,
.preview-panel {
    padding: 22px;
}

.section-title {
    margin: 0 0 18px;
    font-size: 1.08rem;
}

.segments {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.segment {
    position: relative;
}

.segment input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.segment span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0 10px;
    color: var(--muted);
    background: #fff;
    font-size: 0.88rem;
    font-weight: 760;
    text-align: center;
    cursor: pointer;
}

.segment input:checked + span {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.type-fields {
    display: none;
}

.type-fields.active {
    display: grid;
    gap: 16px;
}

.inline-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.map-frame {
    width: 100%;
    aspect-ratio: 1.16 / 1;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface-soft);
}

.map-frame iframe {
    width: 100%;
    height: 100%;
    border: 0;
}

.map-empty {
    height: 100%;
    display: grid;
    place-items: center;
    color: var(--muted);
    text-align: center;
    padding: 24px;
    line-height: 1.45;
}

.status-line {
    min-height: 20px;
    color: var(--muted);
    font-size: 0.86rem;
}

.actions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
}

.table-shell {
    overflow-x: auto;
}

.qrc-table {
    width: 100%;
    min-width: 880px;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.qrc-table th,
.qrc-table td {
    padding: 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.qrc-table th {
    color: #485568;
    background: #f9fbfd;
    font-size: 0.78rem;
    font-weight: 840;
    text-transform: uppercase;
}

.qrc-table tr:last-child td {
    border-bottom: 0;
}

.qr-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}

.qr-thumb {
    width: 58px;
    height: 58px;
    object-fit: contain;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: repeating-conic-gradient(#f5f7fb 0 25%, #fff 0 50%) 50% / 14px 14px;
}

.qr-name {
    display: grid;
    gap: 4px;
}

.qr-name strong {
    overflow-wrap: anywhere;
}

.qr-name span {
    color: var(--muted);
    font-size: 0.86rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    background: #eef4f2;
    color: var(--accent-dark);
    font-size: 0.78rem;
    font-weight: 800;
}

.badge.inactive {
    color: var(--red);
    background: #fff0ee;
}

.download-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-button {
    width: 38px;
    min-height: 38px;
    padding: 0;
    background: #fff;
    color: var(--ink);
    border-color: var(--line);
}

.icon-button:hover {
    border-color: rgba(15, 143, 122, 0.45);
    color: var(--accent-dark);
}

.switch-form {
    display: inline-flex;
}

.switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 52px;
    height: 30px;
    cursor: pointer;
}

.switch input {
    position: absolute;
    opacity: 0;
}

.switch span {
    width: 52px;
    height: 30px;
    border-radius: 999px;
    background: #cbd5e1;
    transition: background 0.16s ease;
}

.switch span::after {
    content: "";
    position: absolute;
    top: 4px;
    left: 4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.22);
    transition: transform 0.16s ease;
}

.switch input:checked + span {
    background: var(--accent);
}

.switch input:checked + span::after {
    transform: translateX(22px);
}

.empty-state {
    min-height: 260px;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 42px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.empty-state h2 {
    margin: 0 0 8px;
}

.empty-state p {
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
}

.install-result {
    display: grid;
    gap: 14px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

.manual-config {
    width: 100%;
    min-height: 220px;
    white-space: pre;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.82rem;
}

@media (max-width: 980px) {
    .app-body {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        padding: 16px;
    }

    .nav-stack {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sidebar-footer {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: stretch;
    }

    .logout-button {
        min-width: 118px;
        height: 100%;
    }

    .workspace {
        padding: 20px;
    }

    .creator-layout,
    .auth-shell,
    .install-shell {
        grid-template-columns: 1fr;
    }

    .auth-panel,
    .install-panel {
        min-height: auto;
    }
}

@media (max-width: 720px) {
    .auth-body,
    .install-body {
        padding: 12px;
    }

    .auth-panel,
    .auth-form,
    .install-panel,
    .install-form,
    .creator-form,
    .preview-panel {
        padding: 20px;
    }

    .form-grid,
    .inline-grid,
    .segments,
    .stat-row {
        grid-template-columns: 1fr;
    }

    .topbar {
        flex-direction: column;
    }

    .sidebar-footer {
        grid-template-columns: 1fr;
    }
}

