/* ============================================================
   LIGHTSPEED DESIGN SYSTEM
   Stripe-inspired design tokens, typography, and base styles
   ============================================================ */

/* --- Design Tokens --- */
:root {
    /* Typography */
    --font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;

    /* Colors - Primary palette */
    --text-primary: #0A2540;
    --text-secondary: #425466;
    --text-muted: #6B7C93;

    /* CTA */
    --cta: #635BFF;
    --cta-hover: #7A73FF;

    /* Backgrounds */
    --bg-primary: #FFFFFF;
    --bg-alt: #F6F9FC;

    /* Borders & Utility */
    --border: #E3E8EE;
    --danger: #DF1B41;
    --success: #30B130;

    /* Lightspeed brand gradient */
    --gradient-start: #E91E8C;
    --gradient-mid: #F47B3A;
    --gradient-end: #F5C623;
    --brand-gradient: linear-gradient(135deg, #E91E8C, #F47B3A, #F5C623);

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-xl: 0 8px 24px rgba(0, 0, 0, 0.12);

    /* Radii */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-pill: 24px;

    /* Layout */
    --max-width: 1200px;
    --section-padding: 100px;
    --transition: all 0.2s ease;

    /* Legacy mappings for app compatibility */
    --primary-dark: #0A2540;
    --primary: #0A2540;
    --primary-light: #425466;
    --accent: #635BFF;
    --bg-dark: #ffffff;
    --bg-card: #ffffff;
    --bg-light: #F6F9FC;
    --bg-input: #F6F9FC;
    --warning: #f59e0b;
    --radius-xl: 24px;
}

/* --- Reset --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* --- Base --- */
html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    opacity: 1; /* Override inline FOUC guard once this stylesheet is loaded */
}

img {
    max-width: 100%;
    display: block;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: var(--font-family);
    cursor: pointer;
    border: none;
    background: none;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
    line-height: 1.15;
    color: var(--text-primary);
}

/* --- Utility: Container --- */
.ls-container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 40px;
}

@media (max-width: 768px) {
    .ls-container {
        padding: 0 24px;
    }
}

/* --- Buttons --- */
.ls-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 15px;
    border-radius: var(--radius-pill);
    padding: 12px 28px;
    transition: var(--transition);
    cursor: pointer;
    border: none;
    white-space: nowrap;
    line-height: 1;
}

.ls-btn:hover {
    transform: scale(1.02);
}

/* Primary CTA */
.ls-btn-primary {
    background: var(--cta);
    color: #fff;
}

.ls-btn-primary:hover {
    background: var(--cta-hover);
}

/* Secondary / Ghost */
.ls-btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.ls-btn-secondary:hover {
    border-color: var(--text-muted);
    background: var(--bg-alt);
}

/* Brand gradient button (sparingly) */
.ls-btn-brand {
    background: var(--brand-gradient);
    color: #fff;
}

.ls-btn-brand:hover {
    opacity: 0.92;
}

/* --- Cards --- */
.ls-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 24px;
    transition: var(--transition);
}

.ls-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* --- Empty States --- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}
.empty-state-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.8;
}
.empty-state-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 6px;
}
.empty-state-text {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 0 0 20px;
}
.empty-state-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    background: var(--cta);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}
.empty-state-btn:hover {
    opacity: 0.9;
}

/* --- Skeleton Loading States --- */
@keyframes skeleton-pulse {
    0% { opacity: 0.6; }
    50% { opacity: 0.3; }
    100% { opacity: 0.6; }
}

.skeleton {
    background: var(--border);
    border-radius: var(--radius-sm);
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-text {
    height: 14px;
    margin-bottom: 10px;
    border-radius: 4px;
}

.skeleton-text-sm {
    height: 12px;
    width: 60%;
    margin-bottom: 8px;
}

.skeleton-title {
    height: 18px;
    width: 45%;
    margin-bottom: 12px;
}

.skeleton-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 24px;
}

.skeleton-card .skeleton-title { width: 50%; }
.skeleton-card .skeleton-text { width: 90%; }
.skeleton-card .skeleton-text:last-child { width: 70%; }

.skeleton-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
}

.skeleton-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
}

.skeleton-row-content {
    flex: 1;
}

/* --- Command Palette (Cmd+K) --- */
.cmdk-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(10, 37, 64, 0.4);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 20vh;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
}

