:root {
    --sidebar-width: 260px;
    --sidebar-bg: #303030;
    --sidebar-logo-bg: #0c1117;
    --sidebar-hover: #34495e;
    --sidebar-active: var(--accent);
    --accent: #C2186A;
    --accent-hover: #9E1456;
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --text-muted: #95a5a6;
    --border: #ecf0f1;
    --bg-page: #f5f5f5;
    --bg-card: #fff;
    --radius: 8px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 2px 4px rgba(0,0,0,0.10);
    --shadow-md: 0 2px 12px rgba(0,0,0,0.08);
    --transition: 0.2s ease;
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    margin: 0;
    min-height: 100vh;
    font-size: 0.9375rem;
    -webkit-font-smoothing: antialiased;
}

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

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    color: #fff;
    z-index: 1040;
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    padding: 1.25rem 1.25rem;
    background: var(--sidebar-logo-bg);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
    color: #fff;
}

.brand-name {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    line-height: 1.2;
    color: var(--accent);
}

.sidebar-nav {
    flex: 1;
    padding: 0.5rem 0;
    overflow-y: auto;
}

.sidebar-nav .nav-label {
    padding: 0.85rem 1rem 0.4rem;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: rgba(255,255,255,0.25);
    font-weight: 500;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.6rem 1rem;
    margin: 1px 0.5rem;
    color: rgba(255,255,255,0.55);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 450;
    transition: all var(--transition);
    border-radius: var(--radius-sm);
    border-left: none;
}

.sidebar-nav a:hover {
    background: var(--sidebar-hover);
    color: rgba(255,255,255,0.9);
}

.sidebar-nav a.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 500;
}

.sidebar-nav a i {
    width: 20px;
    text-align: center;
    font-size: 0.95rem;
    opacity: 0.7;
}

.sidebar-nav a.active i {
    opacity: 1;
}

.sidebar-nav a .badge {
    margin-left: auto;
}

.sidebar-footer {
    padding: 0.65rem 1rem;
    border-top: 1px solid rgba(255,255,255,0.06);
    font-size: 0.75rem;
}

.sidebar-footer a {
    color: rgba(255,255,255,0.4);
    text-decoration: none;
    transition: color var(--transition);
}

.sidebar-footer a:hover {
    color: rgba(255,255,255,0.8);
}

/* Main content */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.top-bar {
    background: var(--bg-card);
    padding: 0 1.5rem;
    height: 58px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1030;
}

.top-bar .page-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.content-area {
    padding: 1.6rem 1.85rem;
}

/* Sidebar toggle for mobile */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.1rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1035;
    backdrop-filter: blur(2px);
}

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

.login-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 2.5rem;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.4);
}

