:root {
    --bg: #f5efe7;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --brand: #b45309;
    --brand-dark: #92400e;
    --brand-light: #fef3c7;
    --danger-bg: #fef2f2;
    --danger: #b91c1c;
    --success-bg: #ecfdf5;
    --success: #047857;
    --shadow: 0 24px 60px rgba(17, 24, 39, 0.18);
}

* {
    box-sizing: border-box;
}

html, body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at 20% 20%, rgba(180, 83, 9, 0.16), transparent 26rem),
        linear-gradient(135deg, #fff7ed 0%, var(--bg) 48%, #f3f4f6 100%);
    color: var(--text);
}

.page-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}

.portal-card {
    width: 100%;
    max-width: 440px;
    overflow: hidden;
    background: var(--card);
    border: 1px solid rgba(255, 255, 255, 0.75);
    border-radius: 28px;
    box-shadow: var(--shadow);
}

.brand-header {
    display: flex;
    gap: 14px;
    align-items: center;
    padding: 28px;
    color: white;
    background: linear-gradient(135deg, var(--brand-dark), var(--brand));
}

.brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.18);
    font-size: 26px;
}

.brand-header h1 {
    margin: 0;
    font-size: 26px;
    line-height: 1.05;
    letter-spacing: -0.04em;
}

.brand-header p {
    margin: 6px 0 0;
    opacity: 0.86;
    font-size: 14px;
}

.status-strip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 22px 28px 6px;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    color: #9ca3af;
    min-width: 58px;
}

.step span {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    border: 2px solid #d1d5db;
    font-weight: 700;
    background: white;
}

.step small {
    font-size: 11px;
    font-weight: 700;
}

.step.active,
.step.done {
    color: var(--brand);
}

.step.active span,
.step.done span {
    color: white;
    border-color: var(--brand);
    background: var(--brand);
}

.line {
    height: 2px;
    width: 34px;
    background: var(--line);
    margin-bottom: 20px;
}

.card-body {
    padding: 22px 28px 28px;
}

.intro {
    text-align: center;
    margin-bottom: 20px;
}

.intro h2 {
    margin: 0 0 6px;
    font-size: 24px;
    letter-spacing: -0.03em;
}

.intro p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

.alert {
    padding: 12px 14px;
    border-radius: 14px;
    margin-bottom: 16px;
    font-size: 14px;
    line-height: 1.45;
}

.alert-error {
    color: var(--danger);
    background: var(--danger-bg);
    border: 1px solid #fecaca;
}

.alert-success {
    color: var(--success);
    background: var(--success-bg);
    border: 1px solid #a7f3d0;
}

.form-stack {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

label {
    font-size: 13px;
    font-weight: 700;
    color: #374151;
}

.phone-input-wrap {
    display: flex;
    align-items: center;
    border: 1px solid #d1d5db;
    border-radius: 16px;
    background: #fff;
    overflow: hidden;
}

.phone-input-wrap span {
    padding-left: 16px;
    color: var(--muted);
    font-weight: 700;
}

input[type="tel"],
input[type="text"] {
    width: 100%;
    border: 0;
    outline: 0;
    padding: 15px 16px;
    font: inherit;
    background: transparent;
    color: var(--text);
}

input:focus,
.phone-input-wrap:focus-within,
.code-input:focus {
    border-color: #f59e0b;
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.16);
}

.code-input {
    border: 1px solid #d1d5db !important;
    border-radius: 16px;
    text-align: center;
    font-size: 28px !important;
    letter-spacing: 0.22em;
    font-weight: 800;
}

