:root {
    --brand: #1a3e73;
    --brand-2: #2f6fd4;
    --ink: #172033;
    --muted: #6f7a8f;
    --line: #e4e9f2;
    --soft: #f4f7fb;
    --panel: #ffffff;
    --danger: #d92d20;
    --success: #067647;
    --warning: #b54708;
    --radius: 24px;
    --small-radius: 16px;
    --shadow: 0 24px 70px rgba(20, 35, 70, .12);
    --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font);
    background: linear-gradient(135deg, #eef3fa 0%, #f8fbff 38%, #edf5ff 100%);
    color: var(--ink);
}

body {
    min-height: 100vh;
}

a {
    color: inherit;
    text-decoration: none;
}

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

button {
    cursor: pointer;
}

.public-screen {
    display: grid;
    place-items: center;
    padding: 32px;
}

.auth-shell {
    width: min(1040px, 100%);
    display: grid;
    grid-template-columns: 1.05fr .95fr;
    gap: 22px;
}

.auth-panel {
    background: rgba(255, 255, 255, .82);
    border: 1px solid rgba(255,255,255,.82);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 34px;
    backdrop-filter: blur(18px);
}

.brand-panel {
    background: radial-gradient(circle at top left, rgba(47, 111, 212, .18), transparent 36%), linear-gradient(135deg, var(--brand), #132744);
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

.brand-panel h1 {
    font-size: clamp(34px, 5vw, 60px);
    line-height: .95;
    margin: 20px 0 12px;
}

.brand-panel p {
    color: rgba(255,255,255,.78);
    font-size: 18px;
    line-height: 1.6;
    max-width: 560px;
}

.brand-visual {
    width: 96px;
    height: 96px;
}

.form-panel h2, .card h2 {
    margin: 0;
    font-size: 24px;
    letter-spacing: -.03em;
}

.muted, .eyebrow {
    color: var(--muted);
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: .12em;
    font-size: 12px;
    font-weight: 800;
    margin: 0 0 6px;
}

.stack-form, .form-grid {
    display: grid;
    gap: 16px;
}

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

.form-grid.one {
    grid-template-columns: 1fr;
}

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

label {
    display: grid;
    gap: 8px;
    color: #3e4a5e;
    font-size: 13px;
    font-weight: 800;
}

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

input:focus, textarea:focus, select:focus, .editor-canvas:focus {
    border-color: rgba(26, 62, 115, .52);
    box-shadow: 0 0 0 4px rgba(26, 62, 115, .12);
}

input[type="color"] {
    min-height: 48px;
    padding: 6px;
}

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

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 22px;
    background: rgba(255,255,255,.76);
    border-right: 1px solid rgba(226, 232, 240, .9);
    backdrop-filter: blur(18px);
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--small-radius);
    font-weight: 900;
    letter-spacing: -.02em;
}

.brand img {
    width: 42px;
    height: 42px;
}

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

.nav-link, .logout-form button {
    border: 0;
    width: 100%;
    background: transparent;
    color: #556176;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 14px;
    border-radius: 18px;
    font-weight: 800;
    text-align: left;
    transition: .18s ease;
}

.nav-link:hover, .logout-form button:hover {
    background: rgba(26, 62, 115, .08);
    color: var(--brand);
}

.nav-link.active {
    background: linear-gradient(135deg, var(--brand), var(--brand-2));
    color: #fff;
    box-shadow: 0 14px 28px rgba(26, 62, 115, .24);
}

.nav-icon, .button-icon {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
}

.nav-link.active .nav-icon {
    filter: brightness(0) invert(1);
}

.logout-form {
    margin-top: auto;
}

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

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

.topbar h1 {
    margin: 0;
    font-size: clamp(28px, 4vw, 42px);
    letter-spacing: -.055em;
}

.top-actions, .button-row, .row-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.primary-btn, .secondary-btn, .small-btn, .icon-button, .toolbar button {
    border: 0;
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    font-weight: 900;
    transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}

.primary-btn {
    background: linear-gradient(135deg, var(--brand), var(--brand-2));
    color: #fff;
    min-height: 48px;
    padding: 0 18px;
    box-shadow: 0 16px 30px rgba(26, 62, 115, .22);
}

.secondary-btn, .small-btn, .toolbar button {
    background: #fff;
    border: 1px solid var(--line);
    color: var(--ink);
    min-height: 44px;
    padding: 0 15px;
}

.small-btn {
    min-height: 34px;
    padding: 0 12px;
    border-radius: 12px;
    font-size: 12px;
}

.danger {
    color: var(--danger);
}

.primary-btn:hover, .secondary-btn:hover, .small-btn:hover, .icon-button:hover, .toolbar button:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(20, 35, 70, .10);
}

.icon-button {
    width: 46px;
    height: 46px;
    background: #fff;
    border: 1px solid var(--line);
}

.mobile-only {
    display: none;
}

.page-content {
    display: grid;
    gap: 22px;
}

