/*
 * KD CRM — Application Styles
 *
 * All colors reference CSS custom properties set by theme.php.
 * To rebrand: change theme.php, not this file.
 */

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4 { font-family: var(--font-heading); font-weight: 600; color: var(--color-text); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }

img { max-width: 100%; }

/* ── Layout ───────────────────────────────────────────────── */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 20px;
}

.container-full {
    padding: 24px 20px;
}

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

.page-header h1 { margin: 0; }

/* ── Navbar ───────────────────────────────────────────────── */
.navbar {
    background: var(--color-primary);
    color: #fff;
    padding: 0 20px;
    display: flex;
    align-items: center;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    margin-right: 32px;
    text-decoration: none;
}

.navbar-brand img {
    height: 28px;
    width: auto;
}

.navbar-nav {
    display: flex;
    list-style: none;
    gap: 4px;
    flex: 1;
}

.navbar-nav a {
    color: rgba(255,255,255,0.8);
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.navbar-nav a:hover,
.navbar-nav a.active {
    color: #fff;
    background: rgba(255,255,255,0.15);
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.navbar-user {
    color: rgba(255,255,255,0.9);
    font-size: 0.8125rem;
}

.navbar-user strong { font-weight: 600; }

/* Admin producer dropdown in navbar */
.producer-switcher {
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.8125rem;
    cursor: pointer;
}

.producer-switcher option { color: #333; background: #fff; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 16px;
}

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

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    line-height: 1.4;
    font-family: inherit;
}

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

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

.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover { filter: brightness(0.9); }

.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.9); }

.btn-sm { padding: 4px 10px; font-size: 0.8125rem; }

.btn-icon {
    padding: 6px;
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: 4px;
}
.btn-icon:hover { background: var(--color-bg); color: var(--color-text); }

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

.form-group label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.875rem;
    font-family: inherit;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-secondary);
    box-shadow: 0 0 0 3px rgba(45, 109, 164, 0.1);
}

select.form-control { cursor: pointer; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
}

/* Inline edit fields */
.inline-edit {
    border: 1px solid transparent;
    padding: 4px 8px;
    border-radius: 4px;
    background: transparent;
    font-size: inherit;
    color: inherit;
    font-family: inherit;
    width: 100%;
}

.inline-edit:hover { border-color: var(--color-border); }
.inline-edit:focus {
    border-color: var(--color-secondary);
    outline: none;
    background: var(--color-surface);
}

/* ── Tables ───────────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    padding: 10px 12px;
    border-bottom: 2px solid var(--color-border);
    white-space: nowrap;
    cursor: pointer;
}

.data-table th:hover { color: var(--color-text); }

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.875rem;
}

.data-table tr:hover td { background: var(--color-bg); }

.data-table .clickable-row { cursor: pointer; }

/* ── Badges / Pills ───────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 12px;
    line-height: 1.4;
}

.badge-stage {
    color: #fff;
    /* Background set inline from stage color */
}

