/* ============================================================
   SILIENT CRM — Design System
   ============================================================ */

:root {
    --primary-dark: #1F2C10;
    --gold: #C8A862;
    --gold-hover: #b89a55;
    --gold-light: rgba(200,168,98,0.12);
    --bg: #FFFAF2;
    --card-bg: #FFFFFF;
    --muted: #6D6762;
    --muted-light: #9B9590;
    --border: #e0dcd6;
    --error: #d44;
    --success: #2a7d2a;
    --warning: #d4a017;
    --radius-card: 8px;
    --radius-input: 6px;
    --radius-badge: 4px;
    --font-heading: 'Gilda Display', serif;
    --font-body: 'Lato', sans-serif;
    --sidebar-width: 260px;
    --sidebar-collapsed: 60px;
    --topbar-height: 56px;
}

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

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--primary-dark);
    font-size: 14px;
    line-height: 1.5;
    overflow-x: hidden;
}

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

/* ── Login ───────────────────────────────────── */
.login-container {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: var(--primary-dark);
}
.login-card {
    background: var(--card-bg); padding: 48px 40px; border-radius: 12px;
    width: 100%; max-width: 400px; box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.login-logo {
    font-family: var(--font-heading); font-size: 32px; text-align: center;
    color: var(--primary-dark); letter-spacing: 3px;
}
.login-subtitle {
    text-align: center; color: var(--muted); margin: 4px 0 32px; font-size: 14px;
}
.app-menu-btn {
    display: flex; align-items: center; gap: 16px; padding: 20px;
    background: var(--bg); border-radius: var(--radius-card);
    border: 2px solid transparent; transition: border-color 0.2s;
    color: var(--primary-dark);
}
.app-menu-btn:hover { border-color: var(--gold); background: var(--gold-light); }
.app-menu-icon { font-size: 28px; }

/* ── Forms ───────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-size: 12px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--muted); margin-bottom: 6px;
}
input, select, textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-input); font-family: var(--font-body);
    font-size: 14px; background: #fff; color: var(--primary-dark);
    transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-light);
}
textarea { resize: vertical; min-height: 80px; }
.form-error { color: var(--error); font-size: 13px; margin-top: 8px; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }
.form-inline { display: flex; gap: 8px; align-items: flex-end; }

/* ── Buttons ─────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 20px; border: none; border-radius: var(--radius-input);
    font-family: var(--font-body); font-size: 14px; font-weight: 600;
    cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.btn-primary { background: var(--gold); color: var(--primary-dark); }
.btn-primary:hover { background: var(--gold-hover); }
.btn-secondary { background: var(--primary-dark); color: #fff; }
.btn-secondary:hover { background: #2a3b15; }
.btn-outline {
    background: transparent; border: 1px solid var(--border); color: var(--primary-dark);
}
.btn-outline:hover { border-color: var(--gold); color: var(--gold); }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #c33; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; }
.btn-link {
    background: none; border: none; color: var(--gold); cursor: pointer;
    font-family: var(--font-body); font-size: 14px;
}
.btn-link:hover { color: var(--gold-hover); }
.btn-icon {
    background: none; border: none; cursor: pointer; font-size: 18px;
    padding: 6px; border-radius: 50%; transition: background 0.2s;
}
.btn-icon:hover { background: var(--gold-light); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; }

/* ── Sidebar ─────────────────────────────────── */
.sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: var(--sidebar-width); background: var(--primary-dark);
    color: #fff; display: flex; flex-direction: column;
    z-index: 100; transition: width 0.2s;
    overflow-y: auto; overflow-x: hidden;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .nav-text,
.sidebar.collapsed .sub-nav,
.sidebar.collapsed .sidebar-logo { display: none; }
.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 16px; border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo {
    font-family: var(--font-heading); font-size: 22px;
    letter-spacing: 3px; color: var(--gold);
}
.sidebar-toggle {
    background: none; border: none; color: #fff; font-size: 20px;
    cursor: pointer; padding: 4px;
}
.sidebar-nav { list-style: none; padding: 12px 0; flex: 1; }
.sidebar-nav > li > a {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 20px; color: rgba(255,255,255,0.7);
    transition: all 0.2s; font-size: 14px;
}
.sidebar-nav > li > a:hover,
.sidebar-nav > li > a.active {
    color: #fff; background: rgba(200,168,98,0.15);
}
.sidebar-nav > li > a.active { border-right: 3px solid var(--gold); }
.nav-icon { font-size: 18px; width: 24px; text-align: center; flex-shrink: 0; }
.sub-nav {
    list-style: none; padding-left: 56px; max-height: 0; overflow: hidden;
    transition: max-height 0.3s;
}
.has-sub.open .sub-nav { max-height: 200px; }
.sub-nav a {
    display: block; padding: 6px 12px; color: rgba(255,255,255,0.5);
    font-size: 13px; transition: color 0.2s;
}
.sub-nav a:hover, .sub-nav a.active { color: var(--gold); }
.sidebar-footer {
    padding: 12px 0; border-top: 1px solid rgba(255,255,255,0.1);
}
.sidebar-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 20px; color: rgba(255,255,255,0.5); font-size: 13px;
}
.sidebar-link:hover { color: var(--gold); }
.admin-only { display: none; }
body.role-admin .admin-only { display: block; }

