/* kezir-whatsapp admin panel */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}

:root {
    --bg: #111318;
    --surface: #1a1d24;
    --surface2: #23272f;
    --border: #2e333d;
    --text: #d4d4d8;
    --text-muted: #71717a;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --red: #ef4444;
    --orange: #f59e0b;
    --green: #22c55e;
    --blue: #3b82f6;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* ---- Top bar ---- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand {
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent);
    letter-spacing: -.02em;
}
.nav-links { display: flex; gap: 1rem; }
.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: .875rem;
    padding: .25rem .5rem;
    border-radius: 4px;
    transition: color .15s;
}
.nav-links a:hover, .nav-links a.active { color: var(--text); }
.nav-links a.active { background: var(--surface2); }

/* ---- Container ---- */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}
h2 { margin-bottom: 1.5rem; font-size: 1.25rem; font-weight: 600; }

/* ---- Card grid (home) ---- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
    text-decoration: none;
    color: var(--text);
    transition: border-color .15s;
}
.card:hover { border-color: var(--accent); }
.card h3 { font-size: 1rem; margin-bottom: .5rem; }
.card p { font-size: .8125rem; color: var(--text-muted); }

/* ---- Login ---- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 380px;
}
.login-card h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    text-align: center;
}
.subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: .8125rem;
    margin-bottom: 1.5rem;
}
.alert {
    padding: .625rem .75rem;
    border-radius: 6px;
    font-size: .8125rem;
    margin-bottom: 1rem;
}
.alert.error { background: rgba(239,68,68,.12); color: var(--red); border: 1px solid rgba(239,68,68,.25); }

label {
    display: block;
    font-size: .8125rem;
    color: var(--text-muted);
    margin-bottom: .25rem;
    margin-top: .75rem;
}
input[type="text"],
input[type="email"],
input[type="password"] {
    width: 100%;
    padding: .5rem .75rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: .875rem;
    outline: none;
    transition: border-color .15s;
}
input:focus { border-color: var(--accent); }

button[type="submit"] {
    width: 100%;
    margin-top: 1.25rem;
    padding: .625rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
button[type="submit"]:hover { background: var(--accent-hover); }

/* ---- Log viewer ---- */
.log-controls {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}
.log-form {
    display: flex;
    align-items: flex-end;
    gap: .75rem;
    flex-wrap: wrap;
}
.log-form label { margin: 0; }
.log-form select {
    padding: .4rem .5rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: .8125rem;
}
.entry-count { font-size: .8125rem; color: var(--text-muted); }
.muted { color: var(--text-muted); font-size: .875rem; }

.log-entries {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.log-entry {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .75rem 1rem;
    border-left: 3px solid var(--border);
}
.log-entry.level-error   { border-left-color: var(--red); }
.log-entry.level-warning { border-left-color: var(--orange); }
.log-entry.level-info    { border-left-color: var(--blue); }
.log-entry.level-debug   { border-left-color: var(--text-muted); }

.log-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    font-size: .75rem;
    margin-bottom: .25rem;
}
.log-level {
    font-weight: 700;
    font-size: .6875rem;
    text-transform: uppercase;
    padding: .1rem .4rem;
    border-radius: 3px;
}
.badge-error   { background: rgba(239,68,68,.15); color: var(--red); }
.badge-warning { background: rgba(245,158,11,.15); color: var(--orange); }
.badge-info    { background: rgba(59,130,246,.15); color: var(--blue); }
.badge-debug   { background: var(--surface2); color: var(--text-muted); }

