/* ============== BASE STYLES ============== */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600&display=swap');

:root {
    --primary: #1d4ed8;
    --primary-dark: #1e40af;
    --secondary: #475467;
    --success: #16a34a;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #f2efe8;
    --bg-card: #ffffff;
    --bg-input: #f2efe8;
    --text: #0f172a;
    --text-muted: #667085;
    --border: #e7e4df;
    --radius: 14px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: #f2efe8;
    color: var(--text);
    min-height: 100vh;
    font-size: 16px;
    line-height: 1.5;
}

.container {
    max-width: 1240px;
    margin: 0 auto;
    padding: 24px;
    background: #f2efe8;
}

/* ============== FLASH MESSAGES ============== */
.flash-messages {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.flash {
    padding: 12px 20px;
    border-radius: var(--radius);
    animation: slideIn 0.3s ease;
    box-shadow: 0 12px 24px rgba(16, 24, 40, 0.12);
}

.flash-error { background: #fee4e2; color: #b42318; border: 1px solid #fecdca; }
.flash-warning { background: #fffaeb; color: #b54708; border: 1px solid #fedf89; }
.flash-info { background: #e8f0ff; color: #1d4ed8; border: 1px solid #c7ddff; }
.flash-success { background: #ecfdf3; color: #027a48; border: 1px solid #abefc6; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ============== BUTTONS ============== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s, background 0.2s;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

.btn-primary { background: var(--primary); color: white; box-shadow: 0 10px 18px rgba(29, 78, 216, 0.25); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-secondary { background: #e8f0ff; color: #1d4ed8; border: 1px solid #c7ddff; }
.btn-secondary:hover:not(:disabled) { background: #dbe8ff; }

.btn-warning { background: #fffaeb; color: #b54708; border: 1px solid #fedf89; }
.btn-warning:hover:not(:disabled) { background: #fef0c7; }

.btn-danger { background: #fee4e2; color: #b42318; border: 1px solid #fecdca; }
.btn-danger:hover:not(:disabled) { background: #fed3d0; }

.btn-outline {
    background: #ffffff;
    border: 1px solid var(--border);
    color: var(--secondary);
}
.btn-outline:hover:not(:disabled) { background: var(--bg-input); }

.btn-block { width: 100%; }

.btn-large {
    padding: 16px 32px;
    font-size: 16px;
}

.btn-icon {
    font-size: 18px;
}

/* ============== FORMS ============== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--text-muted);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-size: 14px;
    transition: border 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.12);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.form-grid .full-width {
    grid-column: 1 / -1;
}

/* ============== LOGIN PAGE ============== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-box {
    background: var(--bg-card);
    padding: 40px;
    border-radius: 20px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 50px rgba(16, 24, 40, 0.15);
    position: relative;
    overflow: hidden;
}

.login-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 6px;
    background: linear-gradient(90deg, #1d4ed8 0%, #0ea5e9 50%, #22c55e 100%);
}

.login-title {
    font-size: 30px;
    text-align: center;
    margin-bottom: 8px;
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 30px;
}

.login-form .btn {
    margin-top: 10px;
}

/* ============== DASHBOARD ============== */
.dashboard {
    padding: 10px 0 20px;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 30px;
}

.client-nickname {
    font-size: 30px;
    font-weight: 600;
}

.header-right {
    display: flex;
    gap: 12px;
    align-items: center;
}

.badge {
    background: var(--danger);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    margin-left: 6px;
}

.badge.hidden { display: none; }

.dashboard-main {
    max-width: 720px;
    margin: 0 auto;
}

.status-panel {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 30px;
    box-shadow: 0 10px 24px rgba(16, 24, 40, 0.08);
    border: 1px solid var(--border);
}

.status-item {
    margin-bottom: 16px;
}

.status-item:last-child {
    margin-bottom: 0;
}

.status-item label {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: block;
}

.status-value {
    font-size: 18px;
    font-weight: 500;
}

.status-connected { color: var(--success); }
.status-disconnected { color: var(--danger); }
.status-loading { color: var(--text-muted); }

.action-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.action-result {
    padding: 16px;
    border-radius: var(--radius);
    text-align: center;
    border: 1px solid transparent;
}

.action-result.success { background: #ecfdf3; color: #027a48; border-color: #abefc6; }
.action-result.error { background: #fee4e2; color: #b42318; border-color: #fecdca; }
.action-result.hidden { display: none; }

/* ============== MODAL ============== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden { display: none; }

.modal-content {
    background: var(--bg-card);
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(16, 24, 40, 0.18);
}

.modal-small {
    max-width: 420px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
}

.modal-close:hover { color: var(--text); }

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
}

.modal-footer textarea {
    flex: 1;
    padding: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    resize: none;
}

/* ============== MESSAGES ============== */
.messages-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    padding: 12px 16px;
    border-radius: var(--radius);
    max-width: 80%;
}

.message-client {
    background: var(--primary);
    color: #ffffff;
    align-self: flex-end;
    margin-left: auto;
}

.message-admin {
    background: var(--bg-input);
    align-self: flex-start;
}

.message-time {
    font-size: 11px;
    color: rgba(15, 23, 42, 0.6);
    margin-top: 4px;
}

/* ============== ADMIN PANEL ============== */
.admin-panel {
    padding: 20px;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.admin-user {
    color: var(--text-muted);
    margin-right: 16px;
}

.admin-tabs {
    display: flex;
    gap: 8px;
    margin: 20px 0;
}

.tab-btn {
    padding: 10px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    border-radius: 12px;
    transition: all 0.2s;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active {
    background: #e8f0ff;
    color: #1d4ed8;
    border-color: #c7ddff;
}

.tab-content {
    display: none;
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.tab-content.active { display: block; }

/* ============== DATA TABLE ============== */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
}

.data-table tbody tr {
    cursor: pointer;
    transition: background 0.2s;
}

.data-table tbody tr:hover {
    background: var(--bg-input);
}

.data-table tbody tr.selected {
    background: rgba(29, 78, 216, 0.1);
}

.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
}

.status-badge.active { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.status-badge.disabled { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.status-badge.expired { background: rgba(245, 158, 11, 0.15); color: var(--warning); }

.loading {
    color: var(--text-muted);
    text-align: center;
    padding: 20px;
}

/* ============== CONTEXT MENU ============== */
.context-menu {
    position: fixed;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 160px;
    box-shadow: 0 12px 28px rgba(16, 24, 40, 0.18);
    z-index: 1001;
}

.context-menu.hidden { display: none; }

.context-item {
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.context-item:hover { background: var(--bg-input); }
.context-item.danger { color: var(--danger); }
.context-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* ============== ADMIN MESSAGES ============== */
.messages-panel {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 20px;
    min-height: 400px;
}

.conversations-list {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow-y: auto;
    max-height: 500px;
    border: 1px solid var(--border);
}

.conversation-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

.conversation-item:hover { background: var(--bg-input); }
.conversation-item.active { background: rgba(29, 78, 216, 0.1); }

.conversation-name {
    font-weight: 600;
    margin-bottom: 4px;
}

.conversation-preview {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.messages-view {
    background: var(--bg-card);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
}

.messages-view .no-selection {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
}

.messages-view .messages-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.messages-view .messages-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    max-height: 350px;
}

.messages-view .messages-input {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

.messages-view .messages-input textarea {
    flex: 1;
    padding: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    resize: none;
}

.text-danger { color: var(--danger); }

/* ============== RESPONSIVE ============== */
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .action-buttons {
        grid-template-columns: 1fr;
    }

    .messages-panel {
        grid-template-columns: 1fr;
    }

    .conversations-list {
        max-height: 200px;
    }
}
