:root {
    --bg-start: #f7fbff;
    --bg-mid: #eef8f3;
    --bg-end: #fff7ed;
    --surface: rgba(255, 255, 255, 0.72);
    --surface-strong: rgba(255, 255, 255, 0.92);
    --surface-soft: rgba(255, 255, 255, 0.52);
    --border: rgba(138, 155, 172, 0.28);
    --border-strong: rgba(97, 116, 136, 0.34);
    --text: #121c2a;
    --muted: #66788b;
    --primary: #0f7f72;
    --primary-hover: #0b685f;
    --secondary: #2467c9;
    --secondary-hover: #1d55a6;
    --danger: #c43d32;
    --danger-hover: #9f2e25;
    --bubble: rgba(255, 255, 255, 0.96);
    --bubble-border: rgba(170, 188, 204, 0.42);
    --pill: rgba(232, 242, 255, 0.92);
    --success-bg: rgba(224, 247, 235, 0.84);
    --success-text: #116846;
    --error-bg: rgba(255, 232, 232, 0.86);
    --error-text: #982323;
    --shadow-soft: 0 20px 70px rgba(29, 45, 68, 0.14);
    --shadow-tight: 0 10px 28px rgba(30, 45, 66, 0.11);
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    background:
        linear-gradient(135deg, var(--bg-start) 0%, var(--bg-mid) 48%, var(--bg-end) 100%);
    color: var(--text);
    font-family: "SF Pro Text", "SF Pro Display", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", ui-sans-serif, sans-serif;
    font-size: 15px;
    font-weight: 400;
    line-height: 1.45;
}

a {
    color: inherit;
}

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

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.74);
    color: var(--text);
    font-weight: 400;
    padding: 9px 11px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: 3px solid rgba(15, 127, 114, 0.18);
    border-color: rgba(15, 127, 114, 0.62);
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 500;
}

code {
    display: inline-block;
    max-width: 100%;
    overflow-wrap: anywhere;
    padding: 2px 5px;
    border-radius: 5px;
    background: rgba(238, 244, 249, 0.9);
    color: var(--text);
    font-size: 0.9em;
}

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    color: var(--text);
    background: rgba(249, 252, 255, 0.72);
    border-bottom: 1px solid rgba(141, 160, 178, 0.24);
    box-shadow: 0 10px 32px rgba(25, 42, 62, 0.08);
    backdrop-filter: blur(22px);
}

.topbar__inner {
    width: min(1120px, calc(100% - 28px));
    min-height: 66px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 22px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.brand::before {
    content: "";
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 5px rgba(15, 127, 114, 0.12);
}

.nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav a {
    padding: 8px 11px;
    border-radius: 8px;
    color: #39485a;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
}

.nav a:hover {
    background: rgba(255, 255, 255, 0.8);
}

.session {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.session form {
    margin: 0;
}

.session__user {
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 450;
}

.main {
    width: min(1120px, calc(100% - 28px));
    margin: 0 auto;
    padding: 28px 0 44px;
    flex: 1;
}

.footer {
    padding: 18px 14px;
    color: var(--muted);
    text-align: center;
}

.page-heading,
.inbox-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.page-heading h1,
.inbox-hero h1,
.auth-panel h1,
.admin-panel h2,
.user-card h2,
.danger-panel h2,
.empty-state h2 {
    margin: 0;
    letter-spacing: 0;
    font-weight: 560;
}

.page-heading h1,
.inbox-hero h1 {
    font-size: clamp(1.45rem, 3vw, 2rem);
    font-weight: 560;
    line-height: 1.02;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--primary);
    font-size: 0.72rem;
    font-weight: 500;
    text-transform: uppercase;
}

.muted {
    margin: 4px 0 0;
    color: var(--muted);
}

.hero-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.count-pill {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 8px 13px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.68);
    color: #385066;
    font-size: 0.92rem;
    font-weight: 500;
    box-shadow: 0 8px 22px rgba(40, 57, 78, 0.08);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: #ffffff;
    background: var(--secondary);
    cursor: pointer;
    font-size: 0.92rem;
    font-weight: 500;
    line-height: 1.1;
    text-decoration: none;
    white-space: nowrap;
    box-shadow: 0 9px 22px rgba(36, 103, 201, 0.17);
}

.button:hover {
    filter: brightness(0.98);
}

.button--primary {
    background: var(--primary);
    box-shadow: 0 9px 22px rgba(15, 127, 114, 0.18);
}

.button--primary:hover {
    background: var(--primary-hover);
}

