/**
 * CRM Light Theme
 * Author: Kai Schnider
 * Version: 2.0
 */

:root {
    --background: #f8f9fa;
    --surface: #ffffff;
    --surface-light: #f1f3f4;
    --surface-hover: #e8eaed;
    --border: #dadce0;
    --border-light: #e0e0e0;
    --text: #202124;
    --text-muted: #5f6368;
    --primary: #1a73e8;
    --primary-hover: #1557b0;
    --primary-light: #e8f0fe;
    --accent: #1a73e8;
    --success: #34a853;
    --success-light: #e6f4ea;
    --warning: #f9ab00;
    --warning-light: #fef7e0;
    --danger: #ea4335;
    --danger-light: #fce8e6;
    --info: #4285f4;
    --info-light: #e8f0fe;
}

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

body { 
    font-family: 'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; 
    background: var(--background); 
    color: var(--text); 
    line-height: 1.5; 
    min-height: 100vh; 
}

.app-container { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar { 
    width: 260px; 
    background: var(--surface); 
    border-right: 1px solid var(--border); 
    display: flex; 
    flex-direction: column; 
    position: fixed; 
    height: 100vh; 
    left: 0; 
    top: 0;
    z-index: 100;
}

.sidebar-header { 
    padding: 20px 24px; 
    border-bottom: 1px solid var(--border); 
}

.sidebar-header h1 { 
    font-size: 20px; 
    font-weight: 500; 
    color: var(--primary); 
}

.sidebar-nav { flex: 1; padding: 8px 0; }

.nav-item { 
    display: flex; 
    align-items: center; 
    padding: 10px 24px; 
    color: var(--text-muted); 
    text-decoration: none; 
    cursor: pointer; 
    transition: all 0.15s; 
    border-radius: 0 24px 24px 0; 
    margin-right: 12px;
    font-size: 14px;
}

.nav-item:hover { 
    background: var(--surface-light); 
    color: var(--text); 
}

.nav-item.active { 
    background: var(--primary-light); 
    color: var(--primary); 
    font-weight: 500; 
}

.nav-item svg { 
    width: 20px; 
    height: 20px; 
    margin-right: 16px; 
}

.sidebar-footer { 
    padding: 16px 20px; 
    border-top: 1px solid var(--border); 
}

.user-info { 
    display: flex; 
    align-items: center; 
    gap: 12px; 
}

.user-avatar { 
    width: 36px; 
    height: 36px; 
    border-radius: 50%; 
    background: var(--primary); 
    color: white;
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-weight: 600; 
    font-size: 14px; 
}

.user-details { flex: 1; }
.user-name { font-size: 14px; font-weight: 500; }
.user-role { font-size: 12px; color: var(--text-muted); }

/* Main Content */
.main-content { 
    flex: 1; 
    margin-left: 260px; 
    padding: 24px 32px; 
    min-height: 100vh; 
}

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

.page-title { 
    font-size: 22px; 
    font-weight: 400; 
}

/* Buttons */
.btn { 
    display: inline-flex; 
    align-items: center; 
    justify-content: center; 
    gap: 8px; 
    padding: 10px 20px; 
    font-size: 14px; 
    font-weight: 500; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer; 
    transition: all 0.15s; 
    text-decoration: none; 
}

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

.btn-primary:hover { 
    background: var(--primary-hover); 
    box-shadow: 0 1px 3px rgba(0,0,0,0.2); 
}

.btn-secondary { 
    background: var(--surface); 
    color: var(--text); 
    border: 1px solid var(--border); 
}

.btn-secondary:hover { 
    background: var(--surface-light); 
}

.btn-danger { 
    background: var(--danger); 
    color: white; 
}

.btn-danger:hover { 
    background: #d33426; 
}

.btn-icon { 
    padding: 8px; 
    background: none; 
    border: none; 
    color: var(--text-muted); 
    cursor: pointer; 
    border-radius: 4px; 
    transition: all 0.15s; 
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover { 
    background: var(--surface-light); 
    color: var(--text); 
}

.btn-icon.danger:hover { 
    color: var(--danger); 
    background: var(--danger-light);
}

/* Cards */
.card { 
    background: var(--surface); 
    border: 1px solid var(--border); 
    border-radius: 8px; 
    overflow: hidden; 
}

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

.card-title { 
    font-size: 14px; 
    font-weight: 500; 
    text-transform: uppercase; 
    letter-spacing: 0.5px; 
    color: var(--text-muted); 
}

.card-body { padding: 24px; }

/* Tables */
.table-container { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th, td { 
    padding: 14px 16px; 
    text-align: left; 
    border-bottom: 1px solid var(--border); 
}

th { 
    font-weight: 500; 
    color: var(--text-muted); 
    font-size: 12px; 
    text-transform: uppercase; 
    letter-spacing: 0.5px; 
    background: var(--surface-light); 
}

tr:hover td { background: var(--surface-light); }
tr.clickable { cursor: pointer; }

.actions { display: flex; gap: 8px; }

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

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

.form-control { 
    width: 100%; 
    padding: 10px 12px; 
    font-size: 14px; 
    color: var(--text); 
    background: var(--surface); 
    border: 1px solid var(--border); 
    border-radius: 4px; 
    transition: border-color 0.15s, box-shadow 0.15s; 
}

.form-control:focus { 
    outline: none; 
    border-color: var(--primary); 
    box-shadow: 0 0 0 2px rgba(26,115,232,0.2); 
}

.form-control::placeholder { color: var(--text-muted); }

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }

/* Search */
.search-box { position: relative; max-width: 300px; }
.search-box input { padding-left: 40px; }
.search-box svg { 
    position: absolute; 
    left: 12px; 
    top: 50%; 
    transform: translateY(-50%); 
    color: var(--text-muted); 
    width: 18px; 
    height: 18px; 
}

/* Badges */
.badge { 
    display: inline-block; 
    padding: 4px 12px; 
    font-size: 12px; 
    font-weight: 500; 
    border-radius: 16px; 
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: #b06000; }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-neutral { background: var(--surface-light); color: var(--text-muted); }

/* Opportunity Type Badges */
.badge-new-business { background: #e8f5e9; color: #2e7d32; }
.badge-upselling { background: #fff3e0; color: #ef6c00; }
.badge-cross-sell { background: #e3f2fd; color: #1565c0; }
.badge-renewal { background: #f3e5f5; color: #7b1fa2; }

/* Modals */
.modal-overlay { 
    position: fixed; 
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0; 
    background: rgba(0,0,0,0.3); 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    z-index: 1000; 
    opacity: 0; 
    visibility: hidden; 
    transition: all 0.2s; 
}

.modal-overlay.active { opacity: 1; visibility: visible; }

.modal { 
    background: var(--surface); 
    border: 1px solid var(--border); 
    border-radius: 8px; 
    width: 100%; 
    max-width: 500px; 
    max-height: 90vh; 
    overflow-y: auto; 
    transform: translateY(-20px); 
    transition: transform 0.2s;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.modal-overlay.active .modal { transform: translateY(0); }

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

.modal-title { font-size: 18px; font-weight: 500; }

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

.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; }

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

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

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

.stat-label { 
    font-size: 12px; 
    color: var(--text-muted); 
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px; 
}

.stat-value { font-size: 28px; font-weight: 400; }
.stat-value.success { color: var(--success); }

/* Toolbar */
.toolbar { 
    display: flex; 
    gap: 12px; 
    margin-bottom: 16px; 
    flex-wrap: wrap; 
    align-items: center;
}

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

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

.spinner { 
    width: 32px; 
    height: 32px; 
    border: 3px solid var(--border); 
    border-top-color: var(--primary); 
    border-radius: 50%; 
    animation: spin 0.8s linear infinite; 
}

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

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

.toast { 
    padding: 12px 16px; 
    border-radius: 4px; 
    background: var(--surface); 
    border: 1px solid var(--border); 
    box-shadow: 0 4px 12px rgba(0,0,0,0.15); 
    animation: slideIn 0.2s ease-out; 
}

.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }

@keyframes slideIn { 
    from { transform: translateX(100%); opacity: 0; } 
    to { transform: translateX(0); opacity: 1; } 
}

/* Login */
.login-container { 
    min-height: 100vh; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    background: var(--background);
}

.login-box { 
    background: var(--surface); 
    border: 1px solid var(--border); 
    border-radius: 8px; 
    padding: 40px; 
    width: 100%; 
    max-width: 400px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.login-title { 
    font-size: 24px; 
    font-weight: 500; 
    margin-bottom: 8px; 
    text-align: center; 
}

.login-subtitle { 
    color: var(--text-muted); 
    text-align: center; 
    margin-bottom: 32px; 
}

/* Kanban */
.kanban-board {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 16px;
    min-height: calc(100vh - 180px);
}

.kanban-column {
    flex: 0 0 300px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 180px);
}

.kanban-column-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
    font-size: 14px;
    background: var(--surface-light);
}

.kanban-column-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stage-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.kanban-count {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    color: var(--text-muted);
}

.kanban-sum {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: 8px;
}

.kanban-cards {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.kanban-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    cursor: grab;
    transition: all 0.15s;
}

.kanban-card:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.kanban-card.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.kanban-card-title {
    font-weight: 500;
    margin-bottom: 6px;
    font-size: 14px;
}

.kanban-card-customer {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.kanban-card-type {
    margin-bottom: 8px;
}

.kanban-card-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--success);
}

.kanban-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.kanban-card-prob {
    font-size: 11px;
    color: var(--text-muted);
}

.kanban-column.drag-over {
    background: var(--primary-light);
    border-color: var(--primary);
}

.kanban-empty {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 13px;
}

.kanban-add-card {
    margin: 0 12px 12px;
    padding: 10px;
    background: transparent;
    border: 2px dashed var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    text-align: center;
    font-size: 13px;
    transition: all 0.15s;
}

.kanban-add-card:hover {
    background: var(--surface-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* Stage Editor */
.stage-editor {
    position: fixed;
    top: 0;
    left: 260px;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.3);
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 40px;
}

.stage-editor-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 100%;
    max-width: 600px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

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

.stage-editor-body { padding: 20px; }

.stage-editor-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.stage-editor-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: 6px;
    align-items: center;
}

.stage-drag-handle {
    cursor: grab;
    color: var(--text-muted);
}

.stage-color-picker {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.stage-name-input {
    flex: 1;
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 14px;
}

.stage-editor-actions {
    display: flex;
    gap: 8px;
}

/* Fullscreen Modal for Opportunities */
.opp-fullscreen-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--background);
    z-index: 2000;
    display: none;
}

.opp-fullscreen-modal.active {
    display: flex;
    flex-direction: column;
}

.opp-fullscreen-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
    flex-shrink: 0;
}

.opp-fullscreen-header h2 {
    font-size: 18px;
    font-weight: 500;
    margin: 0;
}

.opp-fullscreen-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    max-height: calc(100vh - 60px);
}

.opp-sidebar {
    width: 320px;
    background: var(--surface-light);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 20px;
    max-height: 100%;
}

.opp-meta-section {
    margin-bottom: 24px;
}

.opp-meta-section h3 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.opp-main-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    max-height: 100%;
}