.hint,
.test-code {
    margin: -5px 0 0;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

.test-code {
    color: var(--brand);
    background: var(--brand-light);
    padding: 8px 10px;
    border-radius: 12px;
}

.primary-btn {
    border: 0;
    border-radius: 16px;
    padding: 15px 18px;
    background: linear-gradient(135deg, #d97706, var(--brand));
    color: white;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 14px 26px rgba(180, 83, 9, 0.28);
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.primary-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 18px 32px rgba(180, 83, 9, 0.32);
}

.primary-btn:disabled {
    opacity: 0.72;
    cursor: wait;
    transform: none;
}

.hidden {
    display: none !important;
}

.phone-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 16px;
    background: #f9fafb;
    border: 1px solid var(--line);
}

.phone-summary span {
    font-size: 12px;
    color: var(--muted);
}

.phone-summary strong {
    font-size: 13px;
}

.checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fafafa;
    color: #4b5563;
    line-height: 1.4;
}

.checkbox-row input {
    width: 18px;
    height: 18px;
    margin-top: 1px;
    accent-color: var(--brand);
    flex: none;
}

.checkbox-row.optional {
    background: white;
}

.secondary-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    color: var(--muted);
    font-size: 13px;
}

.secondary-actions a,
.link-button {
    color: var(--brand);
    text-decoration: none;
    font-weight: 800;
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    cursor: pointer;
}

.connection-details {
    margin-top: 22px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.connection-details div {
    border: 1px solid var(--line);
    background: #f9fafb;
    border-radius: 16px;
    padding: 10px;
    min-width: 0;
}

.connection-details span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.connection-details strong {
    display: block;
    margin-top: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
}

.portal-footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 28px;
    background: #f9fafb;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
}

@media (max-width: 420px) {
    .brand-header,
    .card-body,
    .portal-footer {
        padding-left: 20px;
        padding-right: 20px;
    }

    .connection-details {
        grid-template-columns: 1fr;
    }
}