.badge-success { background: var(--color-success); color: #fff; }
.badge-danger  { background: var(--color-danger); color: #fff; }
.badge-warning { background: var(--color-warning); color: #fff; }
.badge-info    { background: var(--color-info); color: #fff; }
.badge-muted   { background: var(--color-border); color: var(--color-text-muted); }

/* ── Pipeline / Kanban ────────────────────────────────────── */
.pipeline-board {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 16px;
    min-height: calc(100vh - 180px);
    align-items: flex-start;
}

.pipeline-column {
    flex: 0 0 260px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 180px);
}

.pipeline-column-header {
    padding: 12px;
    border-bottom: 1px solid var(--color-border);
    border-radius: 8px 8px 0 0;
    position: sticky;
    top: 0;
    background: inherit;
    z-index: 1;
}

.pipeline-column-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.pipeline-column-count {
    background: rgba(0,0,0,0.08);
    color: var(--color-text-muted);
    font-size: 0.75rem;
    padding: 1px 8px;
    border-radius: 10px;
}

.pipeline-column-body {
    padding: 8px;
    flex: 1;
    overflow-y: auto;
    min-height: 60px;
}

.pipeline-column-footer {
    padding: 8px 12px;
    border-top: 1px solid var(--color-border);
    font-size: 0.75rem;
    color: var(--color-text-muted);
    background: var(--color-surface);
    border-radius: 0 0 8px 8px;
}

/* Deal cards inside pipeline columns */
.deal-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 8px;
    cursor: grab;
    transition: box-shadow 0.15s, border-color 0.15s;
    position: relative;
}

.deal-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    border-color: var(--color-secondary);
}

.deal-card.sortable-ghost {
    opacity: 0.4;
}

.deal-card.sortable-chosen {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.deal-card-title {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--color-text);
    margin-bottom: 4px;
    line-height: 1.3;
}

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

.deal-card-title a:hover { color: var(--color-secondary); }

.deal-card-meta {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.deal-card-amount {
    font-weight: 600;
    color: var(--color-text);
}

.deal-card-indicator {
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    border-radius: 6px 0 0 6px;
}

/* ── Tabs ─────────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--color-border);
    margin-bottom: 20px;
}

.tab {
    padding: 10px 20px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: inherit;
}

.tab:hover { color: var(--color-text); }

.tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Activity Timeline ────────────────────────────────────── */
.timeline {
    position: relative;
    padding-left: 24px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--color-border);
}

.timeline-item {
    position: relative;
    padding-bottom: 16px;
}

.timeline-dot {
    position: absolute;
    left: -20px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-border);
    border: 2px solid var(--color-surface);
}

.timeline-dot.email-open   { background: var(--color-info); }
.timeline-dot.email-click  { background: var(--color-success); }
.timeline-dot.page-view    { background: var(--color-accent); }
.timeline-dot.note         { background: var(--color-text-muted); }
.timeline-dot.stage-change { background: var(--color-primary); }

.timeline-time {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.timeline-body {
    font-size: 0.875rem;
}

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

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

.stat-card-label {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.stat-card-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
}

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

/* ── Flash Messages ───────────────────────────────────────── */
.flash {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 0.875rem;
}

.flash-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.flash-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.flash-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--color-surface);
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
}

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

.modal-header h3 { margin: 0; }

.modal-body { padding: 20px; }

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

/* ── Pagination ───────────────────────────────────────────── */
.pagination {
    display: flex;
    gap: 4px;
    align-items: center;
    margin-top: 20px;
    justify-content: center;
}

.pagination a, .pagination span {
    padding: 6px 12px;
    font-size: 0.8125rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text-muted);
}

.pagination a:hover { background: var(--color-bg); color: var(--color-text); }

.pagination .current {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

/* ── Search & Filters Bar ─────────────────────────────────── */
.filters-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.search-input {
    flex: 1;
    min-width: 200px;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.875rem;
    background: var(--color-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.656a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") no-repeat 12px center;
    font-family: inherit;
    color: var(--color-text);
}

.search-input:focus {
    outline: none;
    border-color: var(--color-secondary);
}

.filter-select {
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.875rem;
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    font-family: inherit;
}

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

.login-card {
    background: var(--color-surface);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
    text-align: center;
    margin-bottom: 24px;
}

.login-logo img { height: 40px; }

.login-title {
    text-align: center;
    font-size: 1.25rem;
    margin-bottom: 4px;
}

.login-subtitle {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    margin-bottom: 24px;
}

.login-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.875rem;
    margin-bottom: 16px;
}

/* ── Footer ───────────────────────────────────────────────── */
.app-footer {
    text-align: center;
    padding: 20px;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    border-top: 1px solid var(--color-border);
    margin-top: 40px;
}

/* ── Utility ──────────────────────────────────────────────── */
.text-muted { color: var(--color-text-muted); }
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-sm { font-size: 0.8125rem; }
.text-xs { font-size: 0.75rem; }
.font-bold { font-weight: 600; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none; }
.w-full { width: 100%; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .form-row { grid-template-columns: 1fr; }
    .form-row-3 { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .navbar-nav { display: none; }
    .pipeline-column { flex: 0 0 85vw; }
    .container { padding: 16px 12px; }
}