.log-time { color: var(--text-muted); }
.log-endpoint { color: var(--text-muted); margin-left: auto; }
.log-message { font-size: .8125rem; }
.log-context {
    margin-top: .375rem;
    padding: .5rem .75rem;
    background: var(--surface2);
    border-radius: 4px;
    font-size: .75rem;
    color: var(--text-muted);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ---- Wide container (jobs) ---- */
.container-wide { max-width: 1200px; }

/* ---- Audit container (messages, conversation): full width ---- */
.container-audit {
    max-width: none;
    width: 100%;
    min-width: 0;
    padding-left: 1rem;
    padding-right: 1rem;
}

/* ---- Jobs table ---- */
.table-wrap { overflow-x: auto; }
.jobs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .8125rem;
}
.jobs-table th,
.jobs-table td {
    padding: .5rem .75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.jobs-table th {
    background: var(--surface);
    color: var(--text-muted);
    font-weight: 600;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    position: sticky;
    top: 0;
}
.jobs-table tbody tr:hover { background: var(--surface); }
.jobs-table .cell-payload,
.jobs-table .cell-result {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
    font-family: monospace;
    font-size: .75rem;
}

/* ---- Status badges ---- */
.status-badge {
    display: inline-block;
    font-weight: 700;
    font-size: .6875rem;
    text-transform: uppercase;
    padding: .15rem .45rem;
    border-radius: 3px;
}
.status-pending    { background: rgba(59,130,246,.15);  color: var(--blue); }
.status-processing { background: rgba(245,158,11,.15);  color: var(--orange); }
.status-completed  { background: rgba(34,197,94,.15);   color: var(--green); }
.status-failed     { background: rgba(239,68,68,.15);   color: var(--red); }
.status-active     { background: rgba(34,197,94,.15);   color: var(--green); }
.status-inactive   { background: rgba(113,113,122,.2);  color: var(--text-muted); }

/* ---- Edit link ---- */
.edit-link {
    font-size: .8125rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: color .15s;
}
.edit-link:hover { color: var(--accent); }

/* ---- Edit form ---- */
.form-group {
    display: flex;
    flex-direction: column;
    margin-bottom: .25rem;
}
.form-group label { margin-top: .75rem; margin-bottom: .25rem; }
.form-group select {
    padding: .5rem .75rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: .875rem;
    outline: none;
    transition: border-color .15s;
    max-width: 280px;
}
.form-group select:focus { border-color: var(--accent); }
.form-group input[type="datetime-local"] {
    max-width: 280px;
}
textarea {
    width: 100%;
    padding: .5rem .75rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: .8125rem;
    font-family: monospace;
    outline: none;
    resize: vertical;
    transition: border-color .15s;
}
textarea:focus { border-color: var(--accent); }

/* ---- Alert success ---- */
.alert.success { background: rgba(34,197,94,.12); color: var(--green); border: 1px solid rgba(34,197,94,.25); }

/* ---- Pagination ---- */
.pagination {
    display: flex;
    gap: .375rem;
    margin-top: 1.25rem;
    justify-content: center;
}
.pagination a {
    display: inline-block;
    padding: .35rem .7rem;
    font-size: .8125rem;
    color: var(--text-muted);
    text-decoration: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    transition: border-color .15s, color .15s;
}
.pagination a:hover { border-color: var(--accent); color: var(--text); }
.pagination a.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ---- Agents: buttons and inline forms ---- */
.btn-primary {
    display: inline-block;
    padding: .4rem .75rem;
    font-size: .8125rem;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border: none;
    border-radius: 6px;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s;
}
.btn-primary:hover { background: var(--accent-hover); }

.form-inline { display: inline; }
.form-inline button { margin-left: .5rem; }
.btn-link {
    font-size: .8125rem;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    text-decoration: none;
    transition: color .15s;
}
.btn-link:hover { color: var(--accent); }
.btn-link.btn-danger:hover { color: var(--red); }
.cell-actions { white-space: nowrap; }
.cell-actions .edit-link { margin-right: .25rem; }

/* ---- Messages (audit): tabs ---- */
.messages-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}
.messages-tab {
    padding: .5rem 1rem;
    font-size: .875rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color .15s, border-color .15s;
}
.messages-tab:hover { color: var(--text); }
.messages-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ---- Messages: filters ---- */
.messages-filters {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}
.messages-filters-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: .75rem;
}
.messages-filters-row:last-child { margin-bottom: 0; }
.form-group-inline { margin-bottom: 0; }
.form-group-inline label { margin-top: 0; }
.form-group-inline input[type="text"],
.form-group-inline input[type="date"],
.form-group-inline select {
    min-width: 120px;
    max-width: 180px;
}
.messages-summary {
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}

/* ---- Messages table: full width for auditing ---- */
.messages-table {
    table-layout: auto;
    width: 100%;
}
.messages-table th,
.messages-table td {
    white-space: normal;
}
.messages-table .cell-preview {
    max-width: none;
    min-width: 280px;
    width: 28%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .8125rem;
    color: var(--text);
}
.cell-monospace { font-family: ui-monospace, monospace; font-size: .8125rem; }

/* Outbound message status badges (SENT, DELIVERED) */
.status-sent      { background: rgba(34,197,94,.15);  color: var(--green); }
.status-delivered { background: rgba(34,197,94,.2);   color: var(--green); }

/* Queue type badges (fast / slow) on messages list */
.queue-badge {
    display: inline-block;
    font-size: .6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: .2rem .45rem;
    border-radius: 4px;
}
.queue-fast { background: rgba(34, 197, 94, 0.2);  color: #4ade80; border: 1px solid rgba(34, 197, 94, 0.35); }
.queue-slow { background: rgba(59, 130, 246, 0.2); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.35); }