.alert-warn { background: #fff7ed; color: #9a3412; border-left: 4px solid #f97316; }
.admin-body { background: #f3f4f6; }
.admin-shell { min-height: 100vh; display: grid; grid-template-columns: 260px 1fr; }
.admin-sidebar { background: #111827; color: #fff; padding: 24px; display: flex; flex-direction: column; gap: 22px; }
.admin-logo { display: grid; gap: 4px; margin-bottom: 8px; }
.admin-logo span { width: 44px; height: 44px; border-radius: 16px; background: rgba(255,255,255,.12); display: grid; place-items: center; font-size: 24px; }
.admin-logo strong { font-size: 22px; letter-spacing: -.04em; }
.admin-logo small { color: #9ca3af; }
.admin-sidebar nav { display: grid; gap: 8px; }
.admin-sidebar a { color: #d1d5db; text-decoration: none; border-radius: 12px; padding: 11px 12px; font-weight: 700; }
.admin-sidebar a:hover, .admin-sidebar a.active { color: #fff; background: rgba(255,255,255,.12); }
.admin-sidebar .logout { margin-top: auto; color: #fca5a5; }
.admin-main { padding: 28px; max-width: 1440px; width: 100%; }
.admin-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; gap: 16px; }
.admin-top h1 { margin: 0; font-size: 32px; letter-spacing: -.04em; }
.admin-top p { margin: 6px 0 0; color: #6b7280; }
.admin-open { text-decoration: none; color: #92400e; background: #fef3c7; padding: 10px 14px; border-radius: 12px; font-weight: 800; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card, .admin-card { background: #fff; border: 1px solid #e5e7eb; border-radius: 20px; box-shadow: 0 10px 30px rgba(17,24,39,.06); }
.stat-card { padding: 22px; }
.stat-card span { display: block; font-size: 12px; color: #6b7280; font-weight: 800; letter-spacing: .08em; }
.stat-card strong { display: block; margin-top: 10px; font-size: 34px; color: #111827; }
.admin-card { padding: 20px; margin-bottom: 20px; }
.admin-card h2 { margin: 0 0 16px; font-size: 20px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: #6b7280; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; border-bottom: 1px solid #e5e7eb; padding: 10px; }
td { border-bottom: 1px solid #f3f4f6; padding: 11px 10px; vertical-align: top; }
.badge { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 800; background: #e5e7eb; color: #374151; }
.badge.authorized, .badge.info { background: #dcfce7; color: #166534; }
.badge.error, .badge.sms_failed { background: #fee2e2; color: #991b1b; }
.badge.otp_sent, .badge.warning { background: #fef3c7; color: #92400e; }
.admin-search { display: flex; gap: 10px; margin-bottom: 16px; }
.admin-search input, .settings-grid input, .settings-grid select, .admin-input { width: 100%; border: 1px solid #d1d5db; border-radius: 12px; padding: 11px 12px; font: inherit; background: #fff; }
.admin-search button { border: 0; border-radius: 12px; background: #111827; color: #fff; font-weight: 800; padding: 0 18px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.settings-grid label { display: grid; gap: 6px; color: #374151; font-size: 13px; font-weight: 800; }
.settings-submit { grid-column: 1 / -1; }
.admin-login code { background: #f3f4f6; border-radius: 6px; padding: 2px 5px; }
@media (max-width: 920px) { .admin-shell { grid-template-columns: 1fr; } .admin-sidebar { position: static; } .stat-grid, .settings-grid { grid-template-columns: 1fr; } .admin-top { align-items: flex-start; flex-direction: column; } }

.connect-progress {
    display: block;
    margin-top: 2px;
    padding: 10px 12px;
    border-radius: 12px;
    background: #f9fafb;
    border: 1px solid var(--line);
}

.lang-switch {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 3;
}
.lang-current {
    border: 1px solid var(--line);
    background: rgba(255,255,255,.92);
    border-radius: 999px;
    padding: 7px 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(17,24,39,.08);
}
.lang-current small { color: #374151; }
.lang-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 132px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 18px 40px rgba(17,24,39,.14);
    padding: 6px;
}
.lang-switch:hover .lang-menu,
.lang-switch:focus-within .lang-menu { display: grid; }
.lang-menu a {
    color: #111827;
    text-decoration: none;
    font-weight: 800;
    padding: 9px 10px;
    border-radius: 10px;
    font-size: 13px;
}
.lang-menu a:hover { background: #f3f4f6; }

.auth-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
    padding: 5px;
    background: #f3f4f6;
    border: 1px solid var(--line);
    border-radius: 16px;
}
.auth-tab {
    border: 0;
    border-radius: 12px;
    padding: 10px 12px;
    background: transparent;
    color: var(--muted);
    font-weight: 900;
    cursor: pointer;
}
.auth-tab.active {
    background: #fff;
    color: #111827;
    box-shadow: 0 8px 18px rgba(17,24,39,.08);
}
.auth-panel { display: none; }
.auth-panel.active { display: grid; }
.strong-hint {
    background: #f9fafb;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 10px 12px;
}
.pin-input {
    text-align: center;
    font-size: 22px;
    letter-spacing: .32em;
    font-weight: 900;
}
.pin-create-card {
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 12px;
    background: #f9fafb;
    display: grid;
    gap: 8px;
}
.pin-create-card .pin-input { background: #fff; }
.admin-card .context-cell {
    max-width: 520px;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    color: #374151;
}


/* v4 polish */
.page-shell {
    background:
        radial-gradient(circle at 18% 18%, rgba(251, 191, 36, .24), transparent 26%),
        radial-gradient(circle at 86% 10%, rgba(217, 119, 6, .20), transparent 24%),
        linear-gradient(145deg, #fff7ed 0%, #f8fafc 48%, #fefce8 100%);
}
.portal-card { border: 1px solid rgba(255,255,255,.78); box-shadow: 0 28px 70px rgba(120, 53, 15, .20); }
.brand-mark img, .admin-logo img, .logo-preview img { width: 100%; height: 100%; object-fit: contain; border-radius: inherit; }
.brand-header h1 { line-height: 1.05; }
.trust-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.trust-row span { border: 1px solid #fde68a; background: #fffbeb; color: #92400e; border-radius: 999px; padding: 7px 10px; font-size: 11px; font-weight: 900; }
.pin-input-wrap { display: grid; grid-template-columns: 1fr auto; align-items: center; border: 1px solid #d1d5db; border-radius: 16px; background: #fff; overflow: hidden; }
.pin-input-wrap:focus-within { border-color: #f59e0b; box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.16); }
.pin-input-wrap .pin-input { border: 0 !important; outline: 0; padding: 15px 10px 15px 22px; background: transparent; width: 100%; }
.toggle-pass { border: 0; background: #f9fafb; border-left: 1px solid #e5e7eb; height: 100%; padding: 0 14px; color: #92400e; font-weight: 900; cursor: pointer; }
.toggle-pass:hover { background: #fffbeb; }
.logo-upload-card { border: 1px dashed #d1d5db; border-radius: 18px; padding: 16px; background: #f9fafb; display: grid; gap: 12px; }
.logo-preview { width: 96px; height: 96px; border-radius: 24px; background: #fff; border: 1px solid #e5e7eb; display: grid; place-items: center; font-size: 34px; color: #b45309; overflow: hidden; }
.logo-upload-card input[type="file"] { width: 100%; border: 1px solid #d1d5db; border-radius: 12px; padding: 10px; background: #fff; }
.settings-section-title { grid-column: 1 / -1; margin: 10px 0 0; padding-top: 12px; border-top: 1px solid #e5e7eb; color: #111827; font-size: 15px; font-weight: 900; }
@media (max-width: 760px) { .trust-row { justify-content: flex-start; } }

/* v6 polish */
.portal-card { position: relative; backdrop-filter: blur(10px); }
.brand-header { position: relative; overflow: hidden; }
.brand-header::after { content: ""; position: absolute; right: -42px; top: -42px; width: 150px; height: 150px; border-radius: 50%; background: rgba(255,255,255,.12); }
.brand-mark { position: relative; z-index: 1; box-shadow: inset 0 0 0 1px rgba(255,255,255,.22); }
.brand-header > div:last-child { position: relative; z-index: 1; }
.code-input.complete, .pin-input-wrap.complete { border-color: #10b981 !important; box-shadow: 0 0 0 4px rgba(16,185,129,.14) !important; }
.pin-input { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; letter-spacing: .3em; font-size: 22px !important; font-weight: 900; text-align: center; }
.pin-input-wrap .toggle-pass { min-width: 76px; }
.toggle-pass { border: 0; background: #f3f4f6; color: #374151; height: 100%; padding: 0 14px; font-weight: 900; cursor: pointer; }
.toggle-pass:hover { background: #e5e7eb; }
.connect-progress { display: block; padding: 12px 14px; border-radius: 14px; background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; margin-top: 0; }
.settings-help { grid-column: 1 / -1; background: #f8fafc; color: #475569; border: 1px dashed #cbd5e1; border-radius: 14px; padding: 12px 14px; font-size: 13px; line-height: 1.5; }
.settings-help code { background: #fff; border: 1px solid #e5e7eb; border-radius: 6px; padding: 2px 5px; word-break: break-all; }
.logo-upload-card { background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 18px; padding: 14px; }
.logo-preview { width: 72px; height: 72px; border-radius: 22px; background: white; border: 1px solid #e5e7eb; display: grid; place-items: center; font-size: 34px; margin-bottom: 12px; overflow: hidden; }
.admin-card.settings-card { background: linear-gradient(180deg, #fff, #fffdf9); }
.admin-card .settings-section-title { grid-column: 1 / -1; margin-top: 10px; padding-top: 18px; border-top: 1px solid #f3f4f6; color: #92400e; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; font-size: 12px; }
@media (max-width: 420px) { .pin-input { letter-spacing: .22em; } .pin-input-wrap .toggle-pass { min-width: 64px; padding: 0 10px; } }