.button--secondary {
    background: var(--secondary);
}

.button--secondary:hover {
    background: var(--secondary-hover);
}

.button--danger {
    background: var(--danger);
    box-shadow: 0 9px 22px rgba(196, 61, 50, 0.16);
}

.button--danger:hover {
    background: var(--danger-hover);
}

.button--ghost {
    border-color: var(--border-strong);
    background: rgba(255, 255, 255, 0.72);
    color: var(--text);
    box-shadow: none;
}

.button--small {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 0.8rem;
}

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

.flash {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    backdrop-filter: blur(12px);
}

.flash--success {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: rgba(93, 177, 128, 0.32);
}

.flash--error {
    background: var(--error-bg);
    color: var(--error-text);
    border-color: rgba(223, 124, 124, 0.34);
}

.auth-layout {
    min-height: calc(100vh - 180px);
    display: grid;
    place-items: center;
}

.auth-panel,
.filter-panel,
.danger-panel,
.admin-panel,
.user-card,
.empty-state {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(24px);
}

.auth-panel {
    width: min(420px, 100%);
    padding: 24px;
}

.setup-note {
    margin: 18px 0;
    padding: 12px;
    border-left: 4px solid var(--secondary);
    border-radius: 0 8px 8px 0;
    background: rgba(235, 243, 255, 0.82);
    color: var(--text);
    font-size: 0.88rem;
}

.form-stack {
    display: grid;
    gap: 14px;
    margin-top: 18px;
}

.form-row {
    display: flex;
    align-items: end;
    gap: 10px;
    margin-top: 16px;
}

.form-row input {
    flex: 1 1 auto;
}

.filter-panel {
    padding: 12px;
}

.danger-panel {
    padding: 24px;
}

.danger-panel p {
    margin: 14px 0 0;
}

.filters {
    display: grid;
    gap: 0;
}

.search-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) max-content;
    gap: 10px;
    align-items: end;
}

.advanced-filters {
    display: grid;
    grid-template-columns:
        minmax(112px, 0.85fr)
        minmax(130px, 0.95fr)
        minmax(152px, 1fr)
        minmax(152px, 1fr)
        minmax(120px, 0.9fr);
    gap: 11px;
    max-height: 0;
    margin-top: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-4px);
    visibility: hidden;
    transition:
        max-height 180ms ease,
        margin-top 180ms ease,
        opacity 160ms ease,
        transform 180ms ease,
        visibility 0ms linear 180ms;
}

.filter-panel:hover .advanced-filters,
.filter-panel:focus-within .advanced-filters,
.filter-panel--expanded .advanced-filters {
    max-height: 160px;
    margin-top: 12px;
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
    visibility: visible;
    transition-delay: 0ms;
}

.filter-field {
    min-width: 0;
}

.filter-field--wide {
    min-width: 0;
}

.filter-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.filter-actions .button {
    min-width: 90px;
}

.chat-window {
    margin-top: 18px;
    overflow: hidden;
    border: 1px solid rgba(134, 153, 171, 0.28);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.54);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(26px);
}

.chat-feed {
    display: grid;
    gap: 18px;
    padding: 42px 22px 22px;
}

.chat-message {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 10px;
    align-items: end;
    max-width: 900px;
}

.sender-avatar {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.82);
    border-radius: 50%;
    background: linear-gradient(145deg, #1a7f77, #2b6bd8);
    color: #ffffff;
    font-size: 0.76rem;
    font-weight: 500;
    box-shadow: 0 10px 22px rgba(35, 83, 130, 0.24);
}

.bubble-cluster {
    min-width: 0;
}

.bubble-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 5px 6px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 450;
    flex-wrap: wrap;
}

.sender-number {
    color: #334b63;
    overflow-wrap: anywhere;
}

.chat-bubble {
    width: fit-content;
    max-width: min(760px, 100%);
    min-width: min(260px, 100%);
    padding: 13px 14px 12px;
    border: 1px solid var(--bubble-border);
    border-radius: 22px 22px 22px 7px;
    background: var(--bubble);
    box-shadow: var(--shadow-tight);
}

.sms-text {
    margin: 0;
    color: var(--text);
    font-size: 0.94rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.bubble-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.recipient-pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    max-width: 100%;
    padding: 5px 9px;
    border: 1px solid rgba(92, 143, 208, 0.24);
    border-radius: 999px;
    background: var(--pill);
    color: #315d91;
    font-size: 0.74rem;
    font-weight: 500;
    overflow-wrap: anywhere;
}

