:root {
    --primary: #4f46e5;
    --primary-dark: #3730a3;
    --primary-soft: #eef2ff;
    --success: #16a34a;
    --success-soft: #f0fdf4;
    --warning: #d97706;
    --warning-soft: #fffbeb;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --info: #0284c7;
    --info-soft: #f0f9ff;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --surface: #ffffff;
    --canvas: #f6f7fb;
    --sidebar: #111827;
    --shadow: 0 12px 35px rgba(15, 23, 42, 0.07);
    --radius: 18px;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-width: 320px;
    color: var(--ink);
    background: var(--canvas);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

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

button {
    cursor: pointer;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

#managerView,
#loadingIndicator,
#loginError {
    display: none;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(320px, 1.1fr) minmax(380px, 0.9fr);
    background: var(--surface);
}

.auth-visual {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 100vh;
    padding: clamp(2rem, 5vw, 5rem);
    overflow: hidden;
    color: #fff;
    background:
        radial-gradient(circle at 15% 20%, rgba(129, 140, 248, 0.55), transparent 30%),
        radial-gradient(circle at 85% 80%, rgba(14, 165, 233, 0.32), transparent 35%),
        linear-gradient(145deg, #111827 0%, #312e81 55%, #1e1b4b 100%);
}

.auth-visual::after {
    content: "";
    position: absolute;
    right: -12rem;
    bottom: -14rem;
    width: 34rem;
    height: 34rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 50%;
    box-shadow: 0 0 0 70px rgba(255, 255, 255, 0.035), 0 0 0 140px rgba(255, 255, 255, 0.025);
}

.brand {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 13px;
    color: #fff;
    background: linear-gradient(135deg, #818cf8, #4f46e5);
    box-shadow: 0 10px 25px rgba(79, 70, 229, 0.35);
}

.brand-mark svg {
    width: 23px;
    height: 23px;
}

.brand-copy span {
    display: block;
    font-size: 1.05rem;
}

.brand-copy small {
    display: block;
    margin-top: 0.05rem;
    color: rgba(255, 255, 255, 0.56);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.auth-pitch {
    position: relative;
    z-index: 1;
    max-width: 620px;
}

.auth-pitch h1 {
    max-width: 560px;
    margin: 0 0 1.25rem;
    font-size: clamp(2.4rem, 5vw, 4.7rem);
    line-height: 1.02;
    letter-spacing: -0.055em;
}

.auth-pitch p {
    max-width: 520px;
    margin: 0;
    color: rgba(255, 255, 255, 0.7);
    font-size: 1.05rem;
    line-height: 1.7;
}

.auth-feature-row {
    position: relative;
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 0.7rem;
}

.auth-feature {
    padding: 0.55rem 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 999px;
    color: rgba(255, 255, 255, 0.78);
    background: rgba(255, 255, 255, 0.07);
    backdrop-filter: blur(8px);
    font-size: 0.82rem;
}

.auth-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.login-card {
    width: min(100%, 430px);
}

.eyebrow {
    margin: 0 0 0.65rem;
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.login-card h2 {
    margin: 0 0 0.6rem;
    font-size: 2rem;
    letter-spacing: -0.035em;
}

.login-card > p:not(.eyebrow) {
    margin: 0 0 2rem;
    color: var(--muted);
    line-height: 1.6;
}

.field {
    margin-bottom: 1.25rem;
}

.field-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(180px, 0.38fr);
    gap: 1rem;
}

.field label,
.field-label {
    display: block;
    margin-bottom: 0.5rem;
    color: #334155;
    font-size: 0.86rem;
    font-weight: 700;
}

.input,
.select,
.textarea {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 11px;
    outline: none;
    color: var(--ink);
    background: var(--surface);
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.input,
.select {
    min-height: 48px;
    padding: 0 0.9rem;
}

.textarea {
    min-height: 170px;
    padding: 0.9rem;
    line-height: 1.55;
    resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
    border-color: #818cf8;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.11);
}

.field-help {
    display: block;
    margin-top: 0.48rem;
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.45;
}

.password-wrap {
    position: relative;
}

.password-wrap .input {
    padding-right: 4.3rem;
}

.password-toggle {
    position: absolute;
    top: 50%;
    right: 0.8rem;
    padding: 0.25rem;
    border: 0;
    color: var(--primary);
    background: none;
    font-size: 0.78rem;
    font-weight: 700;
    transform: translateY(-50%);
}

.btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem 1rem;
    border: 1px solid transparent;
    border-radius: 11px;
    font-weight: 750;
    transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

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

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    transform: none;
}

.btn-primary {
    color: #fff;
    background: linear-gradient(135deg, #5b54e8, #4338ca);
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.2);
}

.btn-secondary {
    color: #334155;
    border-color: var(--line);
    background: var(--surface);
}

.btn-danger-soft {
    color: #b91c1c;
    background: var(--danger-soft);
}

.btn-block {
    width: 100%;
}

.login-error {
    margin: 1rem 0 0;
    padding: 0.8rem 0.9rem;
    border: 1px solid #fecaca;
    border-radius: 10px;
    color: #b91c1c;
    background: var(--danger-soft);
    font-size: 0.86rem;
}

.loading-overlay {
    position: fixed;
    z-index: 1000;
    inset: 0;
    align-items: center;
    justify-content: center;
    background: rgba(246, 247, 251, 0.85);
    backdrop-filter: blur(6px);
}

.loader-card {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 1rem 1.2rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow);
    font-weight: 700;
}

.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid #c7d2fe;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.app-shell {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    z-index: 60;
    top: 0;
    bottom: 0;
    left: 0;
    width: 260px;
    display: flex;
    flex-direction: column;
    padding: 1.4rem 1rem;
    color: #fff;
    background: var(--sidebar);
}

.sidebar .brand {
    padding: 0 0.6rem 1.6rem;
}

.sidebar-label {
    margin: 1rem 0.7rem 0.55rem;
    color: #64748b;
    font-size: 0.67rem;
    font-weight: 800;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.side-nav {
    display: grid;
    gap: 0.3rem;
    min-height: 0;
    overflow-y: auto;
    padding-right: 0.2rem;
}

.nav-item {
    width: 100%;
    min-height: 47px;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0 0.8rem;
    border: 0;
    border-radius: 11px;
    color: #94a3b8;
    background: transparent;
    text-align: left;
    font-size: 0.9rem;
    font-weight: 650;
    transition: color 0.18s ease, background 0.18s ease;
}

.nav-item:hover,
.nav-item.active {
    color: #fff;
    background: rgba(99, 102, 241, 0.18);
}

.nav-item.active {
    box-shadow: inset 3px 0 0 #818cf8;
}

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

.nav-badge {
    min-width: 22px;
    margin-left: auto;
    padding: 0.15rem 0.4rem;
    border-radius: 999px;
    color: #c7d2fe;
    background: rgba(99, 102, 241, 0.25);
    font-size: 0.7rem;
    text-align: center;
}

.sidebar-footer {
    margin-top: auto;
    padding: 1rem 0.7rem 0.4rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.connection-state {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: #94a3b8;
    font-size: 0.77rem;
    font-weight: 650;
}

.connection-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #f59e0b;
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.12);
}

.connection-state.online .connection-dot {
    background: #22c55e;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.12);
}

.app-main {
    min-height: 100vh;
    margin-left: 260px;
}

.topbar {
    position: sticky;
    z-index: 40;
    top: 0;
    height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 2rem;
    border-bottom: 1px solid rgba(226, 232, 240, 0.85);
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(14px);
}

.topbar-left,
.topbar-actions,
.section-actions,
.button-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.menu-toggle {
    width: 42px;
    height: 42px;
    display: none;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: #334155;
    background: var(--surface);
}

.page-title {
    margin: 0;
    font-size: 1.05rem;
    letter-spacing: -0.015em;
}

.top-connection {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 650;
}

.icon-button {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: #475569;
    background: var(--surface);
}

.content {
    width: min(100%, 1440px);
    margin: 0 auto;
    padding: 2rem;
}

.app-page {
    display: none;
    animation: pageIn 0.22s ease;
}

.app-page.active {
    display: block;
}

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

.hero {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    padding: clamp(1.5rem, 4vw, 2.5rem);
    overflow: hidden;
    border-radius: 22px;
    color: #fff;
    background:
        radial-gradient(circle at 85% 20%, rgba(125, 211, 252, 0.25), transparent 25%),
        linear-gradient(120deg, #312e81, #4f46e5 62%, #6366f1);
    box-shadow: 0 20px 50px rgba(49, 46, 129, 0.2);
}

.hero::after {
    content: "";
    position: absolute;
    right: 7%;
    width: 170px;
    height: 170px;
    border: 28px solid rgba(255, 255, 255, 0.07);
    border-radius: 50%;
}

.hero-copy,
.hero-actions {
    position: relative;
    z-index: 1;
}

.hero h1 {
    margin: 0 0 0.55rem;
    font-size: clamp(1.7rem, 3vw, 2.65rem);
    letter-spacing: -0.045em;
}

.hero p {
    max-width: 620px;
    margin: 0;
    color: rgba(255, 255, 255, 0.7);
    line-height: 1.6;
}

.hero .btn {
    color: var(--primary-dark);
    background: #fff;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.16);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin: 1.25rem 0;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.15rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.035);
}

.stat-icon {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 14px;
}

.stat-icon.pending { color: var(--warning); background: var(--warning-soft); }
.stat-icon.sent { color: var(--info); background: var(--info-soft); }
.stat-icon.delivered { color: var(--success); background: var(--success-soft); }
.stat-icon.failed { color: var(--danger); background: var(--danger-soft); }

.stat-value {
    display: block;
    font-size: 1.6rem;
    font-weight: 850;
    line-height: 1;
}

.stat-label {
    display: block;
    margin-top: 0.35rem;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 650;
}

.dashboard-grid,
.compose-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(270px, 0.65fr);
    gap: 1.25rem;
}

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

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.3rem 1.4rem;
    border-bottom: 1px solid var(--line);
}

.card-header h2,
.card-header h3 {
    margin: 0;
    font-size: 1rem;
    letter-spacing: -0.015em;
}

.card-header p {
    margin: 0.3rem 0 0;
    color: var(--muted);
    font-size: 0.78rem;
}

.card-body {
    padding: 1.4rem;
}

.section-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.4rem;
}