.card, .stat-card {
    background: rgba(255,255,255,.86);
    border: 1px solid rgba(226, 232, 240, .92);
    border-radius: var(--radius);
    box-shadow: 0 18px 46px rgba(20, 35, 70, .08);
    backdrop-filter: blur(16px);
}

.card {
    padding: 22px;
}

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

.stat-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(150px, 1fr));
    gap: 16px;
}

.stat-card {
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 13px;
}

.stat-card p {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.stat-card strong {
    display: block;
    font-size: 28px;
    letter-spacing: -.05em;
}

.stat-icon, .tile-icon {
    width: 42px;
    height: 42px;
    border-radius: 16px;
    background: rgba(26, 62, 115, .09);
    padding: 10px;
}

.grid-two {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 22px;
}

.align-start {
    align-items: start;
}

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

.wide-card, .narrow-card {
    grid-column: 1 / -1;
}

.narrow-card {
    max-width: 720px;
}

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

.action-tile {
    min-height: 118px;
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 18px;
    background: linear-gradient(180deg, #fff, #f8fbff);
    display: flex;
    flex-direction: column;
    gap: 14px;
    font-weight: 900;
}

.mini-list, .template-list {
    display: grid;
    gap: 12px;
}

.mini-row, .template-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
}

.template-card div:first-child {
    display: grid;
    gap: 5px;
}

.template-card span {
    color: var(--muted);
    font-size: 13px;
}

.text-link {
    color: var(--brand);
    font-weight: 900;
}

.table-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: #fff;
}

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

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

th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    background: #f8fafc;
}

td {
    font-size: 14px;
}

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

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    background: rgba(26, 62, 115, .09);
    color: var(--brand);
    font-weight: 900;
    font-size: 12px;
}

.empty-state {
    min-height: 190px;
    border: 1px dashed #cad4e4;
    border-radius: 22px;
    display: grid;
    place-items: center;
    gap: 10px;
    text-align: center;
    padding: 24px;
    background: linear-gradient(135deg, #f8fbff, #fff);
    color: var(--muted);
    font-weight: 800;
}

.empty-state img {
    width: 118px;
    height: auto;
}

.editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 22px;
    align-items: start;
}

.editor-main, .editor-side {
    min-width: 0;
}

.toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.toolbar button {
    min-height: 36px;
    border-radius: 12px;
    font-size: 12px;
}

.editor-canvas {
    min-height: 560px;
    width: 100%;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: #fff;
    padding: 28px;
    line-height: 1.6;
    outline: none;
}

.editor-canvas:empty::before {
    content: attr(data-empty);
    color: #9aa6bb;
}

.small-editor {
    min-height: 320px;
}

.test-send {
    display: flex;
    align-items: end;
    gap: 14px;
    flex-wrap: wrap;
}

.test-send label {
    min-width: min(360px, 100%);
    flex: 1;
}

.target-select {
    display: none;
}

.target-select.show {
    display: grid;
}

.table-search {
    width: min(280px, 100%);
}

.inline-filter {
    margin-bottom: 16px;
    max-width: 420px;
}

.metric-row {
    display: grid;
    grid-template-columns: repeat(6, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.metric-row div {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 15px;
}

.metric-row span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    margin-bottom: 5px;
}

.metric-row strong {
    font-size: 24px;
}

.check-line {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-direction: row;
    padding-top: 24px;
}

.check-line input {
    width: auto;
}

.flash-wrap {
    display: grid;
    gap: 10px;
    margin-bottom: 18px;
}

.flash {
    border-radius: 16px;
    padding: 13px 15px;
    font-weight: 850;
    border: 1px solid var(--line);
    background: #fff;
}

.flash.success {
    border-color: rgba(6, 118, 71, .2);
    color: var(--success);
    background: #ecfdf3;
}

.flash.error {
    border-color: rgba(217, 45, 32, .2);
    color: var(--danger);
    background: #fff1f0;
}

.flash.warning {
    border-color: rgba(181, 71, 8, .2);
    color: var(--warning);
    background: #fffaeb;
}

@media (max-width: 1280px) {
    .stat-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .metric-row {
        grid-template-columns: repeat(3, 1fr);
    }
}

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

    .sidebar {
        position: fixed;
        left: 16px;
        top: 16px;
        bottom: 16px;
        width: min(310px, calc(100vw - 32px));
        height: auto;
        transform: translateX(calc(-100% - 40px));
        transition: transform .22s ease;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-only {
        display: inline-flex;
    }

    .workspace {
        padding: 18px;
    }

    .topbar {
        align-items: flex-start;
    }

    .top-actions {
        display: none;
    }

    .grid-two, .settings-grid, .editor-grid, .auth-shell {
        grid-template-columns: 1fr;
    }

    .editor-side {
        order: -1;
    }
}

@media (max-width: 680px) {
    .stat-grid, .form-grid, .metric-row, .action-grid {
        grid-template-columns: 1fr;
    }

    .card, .auth-panel {
        padding: 18px;
    }

    .editor-canvas {
        min-height: 420px;
        padding: 18px;
    }

    .public-screen {
        padding: 16px;
    }

    .topbar h1 {
        font-size: 28px;
    }
}
