:root {
    --bg: #07111f;
    --bg-soft: #0b1728;
    --surface: #101d31;
    --surface-2: #13243b;
    --surface-3: #172b46;
    --ink: #eaf2ff;
    --muted: #95a9c8;
    --line: #223754;
    --line-soft: #1a2b44;
    --primary: #38bdf8;
    --primary-2: #2563eb;
    --primary-dark: #0ea5e9;
    --accent: #a78bfa;
    --danger: #f87171;
    --ok: #34d399;
    --warning: #fbbf24;
    --shadow: 0 18px 45px rgba(0, 0, 0, .32);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

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

section[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { border: 0; }

.auth-body {
    min-height: 100vh;
    background:
        linear-gradient(135deg, rgba(37, 99, 235, .24), transparent 34%),
        linear-gradient(315deg, rgba(56, 189, 248, .14), transparent 30%),
        var(--bg);
    color: var(--ink);
    display: grid;
    place-items: center;
    padding: 28px;
}

.auth-shell {
    width: min(1080px, 100%);
    display: grid;
    grid-template-columns: 1.15fr .85fr;
    gap: 18px;
}

.hero-card, .login-card, .panel, .stat, .client-info div, .invoice-card, .empty-card {
    border: 1px solid var(--line);
    background: rgba(16, 29, 49, .92);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.hero-card {
    min-height: 560px;
    padding: 48px;
    background:
        linear-gradient(145deg, rgba(37, 99, 235, .44), rgba(10, 21, 38, .95)),
        var(--surface);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.login-card {
    padding: 30px;
    align-self: center;
}

.brand-mark {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: white;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary-2), var(--primary));
    box-shadow: 0 14px 30px rgba(56, 189, 248, .22);
}

.brand-mark.small {
    width: 44px;
    height: 44px;
    font-size: 14px;
}

.eyebrow {
    display: inline-block;
    margin-top: 22px;
    color: var(--primary);
    text-transform: uppercase;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .08em;
}

.hero-card h1 {
    font-size: 56px;
    line-height: 1;
    margin: 18px 0;
    letter-spacing: 0;
}

.hero-card p {
    color: #c8d8f2;
    font-size: 18px;
    max-width: 620px;
    line-height: 1.65;
}

.hero-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 32px;
}

.hero-grid div {
    border: 1px solid rgba(148, 163, 184, .22);
    background: rgba(15, 23, 42, .5);
    border-radius: 8px;
    padding: 16px;
}

.hero-grid strong, .hero-grid span { display: block; }
.hero-grid span { margin-top: 8px; color: var(--muted); font-size: 13px; word-break: break-word; }

.form-header h2 {
    margin: 0 0 8px;
    font-size: 28px;
}

.form-header p {
    color: var(--muted);
    margin: 0 0 24px;
    line-height: 1.5;
}

label {
    display: block;
    font-weight: 750;
    font-size: 13px;
    color: #d7e5fb;
    margin: 0 0 7px;
}

input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    background: #0b1627;
    border-radius: 8px;
    padding: 12px 13px;
    outline: none;
    color: var(--ink);
    margin-bottom: 14px;
    transition: border-color .18s, box-shadow .18s, background .18s;
}

input::placeholder, textarea::placeholder { color: #60728f; }

select {
    color-scheme: dark;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, .16);
    background: #0e1b2e;
}

textarea {
    min-height: 118px;
    resize: vertical;
    line-height: 1.5;
}

.btn {
    border-radius: 8px;
    padding: 12px 16px;
    cursor: pointer;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    transition: transform .18s, box-shadow .18s, background .18s, border-color .18s;
    white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); }

.btn.primary {
    width: 100%;
    color: #04111f;
    background: linear-gradient(135deg, var(--primary), #7dd3fc);
    box-shadow: 0 12px 24px rgba(56, 189, 248, .2);
}

.btn.ghost {
    background: rgba(56, 189, 248, .1);
    color: #c7ecff;
    border: 1px solid rgba(56, 189, 248, .28);
}

.btn.light {
    background: rgba(255,255,255,.1);
    color: white;
    border: 1px solid rgba(255,255,255,.25);
}

.btn.mini {
    padding: 8px 10px;
    min-height: 34px;
    font-size: 12px;
    background: rgba(56, 189, 248, .1);
    color: #c7ecff;
    width: auto;
    border: 1px solid rgba(56, 189, 248, .22);
}

.btn.danger { background: rgba(248, 113, 113, .12); color: #fecaca; border-color: rgba(248, 113, 113, .35); }
.btn.ok { background: rgba(52, 211, 153, .12); color: #bbf7d0; border-color: rgba(52, 211, 153, .35); }

.soft-link {
    margin-top: 18px;
    display: inline-block;
    color: var(--primary);
    font-weight: 800;
}

.layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
    background:
        linear-gradient(120deg, rgba(37, 99, 235, .18), transparent 36%),
        var(--bg);
}

.sidebar {
    background: rgba(8, 18, 33, .96);
    color: white;
    padding: 22px;
    position: sticky;
    top: 0;
    height: 100vh;
    border-right: 1px solid var(--line-soft);
}

.side-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 28px;
}

.side-brand span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-top: 3px;
}

