/* CKTec Email-Assistent - Web App Styles */
:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-hover: #232736;
    --bg-input: #232736;
    --border: #2d3148;
    --text: #e8eaed;
    --text-dim: #8b8fa3;
    --text-muted: #5f6377;
    --accent: #4a7cff;
    --accent-hover: #5d8bff;
    --accent-dim: rgba(74, 124, 255, 0.15);
    --green: #34c759;
    --green-dim: rgba(52, 199, 89, 0.15);
    --orange: #ff9f0a;
    --orange-dim: rgba(255, 159, 10, 0.15);
    --red: #ff453a;
    --red-dim: rgba(255, 69, 58, 0.15);
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
    --sidebar-w: 360px;
    --msg-customer: #1e2a3a;
    --msg-own: #1a2e1a;
    --msg-ai: var(--bg-card);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.screen { display: none; height: 100vh; }
.screen.active { display: flex; }

.hidden { display: none !important; }

/* Scrollbars */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Login ===== */
#login-screen {
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.login-box {
    width: 100%;
    max-width: 380px;
    padding: 40px;
    text-align: center;
}

.login-logo {
    font-size: 32px;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: 2px;
}

.login-subtitle {
    color: var(--text-dim);
    margin-bottom: 32px;
    font-size: 14px;
}

.login-box input {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

.login-box input:focus {
    border-color: var(--accent);
}

.error-msg {
    color: var(--red);
    font-size: 13px;
    margin-top: 8px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
    color: var(--text);
    background: var(--bg-hover);
}

.btn:hover { background: var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary { background: var(--bg-hover); border: 1px solid var(--border); }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-full { width: 100%; padding: 12px; }
.btn-icon { background: none; padding: 6px 10px; font-size: 18px; }
.btn-icon:hover { background: var(--bg-hover); }

/* ===== App Layout ===== */
#app-screen {
    display: none;
    flex-direction: row;
}

#app-screen.active {
    display: flex;
}

/* ===== Sidebar ===== */
#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    height: 100vh;
    background: var(--bg-card);
    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: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
    font-size: 20px;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: 1px;
}

.sidebar-actions { display: flex; gap: 4px; }

/* Stats Bar */
.sidebar-stats {
    display: flex;
    padding: 10px 20px;
    gap: 8px;
    border-bottom: 1px solid var(--border);
}

.stat {
    flex: 1;
    text-align: center;
    padding: 6px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
}

#stat-unread { background: var(--accent-dim); color: var(--accent); }
#stat-today { background: var(--orange-dim); color: var(--orange); }
#stat-replied { background: var(--green-dim); color: var(--green); }
#stat-total { background: var(--bg-hover); color: var(--text-dim); }

/* Filters */
.sidebar-filters {
    display: flex;
    padding: 8px 12px;
    gap: 4px;
}

.filter-btn {
    flex: 1;
    padding: 6px 8px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 13px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}

.filter-btn:hover { background: var(--bg-hover); }
.filter-btn.active { background: var(--accent-dim); color: var(--accent); }

/* Email List */
.email-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.email-item {
    padding: 12px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
    border-left: 3px solid transparent;
}

.email-item:hover { background: var(--bg-hover); }
.email-item.active { background: var(--accent-dim); border-left-color: var(--accent); }
.email-item.unread { border-left-color: var(--accent); }
.email-item.replied { border-left-color: var(--green); }

.email-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.email-item-name {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.email-item-time {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.email-item-subject {
    font-size: 13px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-item-ad {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-item-status {
    display: inline-block;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 500;
}

.status-unread { background: var(--accent-dim); color: var(--accent); }
.status-read { background: var(--orange-dim); color: var(--orange); }
.status-replied { background: var(--green-dim); color: var(--green); }

.list-loading, .load-more {
    padding: 12px;
    text-align: center;
    color: var(--text-dim);
    font-size: 14px;
}

/* ===== Main Content ===== */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* Empty State */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.empty-icon { font-size: 64px; margin-bottom: 16px; opacity: 0.3; }

/* ===== Conversation View ===== */
.conversation-view {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.conv-header {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    gap: 12px;
}

.btn-back { display: none; }

.conv-header-info { flex: 1; overflow: hidden; }

.conv-title {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-meta {
    font-size: 13px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Messages Area */
.conv-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    position: relative;
}

.message-customer {
    align-self: flex-start;
    background: var(--msg-customer);
    border-bottom-left-radius: 4px;
}

.message-own {
    align-self: flex-end;
    background: var(--msg-own);
    border-bottom-right-radius: 4px;
}

.message-label {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.message-customer .message-label { color: var(--accent); }
.message-own .message-label { color: var(--green); }

.message-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    text-align: right;
}

/* ===== Action Bar ===== */
.conv-actions {
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    padding: 0;
}

.draft-area {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.draft-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--text-dim);
    font-weight: 600;
}

.draft-buttons { display: flex; gap: 8px; }

.draft-text {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 14px;
    line-height: 1.5;
    max-height: 250px;
    overflow-y: auto;
    color: var(--text);
    outline: none;
    white-space: pre-wrap;
}

.draft-text:focus { border-color: var(--accent); }

.action-bar {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    align-items: flex-end;
}

.action-bar textarea {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    min-height: 42px;
    max-height: 120px;
    line-height: 1.4;
}

.action-bar textarea:focus { border-color: var(--accent); }

/* ===== Knowledge View ===== */
.knowledge-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

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

.knowledge-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
}

.kb-item {
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color 0.15s;
}

.kb-item:hover { border-color: var(--accent); }

.kb-item-title {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 4px;
}

.kb-item-category {
    font-size: 12px;
    color: var(--accent);
    margin-bottom: 6px;
}

.kb-item-desc {
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.4;
}

.kb-item-meta {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.knowledge-add { padding: 12px 16px; }

.knowledge-form {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
}

.knowledge-form h3 { margin-bottom: 12px; font-size: 16px; }

.knowledge-form input,
.knowledge-form textarea {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
}

.knowledge-form input:focus,
.knowledge-form textarea:focus { border-color: var(--accent); }

.knowledge-form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 8px;
}

.kb-item-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    animation: toast-in 0.3s ease;
    max-width: 360px;
}

.toast-success { background: var(--green); color: #fff; }
.toast-error { background: var(--red); color: #fff; }
.toast-info { background: var(--accent); color: #fff; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Spinner ===== */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    #sidebar {
        width: 100%;
        min-width: 100%;
        position: absolute;
        z-index: 10;
        transition: transform 0.25s ease;
    }

    #sidebar.sidebar-hidden {
        transform: translateX(-100%);
    }

    #main-content {
        width: 100%;
    }

    .btn-back { display: flex; }

    .message { max-width: 88%; }

    .conv-header { padding: 12px 14px; }

    .sidebar-stats { padding: 8px 12px; }

    .email-item-name { max-width: 160px; }

    .draft-text { max-height: 180px; }
}

@media (max-width: 480px) {
    .sidebar-header h1 { font-size: 18px; }
    .email-item { padding: 10px 12px; }
    .conv-messages { padding: 12px; }
    .action-bar { padding: 8px 12px; }
}