/* ---- Message detail (single message audit) ---- */
.message-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}
.message-detail-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
}
.message-detail-section h3 {
    font-size: .875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
    margin-bottom: .75rem;
    padding-bottom: .375rem;
    border-bottom: 1px solid var(--border);
}
.message-detail-dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: .25rem .75rem;
    font-size: .8125rem;
}
.message-detail-dl dt {
    color: var(--text-muted);
    font-weight: 500;
}
.message-detail-dl dd {
    margin: 0;
    word-break: break-all;
}
.message-detail-content { grid-column: 1 / -1; }
.message-detail-json {
    margin: 0;
    padding: 1rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .75rem;
    font-family: ui-monospace, monospace;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 400px;
    overflow-y: auto;
}

/* ---- Conversation: chat-by-phone form ---- */
.conversation-form {
    display: flex;
    align-items: flex-end;
    gap: .75rem;
    margin-bottom: 1.25rem;
}
.conversation-form input[type="text"] {
    width: auto;
    min-width: 200px;
}

/* ---- Chat UI: header and legend ---- */
.chat-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.chat-header-left {
    display: flex;
    align-items: baseline;
    gap: .75rem;
}
.chat-peer {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    letter-spacing: -.02em;
}
.chat-count {
    font-size: .8125rem;
    color: var(--text-muted);
}
.chat-header-legend {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}
.chat-legend-item {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: .25rem .5rem;
    border-radius: 6px;
}
.chat-legend-them {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
    border: 1px solid rgba(59, 130, 246, 0.4);
}
.chat-legend-us {
    background: rgba(34, 197, 94, 0.2);
    color: #86efac;
    border: 1px solid rgba(34, 197, 94, 0.4);
}

/* ---- Chat thread: two clear sides ---- */
.chat-thread {
    display: flex;
    flex-direction: column;
    gap: .75rem;
    max-width: 680px;
    margin: 0 auto;
    padding: 1rem 0;
}

.chat-message {
    width: 100%;
    clear: both;
}
.chat-message-inner {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 85%;
}
.chat-message-us .chat-message-inner {
    align-items: flex-end;
    margin-left: auto;
}

.chat-sender-label {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: .25rem;
    padding: 0 .15rem;
}
.chat-message-them .chat-sender-label {
    color: #60a5fa;
}
.chat-message-us .chat-sender-label {
    color: #4ade80;
}

.chat-bubble {
    width: 100%;
    min-width: 120px;
    max-width: 100%;
    padding: .75rem 1rem;
    border-radius: 14px;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    transition: box-shadow 0.15s ease;
}
.chat-bubble:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.chat-message-them .chat-bubble {
    background: linear-gradient(145deg, #252830 0%, #1e2128 100%);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-bottom-left-radius: 4px;
    color: #e2e8f0;
}
.chat-message-us .chat-bubble {
    background: linear-gradient(145deg, #166534 0%, #14532d 100%);
    border: 1px solid rgba(74, 222, 128, 0.3);
    border-bottom-right-radius: 4px;
    color: #f0fdf4;
}

/* UNSEND: faded, dashed, clearly "removed" */
.chat-bubble--unsend {
    background: var(--surface2) !important;
    border: 1px dashed var(--border) !important;
    opacity: 0.88;
}
.chat-bubble--unsend .chat-body {
    text-decoration: line-through;
    color: var(--text-muted) !important;
}
.chat-unsend-badge {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--orange);
    margin-bottom: .35rem;
    padding-bottom: .35rem;
    border-bottom: 1px solid var(--border);
}

/* Poll (we sent) */
.chat-poll-badge {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    opacity: 0.9;
    margin-bottom: .35rem;
}
.chat-message-them .chat-poll-badge { color: #93c5fd; }
.chat-message-us .chat-poll-badge { color: #bbf7d0; }

/* Vote (they voted) - only on their side */
.chat-bubble--vote {
    border-left: 3px solid #60a5fa;
}
.chat-vote-badge {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #60a5fa;
    margin-bottom: .35rem;
}

.chat-body {
    font-size: .9375rem;
    line-height: 1.5;
    white-space: pre-wrap;
}
.chat-body--faded {
    opacity: 0.8;
    font-style: italic;
}
.chat-message-us .chat-body {
    color: #f0fdf4;
}

.chat-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem;
    margin-top: .5rem;
    padding-top: .45rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    font-size: .7rem;
}
.chat-message-them .chat-footer {
    border-top-color: rgba(59, 130, 246, 0.2);
}
.chat-time {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.chat-message-us .chat-time {
    color: rgba(255, 255, 255, 0.8);
}
.chat-type {
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    font-size: .65rem;
}
.chat-message-us .chat-type {
    color: rgba(255, 255, 255, 0.75);
}
.chat-meta {
    color: var(--text-muted);
    font-size: .65rem;
}
.chat-message-us .chat-meta {
    color: rgba(255, 255, 255, 0.7);
}
.chat-detail-link {
    margin-left: auto;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
    font-size: .7rem;
}
.chat-message-us .chat-detail-link {
    color: rgba(255, 255, 255, 0.9);
}
.chat-detail-link:hover {
    text-decoration: underline;
}