/* ── Main Content ────────────────────────────── */
#main-content {
    margin-left: var(--sidebar-width); min-height: 100vh;
    transition: margin-left 0.2s;
}
.sidebar.collapsed ~ #main-content { margin-left: var(--sidebar-collapsed); }
.topbar {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; height: var(--topbar-height);
    background: var(--card-bg); border-bottom: 1px solid var(--border);
}
.page-title { font-family: var(--font-heading); font-size: 20px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.user-name { font-size: 14px; color: var(--muted); }
.view-container { padding: 24px; }

/* ── Tables ──────────────────────────────────── */
.table-container { overflow-x: auto; }
table.data-table {
    width: 100%; border-collapse: collapse; background: var(--card-bg);
    border-radius: var(--radius-card); overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.data-table thead { background: var(--primary-dark); color: #fff; }
.data-table th {
    padding: 12px 16px; text-align: left; font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;
    white-space: nowrap; cursor: pointer; user-select: none;
}
.data-table th:hover { background: rgba(255,255,255,0.1); }
.data-table th .sort-arrow { margin-left: 4px; opacity: 0.5; }
.data-table th.sorted .sort-arrow { opacity: 1; color: var(--gold); }
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
.data-table tbody tr { transition: background 0.15s; cursor: pointer; }
.data-table tbody tr:hover { background: var(--gold-light); }
.data-table tbody tr.highlighted { background: rgba(200,168,98,0.08); }
.data-table .checkbox-col { width: 40px; text-align: center; }
.data-table input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* ── Badges ──────────────────────────────────── */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: var(--radius-badge);
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;
}
.badge-raw { background: #e8e4de; color: var(--muted); }
.badge-prospecting1 { background: #d4e8ff; color: #1a5fa8; }
.badge-prospecting2 { background: #c8e6ff; color: #1565c0; }
.badge-quoted { background: var(--gold-light); color: #8a6d1b; }
.badge-ordered { background: #d4edda; color: #155724; }
.badge-not-ordering { background: #f5d0d0; color: #8b2020; }
.badge-active { background: #d4edda; color: #155724; }
.badge-draft { background: #e8e4de; color: var(--muted); }
.badge-paused { background: #fff3cd; color: #856404; }
.badge-new { background: var(--gold-light); color: #8a6d1b; }
.badge-sent { background: #d4e8ff; color: #1565c0; }
.badge-viewed { background: #e8f5e9; color: #2e7d32; }
.badge-confirmed { background: #d4edda; color: #155724; }

.priority-stars { color: var(--gold); letter-spacing: 2px; }

/* ── Cards & Stats ───────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--card-bg); padding: 20px; border-radius: var(--radius-card);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06); border-left: 4px solid var(--gold);
}
.stat-card .stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 4px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--primary-dark); }
.stat-card .stat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.card {
    background: var(--card-bg); border-radius: var(--radius-card);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06); 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(--border);
}
.card-header h3 { font-family: var(--font-heading); font-size: 16px; }

/* ── Filter Bar ──────────────────────────────── */
.filter-bar {
    display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
    margin-bottom: 20px; padding: 16px; background: var(--card-bg);
    border-radius: var(--radius-card); box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.filter-bar .form-group { margin-bottom: 0; min-width: 140px; }
.filter-bar input, .filter-bar select { padding: 8px 10px; font-size: 13px; }

/* ── Bulk Action Bar ─────────────────────────── */
.bulk-bar {
    display: none; align-items: center; gap: 12px; padding: 12px 16px;
    background: var(--primary-dark); color: #fff; border-radius: var(--radius-card);
    margin-bottom: 12px;
}
.bulk-bar.visible { display: flex; }
.bulk-bar .bulk-count { font-weight: 600; margin-right: 8px; }
.bulk-bar .btn { padding: 6px 12px; font-size: 12px; }

/* ── Pagination ──────────────────────────────── */
.pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 8px; margin-top: 20px;
}
.pagination button {
    padding: 6px 12px; border: 1px solid var(--border); background: var(--card-bg);
    border-radius: var(--radius-input); cursor: pointer; font-size: 13px;
}
.pagination button:hover { border-color: var(--gold); }
.pagination button.active { background: var(--gold); color: var(--primary-dark); border-color: var(--gold); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Tabs ────────────────────────────────────── */
.tabs {
    display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px;
}
.tab-btn {
    padding: 10px 20px; border: none; background: none; cursor: pointer;
    font-family: var(--font-body); font-size: 14px; color: var(--muted);
    border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.2s;
}
.tab-btn:hover { color: var(--primary-dark); }
.tab-btn.active { color: var(--gold); border-bottom-color: var(--gold); font-weight: 600; }

/* ── Drawer (Detail Panel) ───────────────────── */
.drawer-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.3); z-index: 200;
}
.drawer {
    position: fixed; top: 0; right: 0; bottom: 0; width: 520px;
    background: var(--card-bg); box-shadow: -4px 0 16px rgba(0,0,0,0.1);
    overflow-y: auto; padding: 24px; z-index: 201;
    animation: slideIn 0.2s ease;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.drawer-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.drawer-header h2 { font-family: var(--font-heading); font-size: 20px; }
.drawer-close {
    background: none; border: none; font-size: 24px; cursor: pointer;
    color: var(--muted); padding: 4px;
}

/* ── Modal ───────────────────────────────────── */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4); z-index: 300;
    display: flex; align-items: center; justify-content: center;
}
.modal-content {
    background: var(--card-bg); border-radius: 12px; padding: 32px;
    max-width: 600px; width: 90%; max-height: 90vh; overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { transform: scale(0.95); opacity:0; } to { transform: scale(1); opacity:1; } }
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
}
.modal-header h2 { font-family: var(--font-heading); font-size: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }

/* ── Toast ───────────────────────────────────── */
.toast-container {
    position: fixed; bottom: 24px; right: 24px; z-index: 500;
    display: flex; flex-direction: column; gap: 8px;
}
.toast {
    padding: 12px 20px; border-radius: var(--radius-card);
    color: #fff; font-size: 14px; animation: toastIn 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15); max-width: 400px;
}
@keyframes toastIn { from { transform: translateX(100%); opacity:0; } to { transform: translateX(0); opacity:1; } }
.toast-success { background: var(--success); }
.toast-error { background: var(--error); }
.toast-info { background: var(--gold); color: var(--primary-dark); }

/* ── Search Overlay ──────────────────────────── */
.search-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 400;
    display: flex; align-items: flex-start; justify-content: center;
    padding-top: 15vh;
}
.search-modal {
    background: var(--card-bg); border-radius: 12px;
    width: 90%; max-width: 600px; box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    overflow: hidden;
}
.search-modal input {
    border: none; border-bottom: 1px solid var(--border);
    border-radius: 0; padding: 16px 20px; font-size: 16px;
}
.search-modal input:focus { box-shadow: none; }
.search-results { max-height: 50vh; overflow-y: auto; }
.search-result {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 20px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.search-result:hover { background: var(--gold-light); }
.search-result .type-badge {
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    padding: 2px 6px; border-radius: 3px; background: var(--primary-dark); color: #fff;
}
.search-hint { padding: 8px 20px; font-size: 12px; color: var(--muted); text-align: right; }

/* ── Skeleton Loader ─────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, #e8e4de 25%, #f0ece6 50%, #e8e4de 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-input);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-text { height: 14px; margin-bottom: 8px; width: 80%; }
.skeleton-text.short { width: 40%; }
.skeleton-row { display: flex; gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.skeleton-cell { height: 16px; flex: 1; }

/* ── Notes (Amendment A) ─────────────────────── */
.notes-container { margin-top: 16px; }
.note-add { margin-bottom: 20px; }
.note-add-header {
    display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
}
.note-add-header strong { font-size: 14px; }
.note-add-header .note-stamp { color: var(--muted); font-size: 12px; font-style: italic; }
.note-textarea {
    width: 100%; min-height: 60px; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: var(--radius-input);
    font-family: var(--font-body); font-size: 14px; resize: none;
    overflow: hidden;
}
.note-textarea:focus { border-color: var(--gold); outline: none; box-shadow: 0 0 0 3px var(--gold-light); }
.note-item {
    padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.note-item:nth-child(even) { background: #faf8f4; }
.note-header {
    display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
}
.note-initials {
    font-weight: 700; color: var(--gold);
}
.note-initials.import { color: var(--muted-light); }
.note-timestamp { color: var(--muted); font-size: 12px; }
.note-body { font-size: 14px; line-height: 1.6; }
.note-body.collapsed { max-height: 120px; overflow: hidden; position: relative; }
.note-body.collapsed::after {
    content: ''; position: absolute; bottom: 0; left: 0; right: 0;
    height: 40px; background: linear-gradient(transparent, var(--card-bg));
}
.note-show-more { color: var(--gold); cursor: pointer; font-size: 13px; margin-top: 4px; }
.note-highlight { animation: noteGlow 2s ease-out; }
@keyframes noteGlow {
    0% { background: var(--gold-light); }
    100% { background: transparent; }
}

/* ── Timeline ────────────────────────────────── */
.timeline { list-style: none; }
.timeline-item {
    display: flex; gap: 12px; padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.timeline-icon { font-size: 16px; width: 24px; text-align: center; flex-shrink: 0; padding-top: 2px; }
.timeline-content { flex: 1; }
.timeline-summary { font-size: 14px; }
.timeline-time { font-size: 12px; color: var(--muted); }

/* ── Dashboard Grid ──────────────────────────── */
.dashboard-grid {
    display: grid; grid-template-columns: 1fr 1fr 1fr;
    gap: 20px; margin-top: 20px;
}
.dashboard-grid .card { min-height: 300px; }
.dashboard-grid .card.full-width { grid-column: 1 / -1; }

/* ── Quote Builder ───────────────────────────── */
.quote-builder { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.line-items-editor { }
.line-item-row {
    display: grid; grid-template-columns: 2fr 60px 100px 100px 40px;
    gap: 8px; align-items: center; padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.line-item-row input { padding: 6px 8px; font-size: 13px; }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed; bottom: 0; left: 0; right: 0; top: auto;
        width: 100% !important; height: 60px; flex-direction: row;
        overflow: visible;
    }
    .sidebar-header, .sidebar-footer, .sub-nav, .nav-text { display: none !important; }
    .sidebar-nav {
        display: flex; flex-direction: row; align-items: center;
        justify-content: space-around; width: 100%; padding: 0;
    }
    .sidebar-nav > li > a { padding: 8px; flex-direction: column; font-size: 10px; gap: 2px; }
    .sidebar-nav .has-sub > .sub-nav { display: none !important; }
    .admin-only { display: none !important; }
    #main-content { margin-left: 0 !important; margin-bottom: 60px; }
    .drawer { width: 100% !important; }
    .quote-builder { grid-template-columns: 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .stats-row { grid-template-columns: 1fr 1fr; }
    .filter-bar { flex-direction: column; }
    .form-row { flex-direction: column; }
    .topbar { padding: 0 12px; }
    .view-container { padding: 12px; }
}

/* ── Utility ─────────────────────────────────── */
.muted { color: var(--muted); }
.text-gold { color: var(--gold); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amber-row { background: #fff3cd !important; }
.gold-row { background: var(--gold-light) !important; }
.empty-state {
    text-align: center; padding: 48px 20px; color: var(--muted);
}
.empty-state p { font-size: 16px; margin-bottom: 16px; }