.cmdk-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.cmdk-dialog {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl), 0 0 0 1px rgba(0,0,0,0.05);
    width: 560px;
    max-width: 90vw;
    max-height: 420px;
    overflow: hidden;
    transform: scale(0.96) translateY(-8px);
    transition: transform 0.15s ease;
}

.cmdk-overlay.visible .cmdk-dialog {
    transform: scale(1) translateY(0);
}

.cmdk-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.cmdk-search-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}

.cmdk-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 16px;
    font-family: var(--font-family);
    color: var(--text-primary);
    background: transparent;
}

.cmdk-input::placeholder {
    color: var(--text-muted);
}

.cmdk-kbd {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: var(--font-family);
}

.cmdk-results {
    overflow-y: auto;
    max-height: 340px;
    padding: 8px;
}

.cmdk-group-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 10px 4px;
}

.cmdk-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.1s ease;
}

.cmdk-item:hover,
.cmdk-item.active {
    background: var(--bg-alt);
}

.cmdk-item-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--bg-alt);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.cmdk-item.active .cmdk-item-icon {
    background: var(--border);
}

.cmdk-item-text {
    flex: 1;
    min-width: 0;
}

.cmdk-item-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.cmdk-item-desc {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cmdk-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
    font-size: 14px;
}

/* Fade-out animation for optimistic deletes */
.fade-out-delete {
    opacity: 0;
    transform: scale(0.96);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

/* --- Knowledge Base Page --- */
.kb-page { padding: 24px; flex: 1; min-height: 0; overflow-y: auto; }
.kb-page-header { margin-bottom: 20px; }
.kb-page-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.kb-page-title { font-size: 1.5rem; font-weight: 700; color: var(--text-primary); margin: 0; }

.kb-tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 8px; }
.kb-tab {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.kb-tab:hover { color: var(--text-primary); }
.kb-tab.active { color: var(--cta); border-bottom-color: var(--cta); }

.kb-tab-desc { font-size: 13px; color: var(--text-muted); margin: 0 0 16px; }

.kb-stats { display: flex; gap: 16px; margin-bottom: 16px; }
.kb-stat { font-size: 13px; color: var(--text-secondary); }
.kb-stat-value { font-weight: 700; color: var(--text-primary); }

.kb-toolbar {
    display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap;
}
.kb-search {
    flex: 1; min-width: 180px;
    padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-md);
    font-size: 14px; font-family: var(--font-family); background: var(--bg-primary);
    color: var(--text-primary); transition: border-color 0.15s ease;
}
.kb-search:focus { outline: none; border-color: var(--cta); }
.kb-category-filter {
    padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-md);
    font-size: 14px; font-family: var(--font-family); background: var(--bg-primary);
    color: var(--text-primary); cursor: pointer;
}
.kb-toolbar-actions { display: flex; gap: 8px; }
.btn-sm { padding: 8px 14px; font-size: 13px; }

/* KB Form Card */
.kb-form-card {
    background: var(--bg-primary); border: 1px solid var(--cta); border-radius: var(--radius-md);
    padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow-md);
}
.kb-form-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.kb-form-header h3 { font-size: 1rem; font-weight: 600; margin: 0; }
.kb-form-row { display: flex; gap: 12px; }
.kb-form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