.section-heading h1 {
    margin: 0;
    font-size: clamp(1.55rem, 3vw, 2.15rem);
    letter-spacing: -0.045em;
}

.section-heading p {
    margin: 0.45rem 0 0;
    color: var(--muted);
}

.activity-list,
.inbox-list {
    max-height: 510px;
    overflow-y: auto;
}

.activity-empty,
.inbox-empty {
    display: grid;
    place-items: center;
    min-height: 235px;
    padding: 2rem;
    color: var(--muted);
    text-align: center;
}

.empty-icon {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    margin: 0 auto 0.8rem;
    border-radius: 16px;
    color: #818cf8;
    background: var(--primary-soft);
}

.activity-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.85rem;
    padding: 1rem 1.4rem;
    border-bottom: 1px solid var(--line);
}

.activity-item:last-child {
    border-bottom: 0;
}

.activity-status-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    color: var(--info);
    background: var(--info-soft);
    font-weight: 900;
}

.status-queued .activity-status-icon { color: var(--warning); background: var(--warning-soft); }
.status-sent .activity-status-icon { color: var(--info); background: var(--info-soft); }
.status-delivered .activity-status-icon { color: var(--success); background: var(--success-soft); }
.status-failed .activity-status-icon,
.status-cancelled .activity-status-icon { color: var(--danger); background: var(--danger-soft); }

