@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@300;400;500;600&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:           #0e0f11;
    --surface:      #16181c;
    --surface2:     #1e2026;
    --border:       #2a2d35;
    --text:         #e8eaf0;
    --text-muted:   #6b7280;
    --accent:       #c9963a;
    --accent-dim:   rgba(201,150,58,0.12);
    --accent-border:rgba(201,150,58,0.3);
    --green:        #4ade80;
    --green-dim:    rgba(74,222,128,0.1);
    --green-border: rgba(74,222,128,0.3);
    --red:          #f87171;
    --red-dim:      rgba(248,113,113,0.1);
    --red-border:   rgba(248,113,113,0.3);
    --blue:         #60a5fa;
    --radius:       8px;
    --sidebar-w:    310px;
}

html, body { height: 100%; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

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

/* ── Login ──────────────────────────────────────────────────────────────── */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.login-wrap {
    width: 100%;
    max-width: 420px;
    padding: 24px;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 36px 32px;
}

.login-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 22px;
    font-weight: 500;
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 28px;
}

.login-form { display: flex; flex-direction: column; gap: 18px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.help-link {
    font-size: 11px;
    color: var(--accent);
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
}
.help-link:hover { text-decoration: underline; }

.input-row {
    display: flex;
    align-items: center;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.15s;
}
.input-row:focus-within { border-color: var(--accent); }
.input-row input { flex: 1; border: none; background: transparent; }

.input-suffix {
    padding: 0 12px;
    color: var(--text-muted);
    font-size: 13px;
    white-space: nowrap;
    border-left: 1px solid var(--border);
    height: 100%;
    display: flex;
    align-items: center;
}

input[type="text"],
input[type="email"],
input[type="password"] {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 14px;
    padding: 10px 12px;
    transition: border-color 0.15s;
    outline: none;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-muted); }

.btn-full { width: 100%; justify-content: center; }

/* ── App layout ─────────────────────────────────────────────────────────── */

.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 17px;
    font-weight: 500;
}
.logo-icon  { font-size: 18px; }
.logo-text  { color: var(--text); }
.logo-accent{ color: var(--accent); }

.agent-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.agent-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent);
    color: #000;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.agent-info { flex: 1; min-width: 0; }
.agent-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-meta { font-size: 11px; color: var(--text-muted); }

.search-wrap {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.search-input {
    width: 100%;
    background: var(--surface2) !important;
    border: 1px solid var(--border) !important;
    font-size: 13px !important;
    padding: 7px 10px !important;
    border-radius: var(--radius) !important;
}

.ticket-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.ticket-list::-webkit-scrollbar { width: 4px; }
.ticket-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.list-loading, .list-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.ticket-item {
    padding: 11px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    border: 1px solid transparent;
    margin-bottom: 3px;
    transition: background 0.1s, border-color 0.1s;
}
.ticket-item:hover { background: var(--surface2); }
.ticket-item.active { background: var(--accent-dim); border-color: var(--accent-border); }

.ticket-item-top {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.priority-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.p-1 { background: var(--text-muted); }
.p-2 { background: var(--blue); }
.p-3 { background: var(--accent); }
.p-4 { background: var(--red); }

.ticket-num  { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--text-muted); }
.ticket-age  { font-size: 11px; color: var(--text-muted); margin-left: auto; }

.ticket-subj {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 5px;
}

.ticket-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ticket-from { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }

.status-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}
.st-2 { background: rgba(96,165,250,0.15);   color: var(--blue); }
.st-3 { background: rgba(201,150,58,0.15);   color: var(--accent); }

/* ── Main panel ─────────────────────────────────────────────────────────── */

.main-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 10px;
    color: var(--text-muted);
}
.empty-icon  { font-size: 52px; }
.empty-title { font-size: 16px; font-weight: 500; color: var(--text); }
.empty-sub   { font-size: 13px; }

/* ── Ticket detail ──────────────────────────────────────────────────────── */

.ticket-detail {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.detail-header {
    padding: 18px 24px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.detail-meta {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    color: var(--accent);
    margin-bottom: 4px;
}

.detail-subject {
    font-size: 17px;
    font-weight: 600;
    line-height: 1.4;
}

/* ── Thread ─────────────────────────────────────────────────────────────── */

.thread-wrap {
    flex: 1;
    overflow-y: auto;
    padding: 18px 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.thread-wrap::-webkit-scrollbar { width: 4px; }
.thread-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.thread-loading { color: var(--text-muted); font-size: 13px; padding: 24px; text-align: center; }

.conv-msg {
    padding: 12px 15px;
    border-radius: var(--radius);
    max-width: 82%;
}
.conv-msg.customer {
    background: var(--surface);
    border: 1px solid var(--border);
    align-self: flex-start;
}
.conv-msg.agent {
    background: var(--accent-dim);
    border: 1px solid var(--accent-border);
    align-self: flex-end;
}

.conv-role {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    margin-bottom: 5px;
}
.conv-msg.agent .conv-role { color: var(--accent); }

.conv-body {
    font-size: 13px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
}

.conv-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 5px;
}

/* ── Reply panel ────────────────────────────────────────────────────────── */

.reply-panel {
    border-top: 1px solid var(--border);
    padding: 14px 20px 18px;
    background: var(--surface);
    flex-shrink: 0;
}

.reply-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.reply-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.reply-textarea {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 13px;
    line-height: 1.65;
    padding: 11px 13px;
    resize: vertical;
    min-height: 110px;
    max-height: 260px;
    transition: border-color 0.15s;
    outline: none;
}
.reply-textarea:focus    { border-color: var(--accent); }
.reply-textarea::placeholder { color: var(--text-muted); }

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

.char-count  { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--text-muted); }
.reply-actions { display: flex; gap: 8px; }

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: opacity 0.15s, transform 0.1s;
    white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:not(:disabled):active { transform: scale(0.97); }

.btn-primary   { background: var(--accent); color: #000; font-weight: 600; }
.btn-primary:not(:disabled):hover { opacity: 0.88; }

.btn-secondary { background: var(--surface2); border: 1px solid var(--border); color: var(--text-muted); }
.btn-secondary:not(:disabled):hover { color: var(--text); border-color: var(--text-muted); }

.btn-generate  { background: var(--surface2); border: 1px solid var(--border); color: var(--text); }
.btn-generate:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }

.btn-icon { font-size: 14px; }

.icon-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: var(--radius);
    padding: 5px 9px;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    transition: color 0.15s, border-color 0.15s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}
.icon-btn:hover { color: var(--text); border-color: var(--text-muted); }

/* ── Alerts ─────────────────────────────────────────────────────────────── */

.alert {
    padding: 9px 13px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-top: 10px;
}
.alert-error   { background: var(--red-dim);   border: 1px solid var(--red-border);   color: var(--red); }
.alert-success { background: var(--green-dim); border: 1px solid var(--green-border); color: var(--green); text-align: center; font-weight: 500; }

/* ── Spinner ────────────────────────────────────────────────────────────── */

.spinner {
    display: inline-block;
    width: 12px; height: 12px;
    border: 2px solid rgba(255,255,255,0.25);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utilities ──────────────────────────────────────────────────────────── */

.hidden { display: none !important; }
