/* Minimal, terminal-ish admin skin. One CSS file for everything. */

:root {
    color-scheme: light dark;
    --bg: #0f1114;
    --panel: #171a1f;
    --panel-2: #1e2229;
    --border: #2a2f38;
    --text: #e7e9ee;
    --muted: #8a92a1;
    --accent: #ff8a1d;
    --accent-fg: #0f1114;
    --danger: #ff5a5f;
    --sent: #2b2f38;
    --received: #23272f;
    font: 16px/1.4 system-ui, -apple-system, "SF Pro Text", sans-serif;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f7f7f8;
        --panel: #ffffff;
        --panel-2: #f0f1f4;
        --border: #dfe1e6;
        --text: #131519;
        --muted: #5f6675;
        --sent: #ffe4c8;
        --received: #eef0f4;
    }
}

* {
    box-sizing: border-box;
}
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}
a {
    color: inherit;
}
button {
    font: inherit;
    color: inherit;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
}
button:hover {
    background: var(--panel-2);
}
input,
textarea {
    font: inherit;
    color: inherit;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    width: 100%;
}
textarea {
    resize: vertical;
    min-height: 44px;
}

.loader {
    min-height: 100vh;
    display: grid;
    place-items: center;
    color: var(--muted);
}

/* Top bar shared by inbox + stats */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
}
.topbar h1 {
    margin: 0;
    font-size: 18px;
}
.topbar nav {
    display: flex;
    gap: 8px;
    align-items: center;
}
.topbar nav a {
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 8px;
    color: var(--muted);
}
.topbar nav a.active {
    color: var(--text);
    background: var(--panel-2);
}
.topbar nav button {
    margin-left: 8px;
}

/* Login */
.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}
.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    display: grid;
    gap: 16px;
}
.login-card h1 {
    margin: 0;
    font-size: 20px;
}
.login-card label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 14px;
}
.login-card button {
    background: var(--accent);
    color: var(--accent-fg);
    border-color: transparent;
    font-weight: 600;
}
.error {
    color: var(--danger);
    margin: 0;
    font-size: 14px;
}

/* Inbox */
.inbox {
    display: grid;
    grid-template-columns: minmax(280px, 340px) 1fr;
    height: calc(100vh - 57px);
}
/* Back button lives in the conversation header; only visible on mobile. */
.back-btn {
    display: none;
    background: transparent;
    border: 0;
    padding: 6px 10px;
    margin-right: 4px;
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    border-radius: 8px;
}
.back-btn:hover {
    background: var(--panel-2);
}
@media (max-width: 720px) {
    .inbox {
        grid-template-columns: 1fr;
    }
    /* Mobile default: show the list, hide the view. */
    .conversation-list {
        display: block;
    }
    .conversation-view {
        display: none;
    }
    /* When a conversation is open (`.viewing` on the parent), swap. */
    .inbox.viewing .conversation-list {
        display: none;
    }
    .inbox.viewing .conversation-view {
        display: flex;
    }
    .back-btn {
        display: inline-flex;
        align-items: center;
    }
}
.conversation-list {
    border-right: 1px solid var(--border);
    overflow-y: auto;
    background: var(--panel);
}
.hint {
    color: var(--muted);
    padding: 20px;
    text-align: center;
}
.conversation-item {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 4px 12px;
    padding: 12px 16px;
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    text-align: left;
    width: 100%;
    position: relative;
}
.conversation-item.active {
    background: var(--panel-2);
}
.conversation-item .who {
    font-weight: 600;
    grid-column: 1;
    grid-row: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.conversation-item .stamp {
    color: var(--muted);
    font-size: 12px;
    grid-column: 2;
    grid-row: 1;
}
.conversation-item .preview {
    color: var(--muted);
    font-size: 14px;
    grid-column: 1 / span 2;
    grid-row: 2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.conversation-item .unread-dot {
    position: absolute;
    right: 8px;
    top: 8px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
}

.conversation-view {
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.conversation-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
    display: grid;
    gap: 10px;
}
.conversation-header .user-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.conversation-header .user-name {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}
.sub-badge {
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--muted);
    text-transform: capitalize;
    white-space: nowrap;
}
.sub-badge.active {
    background: rgba(52, 199, 89, 0.15);
    border-color: rgba(52, 199, 89, 0.3);
    color: #34c759;
}
.sub-badge.expired {
    background: rgba(255, 90, 95, 0.15);
    border-color: rgba(255, 90, 95, 0.3);
    color: var(--danger);
}
.sub-badge.free,
.sub-badge.other {
    background: var(--panel-2);
}
.sub-badge.loading {
    opacity: 0.5;
}

.user-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 6px 16px;
    font-size: 12px;
}
.user-meta-grid.loading {
    opacity: 0.6;
}
.user-meta-grid .meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.user-meta-grid .meta .k {
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 10px;
}
.user-meta-grid .meta .v {
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.user-meta-grid .meta.warn .v {
    color: var(--danger);
}

.user-details > summary {
    list-style: none;
    cursor: pointer;
    color: var(--muted);
    font-size: 12px;
    padding: 4px 0;
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.user-details[open] > .user-meta-grid {
    margin-top: 6px;
}
.user-details > summary::-webkit-details-marker {
    display: none;
}
.user-details > summary::before {
    content: "▸";
    display: inline-block;
    font-size: 10px;
    transition: transform 0.15s ease;
}
.user-details[open] > summary::before {
    transform: rotate(90deg);
}
/* On desktop the summary disappears — the meta grid is always open. */
@media (min-width: 721px) {
    .user-details > summary {
        display: none;
    }
}
.msg-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.msg {
    display: flex;
}
.msg.sent {
    justify-content: flex-end;
}
.msg-bubble {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 14px;
    display: grid;
    gap: 4px;
}
.msg.received .msg-bubble {
    background: var(--received);
}
.msg.sent .msg-bubble {
    background: var(--sent);
}
.msg-stamp {
    color: var(--muted);
    font-size: 11px;
    text-align: right;
}
.composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: var(--panel);
}
.composer button {
    background: var(--accent);
    color: var(--accent-fg);
    border-color: transparent;
    font-weight: 600;
}

/* Stats */
.stats {
    padding: 24px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}
.tile {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    display: grid;
    gap: 6px;
}
.tile .label {
    color: var(--muted);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.tile .value {
    font-size: 28px;
    font-weight: 700;
}
.tile .sub {
    color: var(--muted);
    font-size: 13px;
}
