/* === CarlCRM - Pico CSS Overrides === */

/* Brand link */
a.brand { text-decoration: none; color: inherit; }

/* Layout */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.page-header h1 { margin-bottom: 0; }

/* Company detail header */
.detail-page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.2rem;
}

.detail-kicker {
    margin: 0;
    color: var(--pico-muted-color);
    font-size: 0.9rem;
    font-weight: 600;
}

.detail-kicker-sub {
    margin-top: 0.15rem;
    color: var(--pico-muted-color);
}

/* Detail cards + field grid */
.detail-grid {
    display: grid;
    gap: 1rem;
}

.detail-card {
    padding: 1rem;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 10px;
    background: var(--pico-card-background-color);
    box-shadow: 0 1px 10px rgba(0, 0, 0, 0.03);
}

.detail-card + .detail-card { margin-top: 0; }

.detail-card-header h2 {
    margin-top: 0;
    margin-bottom: 0.6rem;
}

.kv-grid {
    display: grid;
    grid-template-columns: minmax(8rem, 12rem) 1fr;
    column-gap: 1rem;
    row-gap: 0.75rem;
    margin: 0;
}

.kv-grid > div {
    display: contents;
}

.kv-grid dt {
    color: var(--pico-muted-color);
    padding: 0.15rem 0;
    font-weight: 600;
}

.kv-grid dd {
    margin: 0;
    padding: 0.15rem 0;
    word-break: break-word;
}

.detail-notes {
    margin: 0;
    white-space: pre-wrap;
    line-height: 1.45;
}

.detail-empty {
    margin: 0;
    color: var(--pico-muted-color);
}

.contact-quick-link {
    display: inline-block;
    margin-right: 0.75rem;
    margin-bottom: 0.5rem;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    text-decoration: none;
    border: 1px solid var(--pico-muted-border-color);
    background: var(--pico-card-sectioning-background-color);
}

.contact-quick-link:hover {
    background: var(--pico-form-element-background-color);
}

/* Compact lists inside custom fields */
.compact-list {
    margin: 0;
    padding-left: 1.1rem;
}

/* Login */
.login-container { max-width: 420px; margin: 2rem auto; }
.error-message { color: var(--pico-del-color); font-weight: 600; }
.required { color: var(--pico-del-color); }

/* Tables: tight padding + sticky header */
.table-wrapper { overflow-x: auto; }
table th, table td { padding: 0.5rem 0.75rem; }
thead th { position: sticky; top: 0; background: var(--pico-card-background-color); z-index: 1; }
thead th a { text-decoration: none; white-space: nowrap; }
tbody tr:hover { background: var(--pico-card-sectioning-background-color); }

