:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-input: #232733;
    --border: #2d3140;
    --text: #e4e6ef;
    --text-dim: #8b8fa3;
    --accent: #6c5ce7;
    --accent-hover: #7f71ea;
    --green: #00b894;
    --red: #ff6b6b;
    --yellow: #ffd93d;
    --blue: #74b9ff;
    --sidebar-w: 240px;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    height: 100vh;
    position: fixed;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 20px;
    border-bottom: 1px solid var(--border);
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: var(--accent);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: white;
}

.logo-text {
    font-weight: 600;
    font-size: 16px;
}

.nav-links {
    list-style: none;
    padding: 12px 0;
    flex: 1;
}

.nav-links li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-dim);
    font-size: 14px;
    transition: all 0.15s;
}

.nav-links li a:hover,
.nav-links li a.active {
    color: var(--text);
    background: rgba(108, 92, 231, 0.1);
    text-decoration: none;
}

.nav-links li a.active {
    border-right: 3px solid var(--accent);
}

.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-dim);
}

/* Content */
.content {
    margin-left: var(--sidebar-w);
    padding: 32px;
    flex: 1;
    max-width: 1200px;
}

.page-header {
    margin-bottom: 28px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 600;
}

.subtitle {
    color: var(--text-dim);
    margin-top: 4px;
    font-size: 14px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 20px;
    overflow: hidden;
}

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

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.sessions-icon { background: rgba(108, 92, 231, 0.15); color: var(--accent); }
.chats-icon { background: rgba(116, 185, 255, 0.15); color: var(--blue); }
.ai-icon { background: rgba(255, 217, 61, 0.15); color: var(--yellow); }
.status-icon { background: rgba(0, 184, 148, 0.15); color: var(--green); }
.status-icon.inactive { background: rgba(255, 107, 107, 0.15); color: var(--red); }

.stat-value {
    font-size: 22px;
    font-weight: 700;
}

.stat-label {
    font-size: 13px;
    color: var(--text-dim);
    margin-top: 2px;
}

/* Table */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 10px 14px;
    text-align: left;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    color: var(--text-dim);
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table code {
    background: var(--bg-input);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 13px;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-ok { background: rgba(0, 184, 148, 0.15); color: var(--green); }
.badge-err { background: rgba(255, 107, 107, 0.15); color: var(--red); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}

.btn:hover { background: var(--border); text-decoration: none; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

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

.btn-danger {
    background: transparent;
    border-color: var(--red);
    color: var(--red);
}

.btn-danger:hover { background: rgba(255, 107, 107, 0.1); }

.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

/* Forms */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-dim);
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    transition: border-color 0.15s;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
}

.form-input::placeholder { color: var(--text-dim); }

small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-dim);
}

.form-actions {
    text-align: center;
    padding: 12px 0;
}

/* Flash messages */
.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

.flash-success { background: rgba(0, 184, 148, 0.15); color: var(--green); border: 1px solid rgba(0, 184, 148, 0.3); }
.flash-error { background: rgba(255, 107, 107, 0.15); color: var(--red); border: 1px solid rgba(255, 107, 107, 0.3); }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-dim);
}

.empty-state p { margin-bottom: 16px; }

/* Categories grid */
.categories-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 380px;
    overflow-y: auto;
    padding-right: 4px;
}

.categories-grid::-webkit-scrollbar { width: 5px; }
.categories-grid::-webkit-scrollbar-track { background: transparent; }
.categories-grid::-webkit-scrollbar-thumb { background: #2d3140; border-radius: 3px; }

.category-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 14px;
    background: var(--bg-input);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.cat-code {
    background: rgba(108, 92, 231, 0.2);
    border: 1px solid rgba(108, 92, 231, 0.45);
    color: #a29bfe;
    padding: 4px 10px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    font-family: 'Consolas', 'Monaco', monospace;
    white-space: nowrap;
    word-break: normal;
}

.cat-name {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Steps list */
.steps-list {
    padding-left: 20px;
    line-height: 2;
    font-size: 14px;
}

.steps-list code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show { display: flex; }

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 420px;
    max-width: 90vw;
}

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

.modal-header h3 { font-size: 16px; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.modal-body { padding: 20px; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

/* Alert */
.alert {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    margin-top: 12px;
}

.alert-info { background: rgba(116, 185, 255, 0.15); color: var(--blue); }
.alert-ok { background: rgba(0, 184, 148, 0.15); color: var(--green); }
.alert-err { background: rgba(255, 107, 107, 0.15); color: var(--red); }

/* Quick Actions */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.action-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    text-decoration: none;
    color: var(--text);
    transition: all 0.15s;
}

.action-card:hover {
    border-color: var(--accent);
    background: rgba(108, 92, 231, 0.05);
    text-decoration: none;
}

.action-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.action-title {
    font-size: 14px;
    font-weight: 500;
}

/* Input Group */
.input-group {
    display: flex;
    gap: 10px;
}

.input-group .form-input {
    flex: 1;
}

/* Chat List */
.chat-list {
    max-height: 400px;
    overflow-y: auto;
}

.chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}

.chat-item:last-child {
    border-bottom: none;
}

.chat-name {
    font-size: 14px;
    word-break: break-all;
}

/* Textarea */
.textarea {
    resize: vertical;
    min-height: 100px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    line-height: 1.5;
}

/* Stat Row */
.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

/* Sort Controls */
.sort-controls {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* Progress Bar */
.progress-bar-container {
    width: 100%;
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-stats {
    display: flex;
    gap: 20px;
    font-size: 14px;
    color: var(--text-dim);
}

/* Filter Row */
.filter-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-btn {
    opacity: 0.6;
}

.filter-btn.active {
    opacity: 1;
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Category count */
.cat-count {
    margin-left: auto;
    font-weight: 700;
    font-size: 16px;
    color: var(--accent);
}

/* Badge cat */
.badge-cat {
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    font-family: 'Consolas', 'Monaco', monospace;
    background: rgba(108, 92, 231, 0.2);
    border: 1px solid rgba(108, 92, 231, 0.45);
    color: #a29bfe;
    display: inline-block;
    white-space: nowrap;
}

/* Table container */
.table-container {
    overflow-x: auto;
    max-height: 500px;
    overflow-y: auto;
}

/* Sort Layout */
.sort-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
}

.sort-left {
    display: flex;
    flex-direction: column;
}

.sort-right {
    display: flex;
    flex-direction: column;
}

/* Terminal */
.terminal-card {
    margin-bottom: 0;
}

.terminal-body {
    padding: 0 !important;
}

.terminal {
    background: #0a0c10;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.6;
    height: 500px;
    overflow-y: auto;
    padding: 12px 16px;
    color: #a0a8c0;
}

.terminal::-webkit-scrollbar { width: 6px; }
.terminal::-webkit-scrollbar-track { background: #0a0c10; }
.terminal::-webkit-scrollbar-thumb { background: #2d3140; border-radius: 3px; }

.terminal-line {
    white-space: pre-wrap;
    word-break: break-all;
    padding: 1px 0;
}

.terminal-line.terminal-ok { color: #00b894; }
.terminal-line.terminal-err { color: #ff6b6b; }
.terminal-line.terminal-warn { color: #ffd93d; }
.terminal-line.terminal-info { color: #74b9ff; }

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .content { margin-left: 0; padding: 16px; }
    .settings-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .quick-actions { grid-template-columns: repeat(2, 1fr); }
    .sort-layout { grid-template-columns: 1fr; }
}