.sidebar nav {
    display: grid;
    gap: 6px;
}

.sidebar nav a {
    padding: 12px 13px;
    border-radius: 8px;
    color: #b8c7df;
    font-weight: 750;
    border: 1px solid transparent;
}

.sidebar nav a:hover,
.sidebar nav a.active {
    background: rgba(56, 189, 248, .12);
    border-color: rgba(56, 189, 248, .28);
    color: white;
}

.content {
    padding: 30px;
    min-width: 0;
}

.admin-section {
    animation: fadeIn .18s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

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

.topbar .eyebrow { margin-top: 0; }
.topbar h1 { margin: 8px 0 0; font-size: 34px; letter-spacing: 0; }

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}

.stat {
    padding: 18px;
    background: linear-gradient(180deg, rgba(19, 36, 59, .94), rgba(13, 27, 48, .94));
}

.stat span {
    color: var(--muted);
    font-weight: 750;
}

.stat strong {
    display: block;
    margin-top: 10px;
    font-size: 30px;
    letter-spacing: 0;
}

.panel {
    padding: 22px;
}

.panel-title {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}

.panel-title h2 {
    margin: 0 0 6px;
    font-size: 24px;
}

.panel-title p {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
}

.grid-form {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.grid-form.compact {
    grid-template-columns: 1.1fr 1.3fr .7fr .75fr .7fr .75fr;
}

.grid-form.compact-settings {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-form input, .grid-form select, .grid-form textarea,
.settings-form input, .settings-form select, .settings-form textarea {
    margin-bottom: 0;
    background: #0b1627;
}

.full { grid-column: 1 / -1; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.actions .btn { width: auto; }
.form-bottom { align-self: end; }

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0b1627;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 880px;
}

th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    color: #8fb4dd;
    letter-spacing: .06em;
    background: #0d1a2d;
}

th, td {
    padding: 14px;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
}

td a {
    color: #7dd3fc;
    word-break: break-word;
}

td small {
    display: block;
    color: var(--muted);
    margin-top: 5px;
}

.pill, .status {
    display: inline-flex;
    padding: 6px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 900;
}

.pill {
    background: rgba(56, 189, 248, .12);
    color: #bae6fd;
}

.status.pending { background: rgba(251, 191, 36, .16); color: #fde68a; }
.status.expired { background: rgba(248, 113, 113, .16); color: #fecaca; }
.status.paid { background: rgba(52, 211, 153, .16); color: #bbf7d0; }

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.row-actions form { margin: 0; }

.empty {
    text-align: center;
    color: var(--muted);
    padding: 28px;
}

.mt { margin-top: 18px; }

.alert {
    padding: 13px 15px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-weight: 750;
}

.alert-success { background: rgba(52, 211, 153, .14); color: #bbf7d0; border: 1px solid rgba(52, 211, 153, .35); }
.alert-danger { background: rgba(248, 113, 113, .14); color: #fecaca; border: 1px solid rgba(248, 113, 113, .35); }

.settings-form {
    display: grid;
    gap: 22px;
}

.settings-block {
    border-top: 1px solid var(--line-soft);
    padding-top: 18px;
}

.settings-block:first-of-type {
    border-top: 0;
    padding-top: 0;
}

.settings-block h3,
.template-head h3 {
    margin: 0 0 14px;
    font-size: 17px;
}

.check-row {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    cursor: pointer;
}

.check-row input {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--primary);
}

.template-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 12px;
}

.variable-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    max-width: 720px;
}

.variable-list span {
    border: 1px solid rgba(56, 189, 248, .22);
    border-radius: 999px;
    background: rgba(56, 189, 248, .08);
    color: #bfdbfe;
    padding: 5px 8px;
    font-size: 12px;
    font-weight: 800;
}

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

.settings-actions {
    border-top: 1px solid var(--line-soft);
    padding-top: 18px;
}

.integration-tests {
    display: grid;
    grid-template-columns: repeat(3, auto) 1fr;
    gap: 12px;
    border-top: 1px solid var(--line-soft);
    margin-top: 22px;
    padding-top: 18px;
}

.test-form {
    display: flex;
    gap: 10px;
    align-items: center;
    margin: 0;
}

.test-form input {
    margin-bottom: 0;
    background: #0b1627;
}

.test-form-wide {
    justify-content: flex-end;
}

.instance-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.instance-list span {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(148, 163, 184, .08);
    color: var(--muted);
    padding: 6px 9px;
    font-size: 12px;
    font-weight: 800;
}

.instance-list span.online {
    border-color: rgba(52, 211, 153, .35);
    background: rgba(52, 211, 153, .12);
    color: #bbf7d0;
}

.client-page {
    min-height: 100vh;
    background:
        linear-gradient(120deg, rgba(37, 99, 235, .18), transparent 36%),
        var(--bg);
    padding: 28px;
}

.client-hero {
    border-radius: 8px;
    padding: 30px;
    color: white;
    background:
        linear-gradient(145deg, rgba(37, 99, 235, .48), rgba(10, 21, 38, .96)),
        var(--surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
}

.client-hero .eyebrow { margin-top: 0; }
.client-hero h1 { margin: 10px 0; font-size: 38px; letter-spacing: 0; }
.client-hero p { color: #c8d8f2; margin: 0; line-height: 1.5; }

.client-info {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin: 20px 0;
}

.client-info div {
    padding: 18px;
    min-width: 0;
}

.client-info span {
    display: block;
    color: var(--muted);
    font-weight: 750;
    margin-bottom: 8px;
}

.client-info strong,
.client-info a {
    word-break: break-word;
}

.invoice-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.invoice-card, .empty-card {
    padding: 22px;
}

.invoice-card.expired { border-color: rgba(248, 113, 113, .42); }
.invoice-card.paid { border-color: rgba(52, 211, 153, .42); }

.invoice-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.invoice-top small {
    color: var(--muted);
    word-break: break-word;
    text-align: right;
}

.invoice-card h2 {
    margin: 18px 0 8px;
    font-size: 21px;
    line-height: 1.25;
}

.price {
    display: block;
    font-size: 32px;
    letter-spacing: 0;
}

.invoice-card p { color: var(--muted); }

.notice {
    padding: 11px 12px;
    border-radius: 8px;
    margin: 14px 0;
    font-weight: 800;
    line-height: 1.4;
}

.notice.warning { background: rgba(251, 191, 36, .16); color: #fde68a; }
.notice.danger { background: rgba(248, 113, 113, .16); color: #fecaca; }
.notice.ok { background: rgba(52, 211, 153, .16); color: #bbf7d0; }
.full-btn { margin-top: 8px; }

.empty-card {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--muted);
    font-weight: 750;
}

@media (max-width: 1100px) {
    .auth-shell, .layout, .stats, .client-info, .invoice-grid {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: relative;
        height: auto;
    }

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

    .grid-form,
    .grid-form.compact,
    .grid-form.compact-settings,
    .template-grid,
    .integration-tests {
        grid-template-columns: 1fr;
    }

    .hero-card {
        min-height: auto;
        padding: 34px;
    }

    .hero-card h1 {
        font-size: 40px;
    }

    .hero-grid {
        grid-template-columns: 1fr;
    }

    .topbar, .panel-title, .client-hero, .template-head {
        flex-direction: column;
        align-items: flex-start;
    }

    .variable-list {
        justify-content: flex-start;
    }

    .test-form,
    .test-form-wide {
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}

@media (max-width: 640px) {
    .auth-body,
    .client-page,
    .content {
        padding: 16px;
    }

    .login-card,
    .hero-card,
    .panel,
    .client-hero {
        padding: 20px;
    }

    .sidebar {
        padding: 16px;
    }

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

    .topbar h1,
    .client-hero h1 {
        font-size: 30px;
    }

    .hero-card h1 {
        font-size: 34px;
    }

    .btn {
        width: 100%;
        white-space: normal;
    }

    .actions .btn,
    .test-form .btn {
        width: 100%;
    }
}