/* KB Entry Cards */
.kb-entries { display: flex; flex-direction: column; gap: 8px; }
.kb-entry {
    background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: 16px; transition: var(--transition); cursor: pointer;
}
.kb-entry:hover { border-color: var(--text-muted); box-shadow: var(--shadow-sm); }
.kb-entry-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.kb-entry-title { font-size: 14px; font-weight: 600; color: var(--text-primary); margin: 0 0 4px; }
.kb-entry-preview { font-size: 13px; color: var(--text-muted); line-height: 1.5; margin: 0 0 8px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.kb-entry-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.kb-entry-tag {
    display: inline-block; padding: 2px 8px; border-radius: 4px;
    font-size: 11px; font-weight: 500; background: var(--bg-alt); color: var(--text-secondary);
}
.kb-entry-tag-feedback { background: #fef3c7; color: #92400e; }

/* Response Rules */
.rules-add-form {
    display: flex; gap: 0.75rem; align-items: flex-start;
    padding: 1rem; background: var(--bg-alt); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: 1rem;
}
.rules-list { display: flex; flex-direction: column; gap: 0; }
.rule-item {
    display: flex; align-items: flex-start; gap: 0.75rem;
    padding: 0.75rem 1rem; border: 1px solid var(--border);
    border-bottom: none; background: var(--bg-primary);
    transition: var(--transition);
}
.rule-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.rule-item:last-child { border-bottom: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); }
.rule-item:only-child { border-radius: var(--radius); border-bottom: 1px solid var(--border); }
.rule-item:hover { background: var(--bg-alt); }
.rule-item.inactive { opacity: 0.5; }
.rule-order { font-size: 0.75rem; font-weight: 700; color: var(--text-muted); min-width: 20px; padding-top: 2px; }
.rule-type-chip {
    display: inline-block; font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
    padding: 2px 6px; border-radius: 3px; letter-spacing: 0.5px; white-space: nowrap;
}
.rule-type-always { background: #d1fae5; color: #065f46; }
.rule-type-never { background: #fee2e2; color: #991b1b; }
.rule-type-formatting { background: #dbeafe; color: #1e40af; }
.rule-type-general { background: var(--bg-alt); color: var(--text-secondary); border: 1px solid var(--border); }
.rule-text { flex: 1; font-size: 0.875rem; line-height: 1.5; color: var(--text-primary); word-break: break-word; }
.rule-actions { display: flex; gap: 4px; flex-shrink: 0; }
.rule-actions button {
    padding: 3px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 11px; font-weight: 500; background: var(--bg-primary); color: var(--text-secondary);
    cursor: pointer; transition: var(--transition); white-space: nowrap;
}
.rule-actions button:hover { border-color: var(--text-muted); color: var(--text-primary); }
.rule-actions .rule-btn-delete:hover { border-color: var(--danger); color: var(--danger); }
.rule-move-btns { display: flex; flex-direction: column; gap: 2px; }
.rule-move-btns button { padding: 1px 6px; font-size: 10px; line-height: 1; }

/* Duplicate finder / merge modal */
.dup-group { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem; overflow: hidden; }
.dup-group-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.5rem 0.75rem; background: var(--bg-alt); border-bottom: 1px solid var(--border);
}
.dup-group-label { font-weight: 600; font-size: 0.85rem; color: var(--text-secondary); }
.dup-entry { padding: 0.75rem; border-bottom: 1px solid var(--border); }
.dup-entry:last-child { border-bottom: none; }
.dup-entry-header { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.25rem; }
.dup-entry-content {
    font-size: 0.85rem; color: var(--text-secondary); line-height: 1.5;
    white-space: pre-wrap; word-break: break-word;
}
.merge-preview {
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 0.75rem; background: var(--bg-primary);
}
.kb-entry-actions { display: flex; gap: 4px; flex-shrink: 0; }
.kb-entry-actions button {
    padding: 4px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 12px; font-weight: 500; background: var(--bg-primary); color: var(--text-secondary);
    cursor: pointer; transition: var(--transition); white-space: nowrap;
}
.kb-entry-actions button:hover { border-color: var(--text-muted); color: var(--text-primary); }
.kb-entry-actions .kb-btn-delete:hover { border-color: var(--danger); color: var(--danger); }

/* KB expanded content */
.kb-entry-full { display: none; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.kb-entry-full-content { font-size: 13px; color: var(--text-secondary); line-height: 1.6; white-space: pre-wrap; }
.kb-entry.expanded .kb-entry-full { display: block; }
.kb-entry.expanded .kb-entry-preview { display: none; }

/* KB Import Modal */
.kb-modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(10,37,64,0.4); backdrop-filter: blur(4px);
    z-index: 9000; display: flex; align-items: center; justify-content: center;
}
.kb-modal {
    background: var(--bg-primary); border-radius: var(--radius-lg);
    padding: 24px; width: 560px; max-width: 90vw; box-shadow: var(--shadow-xl);
}
.kb-modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.kb-modal-header h3 { margin: 0; font-size: 1.1rem; }

@media (max-width: 768px) {
    .kb-form-row { flex-direction: column; }
    .kb-toolbar { flex-direction: column; }
    .kb-toolbar-actions { width: 100%; }
}