.opp-editor-container {
    max-width: 900px;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    min-height: 400px;
}

.opp-editor-container > h3 {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 16px;
    color: var(--text);
}

#opp-editor {
    font-size: 15px;
}

.opp-upload-area {
    margin-top: 12px;
}

.opp-document-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 13px;
}

.opp-document-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.opp-document-size {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: 8px;
}

/* EditorJS Overrides for Light Theme */
.codex-editor__redactor {
    padding-bottom: 150px !important;
}

.ce-block__content,
.ce-toolbar__content {
    max-width: 100%;
}

.ce-paragraph {
    color: var(--text);
    line-height: 1.6;
}

.ce-header {
    color: var(--text);
}

.ce-block--selected .ce-block__content {
    background: var(--primary-light);
}

.ce-toolbar__plus,
.ce-toolbar__settings-btn {
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
}

.ce-toolbar__plus:hover,
.ce-toolbar__settings-btn:hover {
    background: var(--surface-light);
}

.ce-inline-toolbar {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.ce-inline-tool {
    color: var(--text);
}

.ce-inline-tool:hover {
    background: var(--surface-light);
}

.ce-popover {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.ce-popover-item:hover {
    background: var(--surface-light);
}

.ce-popover-item__title {
    color: var(--text);
}

.cdx-checklist__item-checkbox {
    border-color: var(--border);
    background: var(--surface);
}

.cdx-checklist__item--checked .cdx-checklist__item-checkbox {
    background: var(--primary);
    border-color: var(--primary);
}

/* Editor Floating Toolbox */
.editor-floating-tools {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 260px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    z-index: 2100;
    user-select: none;
}

.editor-floating-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    cursor: move;
    font-weight: 500;
    font-size: 13px;
    background: var(--surface-light);
    border-radius: 8px 8px 0 0;
}

.editor-floating-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px;
}

.editor-floating-buttons button {
    padding: 8px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
    color: var(--text);
}

.editor-floating-buttons button:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.editor-floating-hint {
    font-size: 11px;
    color: var(--text-muted);
    padding: 0 12px 12px;
}

.drag-hint {
    font-size: 12px;
    color: var(--text-muted);
}

/* Pipeline Selector */
.pipeline-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.pipeline-tab {
    padding: 8px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
}

.pipeline-tab:hover {
    background: var(--surface-light);
}

.pipeline-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-header h1, .nav-item span, .user-details { display: none; }
    .nav-item { justify-content: center; padding: 16px; }
    .nav-item svg { margin-right: 0; }
    .main-content { margin-left: 60px; padding: 16px; }
    .form-row { grid-template-columns: 1fr; }
    .opp-fullscreen-body { flex-direction: column; }
    .opp-sidebar { width: 100%; max-height: 40vh; }
    .stage-editor { left: 60px; }
}