.activity-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.8rem;
}

.activity-title {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 800;
}

.activity-time {
    color: #94a3b8;
    font-size: 0.7rem;
    white-space: nowrap;
}

.activity-recipient {
    margin: 0.2rem 0 0;
    color: #334155;
    font-size: 0.86rem;
    overflow-wrap: anywhere;
}

.status-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.8rem;
    margin-top: 0.45rem;
    color: var(--muted);
    font-size: 0.72rem;
    overflow-wrap: anywhere;
}

.status-reason {
    width: 100%;
    color: var(--danger);
    font-weight: 650;
}

.tip-list {
    display: grid;
    gap: 1rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.tip-item {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 0.7rem;
    color: #475569;
    font-size: 0.82rem;
    line-height: 1.5;
}

.tip-number {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    color: var(--primary);
    background: var(--primary-soft);
    font-size: 0.72rem;
    font-weight: 850;
}

.message-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 0.5rem;
}

.character-count {
    color: var(--muted);
    font-size: 0.75rem;
}

.character-count strong {
    color: #334155;
}

.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 0;
    border-top: 1px solid var(--line);
}

.switch-copy strong,
.switch-copy span {
    display: block;
}

.switch-copy strong {
    color: #334155;
    font-size: 0.84rem;
}

.switch-copy span {
    margin-top: 0.2rem;
    color: var(--muted);
    font-size: 0.73rem;
}