.login-card .logo {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-card .logo img {
    height: 36px;
}

.login-card h2 {
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

/* Status badges */
.badge-active { background: #10b981; }
.badge-inactive { background: #94a3b8; }
.badge-lead { background: #f59e0b; color: #fff; }

/* Stat cards */
.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: box-shadow var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow);
}

.stat-card .stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
    margin-top: 0.15rem;
}

/* Tables */
.table-wrapper {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}

.table-wrapper .table {
    margin-bottom: 0;
    font-size: 0.875rem;
}

.table-wrapper .table th {
    background: #34495e;
    color: #fff;
    border-top: none;
    border-bottom: none !important;
    font-size: 0.78rem;
    letter-spacing: 0.3px;
    font-weight: 600;
    padding: 0.8rem 0.85rem;
}

.table-wrapper .table td {
    padding: 0.7rem 0.85rem;
    border-color: var(--border);
    vertical-align: middle;
}

.table-wrapper .table tbody tr {
    transition: background var(--transition);
}

.table-wrapper .table tbody tr:hover {
    background: #f8f9fa;
}

.table-actions a,
.table-actions button {
    padding: 0.2rem 0.45rem;
    font-size: 0.78rem;
    opacity: 0.5;
    transition: opacity var(--transition);
}

.table-wrapper .table tbody tr:hover .table-actions a,
.table-wrapper .table tbody tr:hover .table-actions button {
    opacity: 1;
}

/* Kanban board */
.kanban-board {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    padding-bottom: 1rem;
    min-height: 400px;
}

.kanban-column {
    flex: 1;
    min-width: 250px;
    max-width: 320px;
    background: rgba(0,0,0,0.02);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
}

.kanban-column-header {
    padding: 0.65rem 0.85rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.kanban-column-header .count {
    background: rgba(0,0,0,0.06);
    border-radius: 10px;
    padding: 0.1rem 0.45rem;
    font-size: 0.65rem;
    font-weight: 500;
}

.kanban-column[data-status="todo"] .kanban-column-header { border-bottom-color: #94a3b8; }
.kanban-column[data-status="in_progress"] .kanban-column-header { border-bottom-color: #6366f1; }
.kanban-column[data-status="waiting"] .kanban-column-header { border-bottom-color: #f59e0b; }
.kanban-column[data-status="done"] .kanban-column-header { border-bottom-color: #10b981; }

.kanban-cards {
    flex: 1;
    padding: 0.4rem;
    min-height: 80px;
    transition: background var(--transition);
}

.kanban-cards.drag-over,
.planner-day-cards.drag-over,
.planner-queue-cards.drag-over {
    background: rgba(194, 24, 106, 0.06);
}

.kanban-card {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.75rem;
    margin-bottom: 0.35rem;
    border: 1px solid var(--border);
    cursor: grab;
    transition: all var(--transition);
}

.kanban-card:hover {
    box-shadow: var(--shadow-md);
    border-color: #cbd5e1;
    transform: translateY(-1px);
}

.kanban-card.dragging {
    opacity: 0.4;
    transform: rotate(1.5deg);
}

.kanban-card .card-title {
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 0.3rem;
    color: var(--text-primary);
    line-height: 1.35;
}

.kanban-card .card-title a {
    color: inherit;
    text-decoration: none;
}

.kanban-card .card-title a:hover {
    color: var(--accent);
}

.kanban-card .card-meta {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.68rem;
    color: var(--text-muted);
}

.kanban-card .card-meta .badge {
    font-size: 0.58rem;
    font-weight: 500;
    padding: 0.2em 0.5em;
}

/* Priority badges */
.badge-high { background: #ef4444; }
.badge-medium { background: #f59e0b; }
.badge-low { background: #94a3b8; }

/* Project status badges */
.badge-completed { background: #10b981; }
.badge-on_hold { background: #f59e0b; color: #fff; }

/* View toggle */
.view-toggle .btn {
    padding: 0.25rem 0.55rem;
    font-size: 0.75rem;
}

.view-toggle .btn.active {
    background: var(--text-primary);
    color: #fff;
    border-color: var(--text-primary);
}

/* Quick add form */
.quick-add {
    padding: 0.4rem;
}

.quick-add input {
    font-size: 0.78rem;
    border: 1px dashed #cbd5e1;
    background: transparent;
}

.quick-add input:focus {
    border-style: solid;
    background: var(--bg-card);
}

/* Week Planner */
.planner-layout {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    min-height: calc(100vh - 160px);
}

.planner-queue {
    flex: 0 0 220px;
    min-width: 220px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
}

.planner-queue-header {
    padding: 0.6rem 0.75rem;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.planner-queue-cards {
    flex: 1;
    overflow-y: auto;
    padding: 0.35rem;
    min-height: 100px;
}

.planner-section-label {
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 0.5rem 0.4rem 0.2rem;
}

.planner-days {
    flex: 1;
    display: flex;
    gap: 0.5rem;
    min-width: 0;
}

.planner-day {
    flex: 1;
    min-width: 160px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
}

.planner-day-today {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

.planner-day-header {
    padding: 0.5rem 0.65rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.planner-day-name {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-primary);
}

.planner-day-date {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-left: 0.35rem;
}

.planner-day-today .planner-day-name {
    color: var(--accent);
}

.planner-day-hours {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-page);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}

.planner-day-cards {
    flex: 1;
    padding: 0.35rem;
    overflow-y: auto;
    min-height: 80px;
}

.planner-card {
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.6rem;
    margin-bottom: 0.3rem;
    cursor: grab;
    transition: all var(--transition);
    font-size: 0.78rem;
}

.planner-card:hover {
    box-shadow: var(--shadow-md);
    border-color: #cbd5e1;
    transform: translateY(-1px);
}

.planner-card.dragging {
    opacity: 0.35;
}

.planner-card-title {
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.3;
    font-size: 0.76rem;
}

.planner-card-est {
    font-size: 0.65rem;
    color: var(--text-muted);
    white-space: nowrap;
    margin-left: 0.5rem;
}

.planner-card-meta {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.25rem;
    font-size: 0.62rem;
    color: var(--text-muted);
}

.planner-card-meta .badge {
    font-size: 0.55rem;
    padding: 0.15em 0.4em;
}

@media (max-width: 991.98px) {
    .planner-layout {
        flex-direction: column;
    }
    .planner-queue {
        flex: none;
        max-height: 200px;
    }
    .planner-days {
        overflow-x: auto;
    }
}

/* Task side panel */
.task-panel-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.25);
    z-index: 1045;
    backdrop-filter: blur(2px);
}

.task-panel-overlay.show {
    display: block;
}

.task-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 520px;
    max-width: 92vw;
    height: 100vh;
    background: var(--bg-card);
    z-index: 1050;
    transform: translateX(100%);
    transition: transform 0.2s ease;
    display: flex;
    flex-direction: column;
    box-shadow: -8px 0 30px rgba(0,0,0,0.12);
}

.task-panel.show {
    transform: translateX(0);
}

.task-panel-header {
    padding: 0.85rem 1.15rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-page);
    font-size: 0.82rem;
}

.task-panel-header .close-panel {
    background: none;
    border: none;
    font-size: 1rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all var(--transition);
}

.task-panel-header .close-panel:hover {
    background: var(--border);
    color: var(--text-primary);
}

.task-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.15rem;
}

.task-panel-body .form-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

/* Harvest - brand color #fa5d00 */
.btn-harvest {
    background: #fa5d00;
    color: #fff;
    border-color: #fa5d00;
}

.btn-harvest:hover {
    background: #e05300;
    color: #fff;
    border-color: #e05300;
}

.btn-outline-harvest {
    color: #fa5d00;
    border-color: #fa5d00;
}

.btn-outline-harvest:hover {
    background: #fa5d00;
    color: #fff;
}

.harvest-task-timer {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.harvest-task-timer .btn {
    padding: 0.15rem 0.4rem;
    font-size: 0.72rem;
    line-height: 1;
}

#globalTimer.harvest-running {
    background: #fa5d00 !important;
    cursor: pointer;
}

/* Forms - tighter */
.form-control, .form-select {
    font-size: 0.875rem;
    border-color: var(--border);
    border-radius: var(--radius-sm);
}

.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(194, 24, 106, 0.12);
}

.form-control-sm, .form-select-sm {
    font-size: 0.82rem;
    padding: 0.32rem 0.65rem;
}

.form-label {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}

.form-text {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* Buttons - refined */
.btn {
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.btn-sm {
    font-size: 0.8rem;
    padding: 0.32rem 0.7rem;
}

.btn-dark {
    background: var(--text-primary);
    border-color: var(--text-primary);
}

.btn-dark:hover {
    background: #0f0f1a;
    border-color: #0f0f1a;
}

.btn-outline-secondary {
    color: var(--text-secondary);
    border-color: var(--border);
}

.btn-outline-secondary:hover {
    background: var(--bg-page);
    color: var(--text-primary);
    border-color: #cbd5e1;
}

/* Primary buttons follow the accent */
.btn-primary {
    background-color: var(--accent);
    border-color: var(--accent);
}

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

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

.btn-outline-primary:hover {
    background-color: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* Badges - refined */
.badge {
    font-weight: 500;
    font-size: 0.72rem;
    padding: 0.3em 0.65em;
    border-radius: 4px;
    letter-spacing: 0.2px;
}

/* Alerts */
.alert {
    font-size: 0.82rem;
    border-radius: var(--radius-sm);
    border: none;
    padding: 0.65rem 1rem;
}

/* List groups */
.list-group-item {
    border-color: var(--border);
    font-size: 0.875rem;
    padding: 0.65rem 0.9rem;
}

/* Progress bars */
.progress {
    border-radius: 3px;
    background: var(--border);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Responsive */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar-overlay.show {
        display: block;
    }

    .sidebar-toggle {
        display: inline-block;
    }

    .main-content {
        margin-left: 0;
    }
}

@media (max-width: 575.98px) {
    .content-area {
        padding: 0.85rem;
    }

    .login-card {
        margin: 1rem;
        padding: 1.5rem;
    }

    .kanban-column {
        min-width: 220px;
    }
}

/* ─── CRM Assistant ───────────────────────────────────────── */

.assistant-fab {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    font-size: 1.15rem;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
    transition: all 0.2s ease;
    z-index: 1060;
    display: flex;
    align-items: center;
    justify-content: center;
}

.assistant-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.5);
}

.assistant-panel {
    position: fixed;
    bottom: 4.5rem;
    right: 1.25rem;
    width: 400px;
    max-width: calc(100vw - 2rem);
    height: 520px;
    max-height: calc(100vh - 6rem);
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(0,0,0,0.15);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 1060;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px) scale(0.97);
    transition: all 0.2s ease;
}

.assistant-panel.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.assistant-header {
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-page);
    border-radius: var(--radius) var(--radius) 0 0;
    font-size: 0.82rem;
}

.assistant-header-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem 0.4rem;
    border-radius: 4px;
    font-size: 0.8rem;
    transition: all var(--transition);
}

.assistant-header-btn:hover {
    background: var(--border);
    color: var(--text-primary);
}

.assistant-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.assistant-msg {
    display: flex;
    max-width: 88%;
}

.assistant-msg-user {
    align-self: flex-end;
}

.assistant-msg-bot {
    align-self: flex-start;
}

.assistant-msg-content {
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    font-size: 0.8rem;
    line-height: 1.5;
    word-break: break-word;
}

.assistant-msg-user .assistant-msg-content {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.assistant-msg-bot .assistant-msg-content {
    background: var(--bg-page);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.assistant-msg-bot .assistant-msg-content ul {
    font-size: 0.76rem;
}

.assistant-msg-bot .assistant-msg-content code {
    background: rgba(0,0,0,0.06);
    padding: 0.1em 0.3em;
    border-radius: 3px;
    font-size: 0.75rem;
}

.assistant-msg-error .assistant-msg-content {
    background: #fef2f2;
    color: #b91c1c;
    border-color: #fecaca;
}

.assistant-input-area {
    padding: 0.65rem 0.75rem;
    border-top: 1px solid var(--border);
    background: var(--bg-page);
    border-radius: 0 0 var(--radius) var(--radius);
}

.assistant-input-area .form-control {
    font-size: 0.8rem;
    border-radius: 8px;
}

.assistant-input-area .btn {
    border-radius: 8px;
    padding: 0.3rem 0.6rem;
}

/* Typing animation */
.typing-dots span {
    animation: typingBounce 1.2s infinite;
    display: inline-block;
    font-size: 1.4rem;
    line-height: 0.5;
    font-weight: bold;
    color: var(--text-muted);
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

@media (max-width: 575.98px) {
    .assistant-panel {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        max-width: 100vw;
        border-radius: 0;
    }

    .assistant-header { border-radius: 0; }
    .assistant-input-area { border-radius: 0; }

    .assistant-fab {
        bottom: 1rem;
        right: 1rem;
    }
}
