:root {
    --green: #2d6a2d;
    --green-light: #3f8f3f;
    --bg: #121212;
    --bg-card: #1a1a1a;
    --border: #2a2a2a;
    --text: #e8e8e8;
    --text-dim: #9a9a9a;
    --amber: #b8860b;
    --red: #a33;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a {
    color: var(--green-light);
}

button {
    background: var(--green);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    cursor: pointer;
}

button:hover {
    background: var(--green-light);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Login */

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

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 2rem;
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-card h1 {
    margin: 0;
    color: var(--green-light);
}

.login-card .subtitle {
    margin: 0;
    color: var(--text-dim);
    font-size: 0.9rem;
}

.login-card label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
}

.login-card input {
    background: #0e0e0e;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem;
    color: var(--text);
    font-size: 1rem;
}

.alert {
    background: rgba(170, 51, 51, 0.2);
    border: 1px solid var(--red);
    color: #ff9a9a;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
}

/* Layout */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.topbar h1 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--green-light);
}

.logout-link {
    text-decoration: none;
    font-size: 0.9rem;
}

main {
    padding: 1rem;
    max-width: 960px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
}

section h2 {
    margin: 0 0 0.75rem;
    font-size: 1.05rem;
}

.hint {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin: 0 0 0.75rem;
}

/* Status panel */

.status-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    background: none;
    border: none;
    padding: 0;
}

.status-card {
    flex: 1 1 220px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.status-label {
    color: var(--text-dim);
    font-size: 0.85rem;
    flex: 1 1 100%;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.badge-online {
    background: rgba(45, 106, 45, 0.3);
    color: #7ee07e;
}

.badge-stopped {
    background: rgba(170, 51, 51, 0.25);
    color: #ff9a9a;
}

.badge-unknown {
    background: rgba(184, 134, 11, 0.25);
    color: #f0c674;
}

.wa-phone {
    color: var(--text-dim);
    font-size: 0.9rem;
}

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

button.danger-btn:hover {
    background: #c44;
}

/* QR */

.qr-section {
    text-align: center;
}

.qr-section[hidden] {
    display: none;
}

#qr-canvas {
    display: inline-block;
    background: #fff;
    padding: 0.75rem;
    border-radius: 8px;
}

/* Context */

.context-add-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.context-add-form textarea {
    width: 100%;
    background: #0e0e0e;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem;
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
}

.context-add-form button {
    align-self: flex-end;
}

.context-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.context-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.context-item-inactive {
    opacity: 0.5;
}

.context-item-inactive .context-text {
    text-decoration: line-through;
}

.context-text {
    flex: 1;
    word-break: break-word;
}

.context-date {
    color: var(--text-dim);
    font-size: 0.78rem;
    white-space: nowrap;
}

.context-actions {
    display: flex;
    gap: 0.4rem;
    flex: 0 0 auto;
}

.context-actions button {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

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

button.secondary-btn:hover {
    background: #3a3a3a;
}

.context-edit-textarea {
    flex: 1;
    width: 100%;
    background: #0e0e0e;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem 0.6rem;
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
}

.context-empty {
    color: var(--text-dim);
    text-align: center;
    padding: 0.5rem;
}

/* Conversations table */

.table-wrap {
    overflow-x: auto;
}

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

th, td {
    text-align: left;
    padding: 0.5rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

th {
    color: var(--text-dim);
    font-weight: 500;
    font-size: 0.8rem;
    text-transform: uppercase;
}

.msg-cell {
    max-width: 280px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.empty-row {
    text-align: center;
    color: var(--text-dim);
}

.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 0.75rem;
}

.pager span {
    color: var(--text-dim);
    font-size: 0.85rem;
}

.status-badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.78rem;
}

.status-activo {
    background: rgba(45, 106, 45, 0.3);
    color: #7ee07e;
}

.status-pausado {
    background: rgba(184, 134, 11, 0.25);
    color: #f0c674;
}

.status-escalado {
    background: rgba(170, 51, 51, 0.25);
    color: #ff9a9a;
}

/* Mobile: conversations become stacked cards */

@media (max-width: 640px) {
    table, thead, tbody, th, td, tr {
        display: block;
    }

    thead {
        display: none;
    }

    tbody tr {
        border: 1px solid var(--border);
        border-radius: 8px;
        margin-bottom: 0.6rem;
        padding: 0.4rem 0.6rem;
    }

    td {
        border-bottom: none;
        padding: 0.3rem 0;
        display: flex;
        justify-content: space-between;
        gap: 0.5rem;
    }

    td[data-label]::before {
        content: attr(data-label);
        color: var(--text-dim);
        font-size: 0.78rem;
        flex: 0 0 auto;
    }

    .msg-cell {
        max-width: 60%;
    }
}
