:root {
    --bg: #eef1f5;
    --box: #ffffff;
    --box2: #f5f6f8;
    --text: #172033;
    --muted: #687386;
    --line: #d7dde6;
    --accent: #2563eb;
    --danger: #dc2626;
    --ok: #15803d;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

button,
input,
textarea {
    font: inherit;
}

button {
    border: 1px solid var(--line);
    background: var(--box2);
    color: var(--text);
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 2px;
}

button:hover {
    background: #e9edf3;
}

button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

button.danger {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.app-shell {
    width: min(860px, calc(100vw - 32px));
    max-height: calc(100vh - 56px);
    background: var(--box);
    border: 1px solid var(--line);
    overflow: hidden;
}

.topbar {
    min-height: 58px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: var(--box);
}

.brand {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
}

.status {
    margin-top: 2px;
    font-size: 12px;
    color: var(--muted);
}

.top-action {
    margin: 0;
}

.top-action:first-of-type {
    margin-left: auto;
}

.tabs {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    border-bottom: 1px solid var(--line);
    background: var(--box2);
}

.tabs a {
    text-align: center;
    padding: 11px 8px;
    border-right: 1px solid var(--line);
    color: var(--muted);
}

.tabs a:last-child {
    border-right: 0;
}

.tabs a.active {
    background: var(--box);
    color: var(--text);
    font-weight: 600;
}

.notice {
    position: fixed;
    left: 50%;
    top: 18px;
    transform: translateX(-50%);
    z-index: 100;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: auto;
    min-width: 0;
    max-width: 80vw;

    padding: 8px 14px;

    border: 1px solid;
    font-size: 13px;
    font-weight: 500;

    text-align: center;
    white-space: nowrap;

    transition: opacity .25s ease;
}

.notice.ok {
    background: #dcfce7;
    border-color: #22c55e;
    color: #166534;
}

.notice.error {
    background: #fee2e2;
    border-color: #ef4444;
    color: #991b1b;
}

.sms-layout {
    display: grid;
    grid-template-columns: 235px 1fr;
    min-height: 390px;
    max-height: calc(100vh - 190px);
}

.sms-list {
    border-right: 1px solid var(--line);
    background: var(--box2);
    overflow-y: auto;
}

.sms-row {
    display: grid;
    grid-template-columns: 1fr 72px;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
}

.sms-row span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sms-row time {
    color: var(--muted);
    text-align: right;
    white-space: nowrap;
}

.sms-row:hover,
.sms-row.selected {
    background: var(--box);
}

.viewer {
    padding: 14px;
    min-width: 0;
    overflow-y: auto;
}

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

.viewer-phone {
    font-size: 18px;
    font-weight: 700;
}

.viewer-date {
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
}

.sms-text {
    margin: 0;
    padding: 12px;
    min-height: 220px;
    border: 1px solid var(--line);
    background: var(--box2);
    white-space: pre-wrap;
    word-break: break-word;
    font: inherit;
    font-size: 17px;
    line-height: 1.45;
}

.empty {
    padding: 14px;
    color: var(--muted);
    font-size: 14px;
}

.compose {
    padding: 16px;
}

label {
    display: block;
    margin: 0 0 5px;
    color: var(--muted);
    font-size: 14px;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    background: white;
    color: var(--text);
    padding: 9px 10px;
    margin-bottom: 12px;
    border-radius: 2px;
}

textarea {
    resize: vertical;
}

.counter {
    margin: -6px 0 12px;
    color: var(--muted);
    font-size: 13px;
}

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

.login-box {
    width: min(360px, 100%);
    background: var(--box);
    border: 1px solid var(--line);
    padding: 18px;
}

.login-box h1 {
    margin: 0 0 16px;
    font-size: 22px;
}

.login-box button {
    width: 100%;
}

.alert {
    margin-bottom: 12px;
    padding: 9px 10px;
    border: 1px solid var(--line);
    background: var(--box2);
    font-size: 14px;
}

.alert.error {
    border-color: #fecaca;
    color: var(--danger);
}

.idle-warning {
    position: fixed;
    right: 14px;
    bottom: 14px;
    z-index: 50;
    padding: 10px 12px;
    background: #111827;
    color: white;
    font-size: 14px;
}

@media (max-width: 760px) {
    body {
        display: block;
        min-height: 100vh;
        background: var(--box);
    }

    .app-shell {
        width: 100%;
        min-height: 100vh;
        max-height: none;
        border: 0;
        overflow: visible;
    }

    .topbar {
        align-items: flex-start;
        flex-wrap: wrap;
        padding: 9px;
    }

    .brand {
        font-size: 17px;
    }

    .status {
        max-width: 100%;
        font-size: 11px;
    }

    .top-action:first-of-type {
        margin-left: auto;
    }

    .top-action button {
        padding: 7px 9px;
        font-size: 13px;
    }

    .tabs a {
        padding: 10px 4px;
        font-size: 14px;
    }

    .sms-layout {
        display: block;
        min-height: 0;
        max-height: none;
    }

    .sms-list {
        border-right: 0;
        border-bottom: 1px solid var(--line);
        max-height: 230px;
    }

    .sms-row {
        grid-template-columns: 1fr 68px;
        padding: 10px;
    }

    .viewer {
        padding: 10px;
    }

    .viewer-head {
        align-items: stretch;
    }

    .viewer-phone {
        font-size: 17px;
    }

    .sms-text {
        min-height: 230px;
        font-size: 16px;
    }

    .compose {
        padding: 10px;
    }

    .login-page {
        padding: 0;
        background: var(--box);
    }

    .login-box {
        width: 100%;
        min-height: 100vh;
        border: 0;
        padding: 18px;
    }

    .notice {
        top: auto;
        bottom: 12px;

        left: 12px;
        right: 12px;
        transform: none;

        width: auto;
        max-width: none;
        min-width: 0;

        padding: 8px 12px;

        font-size: 13px;
        font-weight: 500;

        text-align: center;
    }
}