/* Action cells */
.actions { white-space: nowrap; }
.btn-small {
    display: inline-block; padding: 0.25rem 0.6rem; font-size: 0.8rem;
    border-radius: 4px; cursor: pointer; border: 1px solid var(--pico-primary);
    background: transparent; color: var(--pico-primary); text-decoration: none; line-height: 1.5;
}
.btn-small:hover { background: var(--pico-primary); color: #fff; }
.btn-danger { border-color: var(--pico-del-color); color: var(--pico-del-color); }
.btn-danger:hover { background: var(--pico-del-color); color: #fff; }

/* Badges (shared base) */
.badge {
    display: inline-block; padding: 0.15rem 0.5rem; border-radius: 12px;
    font-size: 0.78rem; font-weight: 600; line-height: 1.4; white-space: nowrap;
}

/* Deal stage badges */
.stage-lead        { background: #6b7280; color: #fff; }
.stage-contacted   { background: #3b82f6; color: #fff; }
.stage-qualified   { background: #06b6d4; color: #fff; }
.stage-proposal    { background: #f59e0b; color: #fff; }
.stage-negotiation { background: #8b5cf6; color: #fff; }
.stage-won         { background: #10b981; color: #fff; }
.stage-lost        { background: #ef4444; color: #fff; }

/* Task priority badges */
.priority-low    { background: #d1d5db; color: #374151; }
.priority-medium { background: #fbbf24; color: #374151; }
.priority-high   { background: #f97316; color: #fff; }
.priority-urgent { background: #ef4444; color: #fff; }

/* Task status badges */
.status-open        { background: #3b82f6; color: #fff; }
.status-in_progress { background: #8b5cf6; color: #fff; }
.status-done        { background: #10b981; color: #fff; }
.status-cancelled   { background: #6b7280; color: #fff; }

/* Interaction type badges */
.interaction-note    { background: #6b7280; color: #fff; }
.interaction-email   { background: #3b82f6; color: #fff; }
.interaction-call    { background: #10b981; color: #fff; }
.interaction-meeting { background: #8b5cf6; color: #fff; }

/* Overdue highlight */
.overdue { color: #ef4444; font-weight: 600; }

/* Dashboard stats */
.stat-number { font-size: 2.2rem; font-weight: 700; margin: 0.5rem 0; }
.stat-subtitle { display: block; color: var(--pico-muted-color); }
.stat-warning { color: #ef4444; }

/* Pipeline chart */
.pipeline-chart { display: flex; flex-direction: column; gap: 0.5rem; }
.pipeline-bar-wrapper { display: grid; grid-template-columns: 100px 1fr 90px; align-items: center; gap: 0.5rem; }
.pipeline-label { text-align: right; font-size: 0.85rem; font-weight: 500; }
.pipeline-bar-track { background: var(--pico-card-sectioning-background-color); border-radius: 4px; height: 1.6rem; overflow: hidden; }
.pipeline-bar {
    height: 100%; border-radius: 4px; min-width: 2rem;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 0.8rem; font-weight: 600;
}
.pipeline-value { font-size: 0.85rem; color: var(--pico-muted-color); }

/* Toast notifications */
.toast { position: relative; padding: 0.75rem 2.5rem 0.75rem 1rem; margin-bottom: 1rem; border-radius: 6px; animation: toast-in 0.3s ease-out; }
.toast-success { border-left: 4px solid #10b981; }
.toast-error   { border-left: 4px solid #ef4444; }
.toast-close {
    position: absolute; top: 0.5rem; right: 0.5rem; background: none; border: none;
    font-size: 1.1rem; cursor: pointer; padding: 0; margin: 0; width: auto; color: inherit;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* Search bar */
.search-bar { margin-bottom: 1rem; }
.search-bar input[type="search"] { margin-bottom: 0; }

/* Form actions */
.form-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }

/* Empty state */
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--pico-muted-color); }

/* Timeline */
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-day-header {
    font-size: 0.78rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--pico-muted-color);
    padding: 0.75rem 0 0.35rem; margin-top: 0.25rem;
    border-bottom: 2px solid var(--pico-primary);
}
.timeline-day-header:first-child { margin-top: 0; }
.timeline-event {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.5rem 0.25rem; border-bottom: 1px solid var(--pico-muted-border-color);
    transition: background 0.1s;
}
.timeline-event:last-child { border-bottom: none; }
.timeline-event-email:hover { background: rgba(21, 101, 192, 0.04); }
.timeline-badge { flex-shrink: 0; min-width: 2.5rem; text-align: center; }
.timeline-summary { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline-time { flex-shrink: 0; font-size: 0.78rem; color: var(--pico-muted-color); white-space: nowrap; }
.timeline-expand-icon {
    flex-shrink: 0; font-size: 0.7rem; color: var(--pico-muted-color);
    transition: transform 0.15s; width: 1rem; text-align: center;
}
.timeline-expand-icon.expanded { transform: rotate(0deg); }
.timeline-interaction { background: #3b82f6; color: #fff; }
.timeline-stage_change { background: #8b5cf6; color: #fff; }
.timeline-task { background: #f59e0b; color: #fff; }

/* Filter row (analytics) */
.filter-row { display: flex; gap: 1rem; align-items: end; margin-bottom: 1.5rem; }
.filter-row label { margin-bottom: 0; }
.filter-row input { margin-bottom: 0; }

/* Kanban Board */
.kanban-board {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.75rem;
    overflow-x: auto;
    min-height: 400px;
}

.kanban-column {
    display: flex;
    flex-direction: column;
    background: var(--pico-card-sectioning-background-color);
    border-radius: 8px;
    padding: 0.5rem;
    min-width: 200px;
}

.kanban-cards {
    flex: 1;
    min-height: 100px;
}

.kanban-column-header {
    text-align: center;
    padding: 0.5rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
}

.kanban-column-header small {
    display: block;
    font-weight: 400;
    font-size: 0.75rem;
    opacity: 0.85;
}

.kanban-card {
    background: var(--pico-card-background-color);
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 6px;
    padding: 0.6rem;
    margin-bottom: 0.5rem;
    cursor: grab;
    transition: box-shadow 0.15s;
}

.kanban-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.kanban-card .deal-title { font-weight: 600; font-size: 0.85rem; margin-bottom: 0.25rem; }
.kanban-card .deal-title a { text-decoration: none; }
.kanban-card .deal-meta { font-size: 0.78rem; color: var(--pico-muted-color); }
.kanban-card .deal-value { font-weight: 600; color: var(--pico-primary); font-size: 0.82rem; }

.kanban-move-btns { display: flex; gap: 0.25rem; margin-top: 0.4rem; }
.kanban-move-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.6rem; height: 1.6rem; border-radius: 4px; font-size: 0.75rem;
    border: 1px solid var(--pico-muted-border-color); background: transparent;
    cursor: pointer; padding: 0; line-height: 1;
}
.kanban-move-btn:hover { background: var(--pico-primary); color: #fff; border-color: var(--pico-primary); }

/* Filter Panel */
.filter-panel {
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 8px;
    padding: 0;
    margin-bottom: 1rem;
    background: var(--pico-card-background-color);
}

.filter-toggle {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.5rem 0.75rem; cursor: pointer; font-weight: 500; font-size: 0.9rem;
    border: none; background: none; width: 100%; text-align: left;
}

.filter-toggle:hover { background: var(--pico-card-sectioning-background-color); }

.filter-body {
    padding: 0.75rem;
    border-top: 1px solid var(--pico-muted-border-color);
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
    align-items: end;
}

.filter-grid label { font-size: 0.82rem; margin-bottom: 0.2rem; }
.filter-grid input, .filter-grid select { margin-bottom: 0; font-size: 0.85rem; }

.filter-actions { margin-top: 0.75rem; display: flex; gap: 0.5rem; }

/* CSV download link */
.csv-download {
    display: inline-flex; align-items: center; gap: 0.3rem;
    font-size: 0.82rem; text-decoration: none;
}

/* Pagination */
.pagination ul { display: flex; justify-content: center; gap: 0.25rem; list-style: none; padding: 0; margin: 1.5rem 0; }
.pagination a, .pagination span { padding: 0.4rem 0.75rem; font-size: 0.85rem; }
.pagination .disabled { opacity: 0.4; cursor: default; }

/* --- Email Timeline --- */
.timeline-email {
    background-color: #e3f2fd;
    color: #1565c0;
    font-size: 0.75rem;
}
.badge-sent {
    background-color: #e8f5e9 !important;
    color: #2e7d32 !important;
}

.timeline-event-email {
    border-left: 3px solid #1565c0;
    padding-left: 0.5rem;
}

.email-detail-container {
    margin: 0 0 0.5rem 2.5rem;
    padding: 0;
}

.email-detail {
    background: var(--pico-card-background-color);
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    padding: 1rem;
    font-size: 0.9em;
}

.email-detail header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.email-detail-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.email-meta {
    margin: 0.5rem 0;
    font-size: 0.85em;
}

.email-meta div {
    display: flex;
    gap: 0.5rem;
}

.email-meta dt {
    font-weight: 600;
    min-width: 3rem;
    color: var(--pico-muted-color);
}

.email-body {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--pico-code-background-color);
    border-radius: var(--pico-border-radius);
    max-height: 400px;
    overflow-y: auto;
}

.email-body pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
    font-size: 0.85em;
    background: transparent;
    padding: 0;
}

.email-snippet {
    color: var(--pico-muted-color);
    font-style: italic;
}

.email-attachments {
    margin-top: 0.75rem;
    font-size: 0.85em;
}

.email-attachments ul {
    margin: 0.25rem 0 0 1rem;
    padding: 0;
}

.email-detail-close {
    background: none; border: none; cursor: pointer;
    font-size: 1.2rem; line-height: 1; padding: 0.1rem 0.3rem;
    color: var(--pico-muted-color); border-radius: 4px;
}
.email-detail-close:hover { background: var(--pico-muted-border-color); color: var(--pico-color); }

.email-contacts {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--pico-muted-border-color);
}

/* --- Emails Tab --- */
.email-list-item {
    padding: 0.5rem 0.25rem;
    border-bottom: 1px solid var(--pico-muted-border-color);
    transition: background 0.1s;
}

.email-list-item:hover {
    background: rgba(21, 101, 192, 0.04);
}

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

.email-list-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.email-list-header .timeline-time {
    margin-left: auto;
}

.email-list-expand-icon {
    flex-shrink: 0; font-size: 0.7rem; color: var(--pico-muted-color);
    transition: transform 0.15s; width: 1rem; text-align: center;
}

.email-list-expand-icon.expanded { transform: rotate(0deg); }

.email-list-meta {
    margin: 0.15rem 0 0 1.75rem;
}

.email-list-snippet {
    margin: 0.15rem 0 0 1.75rem;
    color: var(--pico-muted-color);
    font-size: 0.85em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.badge-success {
    background-color: #c8e6c9;
    color: #2e7d32;
}

.badge-error {
    background-color: #ffcdd2;
    color: #c62828;
}

.badge-warning {
    background-color: #fff9c4;
    color: #f57f17;
}

.text-error {
    color: #c62828;
}

/* Patent confidence badges */
.patent-badge { font-size: 0.75rem; padding: 0.1rem 0.4rem; border-radius: 0.25rem; }
.patent-badge-high   { background: #d1fae5; color: #065f46; }
.patent-badge-medium { background: #fef3c7; color: #92400e; }
.patent-badge-low    { background: #f3f4f6; color: #374151; }