.switch {
    position: relative;
    width: 44px;
    height: 25px;
    flex: 0 0 auto;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: #cbd5e1;
    transition: 0.2s;
}

.switch-slider::before {
    content: "";
    position: absolute;
    width: 19px;
    height: 19px;
    top: 3px;
    left: 3px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 5px rgba(15, 23, 42, 0.2);
    transition: 0.2s;
}

.switch input:checked + .switch-slider {
    background: var(--primary);
}

.switch input:checked + .switch-slider::before {
    transform: translateX(19px);
}

.form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.2rem;
}

.send-feedback,
.bulk-feedback {
    display: none;
    margin-bottom: 1rem;
    padding: 0.85rem 1rem;
    border-radius: 11px;
    font-size: 0.82rem;
    font-weight: 650;
}

.feedback-success { display: block; color: #166534; background: var(--success-soft); }
.feedback-error { display: block; color: #991b1b; background: var(--danger-soft); }
.feedback-info { display: block; color: #075985; background: var(--info-soft); }

.upload-zone {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 190px;
    padding: 2rem;
    border: 1.5px dashed #cbd5e1;
    border-radius: 15px;
    color: var(--muted);
    background: #fafbff;
    text-align: center;
    transition: border-color 0.18s ease, background 0.18s ease;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: #818cf8;
    background: var(--primary-soft);
}

.upload-zone input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    opacity: 0;
}

.upload-zone strong,
.upload-zone span {
    display: block;
}

.upload-zone strong {
    margin-bottom: 0.35rem;
    color: #334155;
}

.upload-zone span {
    font-size: 0.78rem;
}

.upload-icon {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    margin: 0 auto 0.8rem;
    border-radius: 13px;
    color: var(--primary);
    background: var(--primary-soft);
}

#csvPreview {
    display: none;
    margin-top: 1rem;
    border: 1px solid var(--line);
    border-radius: 13px;
    overflow: hidden;
}

.preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    color: #334155;
    background: #f8fafc;
    font-size: 0.8rem;
    font-weight: 800;
}

#csvPreviewContent {
    max-height: 270px;
    overflow-y: auto;
}

.csv-row {
    display: grid;
    grid-template-columns: 34px minmax(120px, 0.5fr) minmax(0, 1fr);
    gap: 0.6rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--line);
    color: #475569;
    font-size: 0.78rem;
}

.csv-index {
    color: #94a3b8;
}

.csv-phone {
    color: #334155;
    font-weight: 750;
}

.csv-message {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inbox-message {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 0.85rem;
    padding: 1rem 1.4rem;
    border-bottom: 1px solid var(--line);
}

.inbox-message:last-child {
    border-bottom: 0;
}

.sender-avatar {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 13px;
    color: var(--primary);
    background: var(--primary-soft);
    font-size: 0.78rem;
    font-weight: 850;
}

.inbox-message-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.inbox-sender {
    color: #334155;
    font-size: 0.86rem;
    font-weight: 800;
    overflow-wrap: anywhere;
}

.inbox-time {
    color: #94a3b8;
    font-size: 0.7rem;
    white-space: nowrap;
}

.inbox-text {
    margin: 0.35rem 0 0;
    color: #475569;
    font-size: 0.84rem;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.toast-region {
    position: fixed;
    z-index: 2000;
    right: 1rem;
    bottom: 1rem;
    width: min(390px, calc(100vw - 2rem));
    display: grid;
    gap: 0.65rem;
    pointer-events: none;
}

.toast {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    border: 1px solid var(--line);
    border-radius: 13px;
    color: #334155;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(10px);
    animation: toastIn 0.22s ease;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--info); }

.toast-icon {
    font-weight: 900;
}

.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--danger); }
.toast.info .toast-icon { color: var(--info); }

