/* ─── Taktline Design System ───────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --charcoal: #111118;
    --surface: #1a1a24;
    --card: #22222e;
    --amber: #f59e0b;
    --amber-soft: #fbbf24;
    --amber-glow: rgba(245, 158, 11, 0.15);
    --green: #22c55e;
    --green-glow: rgba(34, 197, 94, 0.15);
    --red: #ef4444;
    --red-glow: rgba(239, 68, 68, 0.15);
    --blue: #3b82f6;
    --blue-glow: rgba(59, 130, 246, 0.15);
    --text: #e8e8ed;
    --text-muted: #9494a8;
    --text-dim: #6b6b80;
    --border: #2a2a38;
    --border-hover: #3a3a4a;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
}

body {
    font-family: 'DM Sans', -apple-system, sans-serif;
    background: var(--charcoal);
    color: var(--text);
    overflow-x: hidden;
    line-height: 1.6;
    min-height: 100vh;
}

body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 0;
}

/* ─── Typography ──────────────────────────────────────── */
h1, h2, h3 {
    font-family: 'Space Grotesk', sans-serif;
    letter-spacing: -0.5px;
}

/* ─── Auth Pages ──────────────────────────────────────── */
.auth-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
    z-index: 1;
}

.logo-link {
    text-decoration: none;
    margin-bottom: 32px;
}

.logo {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 28px;
    letter-spacing: -0.5px;
    color: var(--text);
}

.logo span { color: var(--amber); }

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
}

.auth-card h2 {
    font-size: 24px;
    margin-bottom: 4px;
}

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

.auth-switch {
    text-align: center;
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 20px;
}

.auth-switch a {
    color: var(--amber);
    text-decoration: none;
    font-weight: 500;
}

/* ─── Forms ───────────────────────────────────────────── */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input, textarea, select {
    width: 100%;
    padding: 12px 14px;
    background: var(--charcoal);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--amber);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%239494a8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.error-msg {
    background: var(--red-glow);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 16px;
}

/* ─── Buttons ─────────────────────────────────────────── */
.btn-primary {
    width: 100%;
    padding: 13px 20px;
    background: var(--amber);
    color: var(--charcoal);
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    letter-spacing: -0.2px;
}

.btn-primary:hover { background: var(--amber-soft); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
    padding: 10px 18px;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.btn-secondary:hover { border-color: var(--amber); background: var(--surface); }

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
    border-radius: 6px;
}

.btn-approve {
    background: var(--green);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    font-size: 13px;
    transition: opacity 0.2s;
}
.btn-approve:hover { opacity: 0.9; }

.btn-reject {
    background: transparent;
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}
.btn-reject:hover { background: var(--red-glow); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: color 0.2s;
}
.btn-ghost:hover { color: var(--text); }

/* ─── Dashboard Layout ────────────────────────────────── */
.app-wrapper {
    position: relative;
    z-index: 1;
    min-height: 100vh;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(17, 17, 24, 0.8);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 50;
}

.app-header .logo { font-size: 20px; }

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-name {
    font-size: 13px;
    color: var(--text-muted);
}

.app-nav {
    display: flex;
    gap: 2px;
    padding: 12px 24px 0;
    border-bottom: 1px solid var(--border);
    background: var(--charcoal);
}

.nav-tab {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
    position: relative;
    top: 1px;
}

.nav-tab:hover { color: var(--text); }
.nav-tab.active { color: var(--amber); border-bottom-color: var(--amber); }

.nav-tab .badge {
    background: var(--amber);
    color: var(--charcoal);
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 10px;
    margin-left: 6px;
}

.app-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px;
}

/* ─── Stats Cards ─────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.stat-card .stat-value {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 32px;
    font-weight: 700;
    color: var(--amber);
    letter-spacing: -1px;
}

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

/* ─── Thread List ─────────────────────────────────────── */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.filter-btn {
    padding: 6px 14px;
    font-size: 13px;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 100px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'DM Sans', sans-serif;
}

.filter-btn:hover { border-color: var(--amber); color: var(--text); }
.filter-btn.active { background: var(--amber-glow); border-color: var(--amber); color: var(--amber); }

.thread-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.thread-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.2s, transform 0.1s;
}

.thread-item:hover { border-color: var(--border-hover); transform: translateX(2px); }