.copy-button {
    min-height: 30px;
    padding: 5px 10px;
    border: 1px solid rgba(15, 127, 114, 0.22);
    border-radius: 999px;
    background: rgba(235, 250, 247, 0.88);
    color: var(--primary);
    cursor: pointer;
    font-size: 0.76rem;
    font-weight: 500;
}

.copy-button:hover {
    background: rgba(213, 245, 238, 0.96);
}

.empty-state {
    margin-top: 18px;
    padding: 34px 18px;
    text-align: center;
}

.empty-phone {
    width: 74px;
    height: 112px;
    margin: 0 auto 18px;
    padding: 8px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.72);
}

.empty-phone__screen {
    height: 100%;
    display: grid;
    align-content: center;
    gap: 8px;
    padding: 10px;
    border-radius: 6px;
    background: rgba(238, 246, 252, 0.88);
}

.empty-phone__screen div {
    height: 10px;
    border-radius: 999px;
    background: rgba(36, 103, 201, 0.28);
}

.empty-phone__screen div:nth-child(2) {
    width: 78%;
    margin-left: auto;
    background: rgba(15, 127, 114, 0.3);
}

.empty-phone__screen div:nth-child(3) {
    width: 62%;
}

.admin-grid {
    display: grid;
    grid-template-columns: minmax(280px, 360px) 1fr;
    gap: 16px;
    align-items: start;
}

.admin-panel,
.user-card {
    padding: 16px;
}

.user-list {
    display: grid;
    gap: 14px;
}

.user-card__header {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 12px;
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

.checkbox-field input {
    width: auto;
    min-height: auto;
}

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

@media (max-width: 980px) {
    .topbar__inner {
        flex-wrap: wrap;
        gap: 10px;
        padding: 12px 0;
    }

    .session {
        width: 100%;
        margin-left: 0;
        justify-content: space-between;
    }

    .advanced-filters,
    .admin-grid {
        grid-template-columns: 1fr;
    }

    .filter-panel:hover .advanced-filters,
    .filter-panel:focus-within .advanced-filters,
    .filter-panel--expanded .advanced-filters {
        max-height: 540px;
    }

    .filter-actions,
    .form-row {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .filter-actions .button,
    .form-row .button {
        flex: 1 1 130px;
    }
}

@media (max-width: 640px) {
    .main {
        width: min(100% - 20px, 1120px);
    }

    .topbar__inner {
        width: min(100% - 20px, 1120px);
        min-height: auto;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 10px 12px;
        padding: 10px 0 12px;
    }

    .brand {
        min-width: 0;
        font-size: 0.94rem;
    }

    .brand::before {
        width: 10px;
        height: 10px;
        box-shadow: 0 0 0 4px rgba(15, 127, 114, 0.12);
    }

    .session {
        width: auto;
        grid-column: 2;
        grid-row: 1;
        justify-content: end;
        gap: 0;
    }

    .session__user {
        display: none;
    }

    .session .button {
        width: auto;
        min-height: 34px;
        padding: 7px 10px;
        border-radius: 999px;
        font-size: 0.82rem;
    }

    .main {
        padding-top: 20px;
    }

    .page-heading,
    .inbox-hero,
    .user-card__header {
        align-items: stretch;
        flex-direction: column;
    }

    .hero-actions {
        justify-content: stretch;
    }

    .nav {
        grid-column: 1 / -1;
        width: 100%;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 4px;
        padding: 4px;
        border: 1px solid var(--border);
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.62);
    }

    .nav a {
        padding: 7px 8px;
        border-radius: 999px;
        text-align: center;
        font-size: 0.82rem;
    }

    .button {
        width: 100%;
    }

    .search-row {
        grid-template-columns: 1fr;
    }

    .filter-actions {
        justify-content: stretch;
    }

    .count-pill {
        justify-content: center;
        width: 100%;
        border-radius: 8px;
    }

    .chat-feed {
        padding: 30px 14px 14px;
        gap: 16px;
    }

    .chat-message {
        grid-template-columns: 34px minmax(0, 1fr);
        gap: 8px;
    }

    .sender-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.68rem;
    }

    .chat-bubble {
        min-width: 0;
        width: 100%;
        border-radius: 18px 18px 18px 7px;
    }

    .bubble-meta {
        margin-left: 4px;
        gap: 6px;
    }

    .bubble-footer {
        align-items: stretch;
    }

    .recipient-pill,
    .copy-button {
        justify-content: center;
        width: 100%;
    }
}