.toast strong,
.toast span {
    display: block;
}

.toast strong {
    font-size: 0.84rem;
}

.toast span {
    margin-top: 0.15rem;
    color: var(--muted);
    font-size: 0.75rem;
    line-height: 1.4;
}

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

.mobile-backdrop {
    display: none;
}

.data-toolbar {
    display: flex;
    align-items: flex-end;
    gap: 0.85rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--line);
    background: #fbfcff;
}

.search-box {
    min-height: 46px;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex: 1;
    padding: 0 0.85rem;
    border: 1px solid #cbd5e1;
    border-radius: 11px;
    color: #94a3b8;
    background: #fff;
}

.search-box input {
    width: 100%;
    border: 0;
    outline: 0;
    color: var(--ink);
    background: transparent;
}

.toolbar-summary {
    margin-left: auto;
    padding: 0.45rem 0.7rem;
    border-radius: 999px;
    color: #475569;
    background: #eef2f7;
    font-size: 0.75rem;
    font-weight: 750;
    white-space: nowrap;
}

.compact-field {
    min-width: 160px;
    margin: 0;
}

.compact-field .input,
.compact-field .select {
    min-height: 42px;
}

.contacts-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    padding: 1.25rem;
}

.contacts-grid > .activity-empty {
    grid-column: 1 / -1;
}

.contact-card {
    position: relative;
    padding: 1.1rem;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: #fff;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.contact-card:hover {
    border-color: #c7d2fe;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
    transform: translateY(-2px);
}