.thread-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--amber-glow);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 16px;
    color: var(--amber);
    flex-shrink: 0;
}

.thread-content { flex: 1; min-width: 0; }

.thread-sender {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.thread-subject {
    font-size: 14px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

.thread-time {
    font-size: 12px;
    color: var(--text-dim);
}

.status-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 100px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-pending { background: var(--amber-glow); color: var(--amber); }
.status-responded { background: var(--green-glow); color: var(--green); }
.status-archived { background: rgba(148, 148, 168, 0.1); color: var(--text-muted); }
.status-draft { background: var(--blue-glow); color: var(--blue); }

/* ─── Thread Detail ───────────────────────────────────── */
.thread-detail {
    max-width: 760px;
    margin: 0 auto;
}

.thread-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
    margin-bottom: 20px;
    transition: color 0.2s;
}
.thread-back:hover { color: var(--amber); }

.thread-header {
    margin-bottom: 24px;
}

.thread-header h2 {
    font-size: 22px;
    margin-bottom: 4px;
}

.thread-header-meta {
    font-size: 13px;
    color: var(--text-muted);
}

.message-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.message-card.inbound { border-left: 3px solid var(--text-dim); }
.message-card.outbound { border-left: 3px solid var(--amber); }
.message-card.draft-message { border-left: 3px solid var(--blue); background: rgba(59, 130, 246, 0.04); }

.message-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.message-sender {
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.message-sender .ai-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--amber-glow);
    color: var(--amber);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.message-time {
    font-size: 12px;
    color: var(--text-dim);
}

.message-body {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text);
    white-space: pre-wrap;
}

.draft-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.edit-draft-area {
    width: 100%;
    margin-top: 12px;
}

.edit-draft-area textarea {
    min-height: 120px;
    margin-bottom: 8px;
}

/* ─── Settings Page ───────────────────────────────────── */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.settings-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
}

.settings-section h3 {
    font-size: 18px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-section.full-width {
    grid-column: 1 / -1;
}

.api-key-display {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.api-key-value {
    flex: 1;
    padding: 10px 14px;
    background: var(--charcoal);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
    color: var(--text-muted);
    word-break: break-all;
}

.webhook-url {
    padding: 12px 14px;
    background: var(--charcoal);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
    color: var(--amber);
    word-break: break-all;
    margin-bottom: 16px;
}

.code-block {
    background: var(--charcoal);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    color: var(--text-muted);
    overflow-x: auto;
    white-space: pre;
    line-height: 1.6;
}

/* ─── Rules Section ───────────────────────────────────── */
.rules-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rule-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--charcoal);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.rule-info h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
}

.rule-info p {
    font-size: 12px;
    color: var(--text-muted);
}

.rule-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.toggle-switch {
    position: relative;
    width: 36px;
    height: 20px;
    cursor: pointer;
}

.toggle-switch input { display: none; }

.toggle-slider {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--border);
    border-radius: 10px;
    transition: background 0.2s;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--text-muted);
    top: 2px; left: 2px;
    transition: transform 0.2s, background 0.2s;
}

.toggle-switch input:checked + .toggle-slider { background: var(--amber-glow); }
.toggle-switch input:checked + .toggle-slider::after { transform: translateX(16px); background: var(--amber); }

/* ─── Empty State ─────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 18px;
    color: var(--text);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    max-width: 400px;
    margin: 0 auto;
}

/* ─── Loading ─────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--amber);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.loading-center {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
}

/* ─── Toast Notifications ─────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 20px;
    font-size: 14px;
    z-index: 100;
    animation: slideUp 0.3s ease;
    max-width: 360px;
}

.toast.success { border-color: rgba(34, 197, 94, 0.4); }
.toast.error { border-color: rgba(239, 68, 68, 0.4); }

@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ─── Modal ───────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 80;
    animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    width: 90%;
    max-width: 520px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal h3 { font-size: 20px; margin-bottom: 20px; }

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

/* ─── Responsive ──────────────────────────────────────── */
@media (max-width: 768px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .settings-grid { grid-template-columns: 1fr; }
    .app-nav { overflow-x: auto; padding: 12px 16px 0; }
    .app-main { padding: 16px; }
    .thread-item { padding: 12px 16px; }
    .auth-card { padding: 28px; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .draft-actions { flex-direction: column; }
}