.contact-head {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.contact-avatar {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 14px;
    color: var(--primary);
    background: var(--primary-soft);
    font-size: 0.8rem;
    font-weight: 850;
}

.contact-name {
    margin: 0;
    color: #1e293b;
    font-size: 0.92rem;
    font-weight: 850;
}

.contact-company {
    margin: 0.2rem 0 0;
    color: var(--muted);
    font-size: 0.74rem;
}

.contact-details {
    display: grid;
    gap: 0.35rem;
    margin: 1rem 0;
    color: #475569;
    font-size: 0.8rem;
    overflow-wrap: anywhere;
}

.contact-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.mini-button {
    min-height: 34px;
    padding: 0.4rem 0.65rem;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: #475569;
    background: #fff;
    font-size: 0.72rem;
    font-weight: 750;
}

.mini-button.primary { color: var(--primary); border-color: #c7d2fe; background: var(--primary-soft); }
.mini-button.danger { color: var(--danger); }

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

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

.data-table th {
    color: #64748b;
    background: #f8fafc;
    font-size: 0.68rem;
    font-weight: 850;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.data-table td {
    color: #475569;
    font-size: 0.79rem;
}

.table-message {
    max-width: 330px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.state-badge,
.log-status {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.55rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 800;
    white-space: nowrap;
}

.state-Pending,
.state-Processed { color: #92400e; background: var(--warning-soft); }
.state-Sent { color: #075985; background: var(--info-soft); }
.state-Delivered { color: #166534; background: var(--success-soft); }
.state-Failed,
.state-Cancelled { color: #991b1b; background: var(--danger-soft); }

.pagination-footer {
    display: flex;
    justify-content: center;
    padding: 1rem;
}

.operation-list {
    max-height: 650px;
    overflow-y: auto;
}

.operation-item {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) auto;
    gap: 0.85rem;
    align-items: center;
    padding: 0.9rem 1.25rem;
    border-bottom: 1px solid var(--line);
}

.operation-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    color: var(--primary);
    background: var(--primary-soft);
    font-weight: 850;
}

.operation-item[data-status="success"] .operation-icon { color: var(--success); background: var(--success-soft); }
.operation-item[data-status="error"] .operation-icon { color: var(--danger); background: var(--danger-soft); }

.operation-copy strong,
.operation-copy span {
    display: block;
}

.operation-copy strong {
    color: #334155;
    font-size: 0.82rem;
}

.operation-copy span {
    margin-top: 0.2rem;
    color: var(--muted);
    font-size: 0.72rem;
    overflow-wrap: anywhere;
}

.operation-time {
    color: #94a3b8;
    font-size: 0.7rem;
    white-space: nowrap;
}

.api-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1.25rem;
}

.copy-field,
.secret-field {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 48px;
    padding: 0.55rem 0.65rem 0.55rem 0.85rem;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #f8fafc;
}

.copy-field code,
.secret-field code {
    min-width: 0;
    flex: 1;
    color: #334155;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.75rem;
    overflow-wrap: anywhere;
}

.secret-field code {
    max-height: 95px;
    overflow-y: auto;
}

.copy-button,
.code-copy {
    padding: 0.4rem 0.6rem;
    border: 0;
    border-radius: 8px;
    color: var(--primary);
    background: var(--primary-soft);
    font-size: 0.7rem;
    font-weight: 800;
}

.endpoint-list {
    display: grid;
    gap: 0.5rem;
    margin: 1.2rem 0;
}

.endpoint-list > div {
    display: grid;
    grid-template-columns: 54px minmax(130px, 0.7fr) minmax(0, 1fr);
    gap: 0.65rem;
    align-items: center;
    padding: 0.65rem;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.endpoint-list code {
    color: #334155;
    font-size: 0.74rem;
}

.endpoint-list small {
    color: var(--muted);
}

.method {
    padding: 0.22rem 0.35rem;
    border-radius: 6px;
    font-size: 0.62rem;
    font-weight: 900;
    text-align: center;
}

.method.get { color: #0369a1; background: #e0f2fe; }
.method.post { color: #166534; background: #dcfce7; }

.subheading {
    margin: 1.4rem 0 0.6rem;
    font-size: 0.86rem;
}

.code-block {
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    color: #dbeafe;
    background: #0f172a;
}

.code-block pre {
    margin: 0;
    padding: 1.1rem;
    overflow-x: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.7rem;
    line-height: 1.6;
}

.code-copy {
    position: absolute;
    top: 0.55rem;
    right: 0.55rem;
    color: #c7d2fe;
    background: rgba(99, 102, 241, 0.3);
}

.security-note {
    margin: 1rem 0 0;
    padding: 0.8rem 0.9rem;
    border-radius: 10px;
    color: #075985;
    background: var(--info-soft);
    font-size: 0.75rem;
    line-height: 1.5;
}

.security-note.warning {
    color: #92400e;
    background: var(--warning-soft);
}

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

.permission-grid label {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.7rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    cursor: pointer;
}

.permission-grid input {
    margin-top: 0.2rem;
    accent-color: var(--primary);
}

.permission-grid strong,
.permission-grid small {
    display: block;
}

.permission-grid strong { color: #334155; font-size: 0.76rem; }
.permission-grid small { margin-top: 0.15rem; color: var(--muted); font-size: 0.64rem; }

.token-list {
    display: grid;
}

.token-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 1rem;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--line);
}

.token-item:last-child { border-bottom: 0; }
.token-name { margin: 0; color: #334155; font-size: 0.86rem; font-weight: 850; }
.token-meta { margin: 0.3rem 0 0; color: var(--muted); font-size: 0.7rem; overflow-wrap: anywhere; }

.dialog {
    width: min(620px, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    padding: 0;
    border: 0;
    border-radius: 18px;
    background: transparent;
    box-shadow: 0 28px 80px rgba(15, 23, 42, 0.3);
}

.dialog.wide-dialog { width: min(820px, calc(100vw - 2rem)); }
.dialog::backdrop { background: rgba(15, 23, 42, 0.58); backdrop-filter: blur(4px); }

.dialog-panel {
    max-height: calc(100vh - 2rem);
    padding: 1.4rem;
    overflow-y: auto;
    border-radius: 18px;
    background: #fff;
}

.dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.2rem;
}

.dialog-header h2 { margin: 0; font-size: 1.25rem; letter-spacing: -0.03em; }
.dialog-close { width: 36px; height: 36px; border: 0; border-radius: 10px; color: #64748b; background: #f1f5f9; font-size: 1.25rem; }
.small-textarea { min-height: 95px; }

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

.detail-box {
    padding: 0.8rem;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #f8fafc;
}

.detail-box span,
.detail-box strong { display: block; }
.detail-box span { color: var(--muted); font-size: 0.68rem; }
.detail-box strong { margin-top: 0.25rem; color: #334155; font-size: 0.8rem; overflow-wrap: anywhere; }

.message-detail-content {
    margin: 1rem 0;
    padding: 1rem;
    border-radius: 12px;
    color: #334155;
    background: #f8fafc;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.timeline {
    display: grid;
    gap: 0.6rem;
    margin-top: 1rem;
}

.timeline-item {
    display: grid;
    grid-template-columns: 12px minmax(0, 1fr) auto;
    gap: 0.6rem;
    align-items: center;
    color: #475569;
    font-size: 0.76rem;
}

.timeline-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }

@media (max-width: 1180px) {
    .contacts-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .api-grid { grid-template-columns: 1fr; }
}

@media (max-width: 1080px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-grid,
    .compose-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

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

    .auth-visual {
        min-height: auto;
        padding: 2rem;
    }

    .auth-pitch {
        margin: 4rem 0 1.5rem;
    }

    .auth-pitch h1 {
        font-size: clamp(2rem, 8vw, 3.4rem);
    }

    .auth-feature-row {
        display: none;
    }

    .auth-panel {
        padding: 3rem 1.5rem;
    }

    .sidebar {
        transform: translateX(-105%);
        transition: transform 0.22s ease;
        box-shadow: 20px 0 50px rgba(15, 23, 42, 0.25);
    }

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

    .mobile-backdrop {
        position: fixed;
        z-index: 50;
        inset: 0;
        background: rgba(15, 23, 42, 0.5);
        backdrop-filter: blur(3px);
    }

    body.menu-open .mobile-backdrop {
        display: block;
    }

    .app-main {
        margin-left: 0;
    }

    .menu-toggle {
        display: grid;
    }
}

@media (max-width: 640px) {
    .topbar {
        height: 66px;
        padding: 0 1rem;
    }

    .top-connection,
    .topbar-actions .btn span {
        display: none;
    }

    .topbar-actions .btn {
        width: 42px;
        padding: 0;
    }

    .content {
        padding: 1rem;
    }

    .hero {
        display: block;
    }

    .hero-actions {
        margin-top: 1.2rem;
    }

    .hero .btn {
        width: 100%;
    }

    .stats-grid {
        gap: 0.7rem;
    }

    .stat-card {
        display: block;
        padding: 1rem;
    }

    .stat-icon {
        width: 38px;
        height: 38px;
        margin-bottom: 0.8rem;
    }

    .section-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .field-row {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .card-header,
    .card-body,
    .activity-item,
    .inbox-message {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .form-actions {
        align-items: stretch;
        flex-direction: column-reverse;
    }

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

    .csv-row {
        grid-template-columns: 28px minmax(0, 1fr);
    }

    .csv-message {
        grid-column: 2;
        white-space: normal;
    }

    .activity-head,
    .inbox-message-head {
        display: block;
    }

    .activity-time,
    .inbox-time {
        display: block;
        margin-top: 0.2rem;
    }

    .data-toolbar,
    .history-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .compact-field,
    .search-box {
        width: 100%;
    }

    .toolbar-summary {
        align-self: flex-start;
        margin-left: 0;
    }

    .contacts-grid {
        grid-template-columns: 1fr;
        padding: 0.85rem;
    }

    .data-table thead {
        display: none;
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100%;
    }

    .data-table tr {
        position: relative;
        padding: 0.85rem 1rem;
        border-bottom: 1px solid var(--line);
    }

    .data-table td {
        padding: 0.22rem 0;
        border: 0;
    }

    .data-table td:last-child {
        position: absolute;
        top: 0.75rem;
        right: 0.75rem;
    }

    .table-message {
        max-width: calc(100vw - 4rem);
    }

    .operation-item {
        grid-template-columns: 38px minmax(0, 1fr);
        padding: 0.85rem 1rem;
    }

    .operation-time {
        grid-column: 2;
    }

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

    .endpoint-list > div {
        grid-template-columns: 54px minmax(0, 1fr);
    }

    .endpoint-list small {
        grid-column: 2;
    }

    .token-item {
        grid-template-columns: 1fr auto;
        gap: 0.65rem;
    }

    .token-item .token-status {
        grid-column: 1;
    }

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

    .dialog-panel {
        padding: 1rem;
    }
}

@media (max-width: 390px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .auth-panel {
        padding: 2.5rem 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
