/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f4f5f9;
    color: #1f2430;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; height: 65px}
button { font-family: inherit; cursor: pointer; }
h1, h2, h3, h4 { margin: 0 0 0.5em; line-height: 1.25; }
input, select, textarea, button {
    font-family: inherit;
    font-size: 0.95rem;
}

:root {
    --indigo: #180f4c;
    --indigo-dark: #4338ca;
    --green: #22c55e;
    --red: #ef4444;
    --amber: #f59e0b;
    --border: #e3e5ec;
    --card-bg: #ffffff;
    --muted: #6b7280;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16,24,40,0.06), 0 1px 3px rgba(16,24,40,0.08);
}

/* ---------- App shell ---------- */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 0.65rem 1.25rem;
    position: sticky;
    top: 0;
    z-index: 50;
}
.brand { font-weight: 700; font-size: 1.05rem; color: #1f2430; white-space: nowrap; display: flex; align-items: center; }
.brand span { color: var(--indigo); }
.brand-logo { height: 65px; width: auto; display: block; }
.nav-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1.1rem;
    padding: 0.35rem 0.6rem;
}
.topnav { display: flex; gap: 0.25rem; flex: 1; padding-left:50px; }
.topnav a {
    padding: 0.5rem 0.9rem;
    border-radius: 8px;
    font-weight: 500;
    color: var(--muted);
}
.topnav a:hover { background: #f1f2f8; color: #1f2430; }
.topnav a.active { background: #eef0fe; color: var(--indigo-dark); }

.user-menu { display: flex; align-items: center; gap: 0.6rem; margin-left: auto; }
.avatar {
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 0.8rem; flex-shrink: 0;
}
.user-name { font-weight: 600; font-size: 0.9rem; white-space: nowrap; }
.logout-link { color: var(--muted); font-size: 0.85rem; border-left: 1px solid var(--border); padding-left: 0.6rem; }
.logout-link:hover { color: var(--red); }

.notif-bell { position: relative; font-size: 1.15rem; line-height: 1; padding: 0.3rem; border-radius: 8px; }
.notif-bell:hover { background: #f1f2f8; }
.notif-badge {
    position: absolute; top: -2px; right: -2px;
    background: var(--red); color: #fff; font-size: 0.65rem; font-weight: 700;
    min-width: 16px; height: 16px; border-radius: 20px; padding: 0 3px;
    display: flex; align-items: center; justify-content: center; line-height: 1;
}

.app-main { flex: 1; padding: 1.25rem; max-width: 1650px; width: 100%; margin: 0 auto; }

/* ---------- Flash messages ---------- */
.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-weight: 500;
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
}
.flash-success { background: #ecfdf3; color: #067647; border: 1px solid #abefc6; }
.flash-error { background: #fef3f2; color: #b42318; border: 1px solid #fecdca; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border-radius: 8px;
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 0.9rem;
    background: var(--indigo);
    color: #fff;
    transition: background 0.15s ease;
}
.btn:hover { background: var(--indigo-dark); }
.btn-secondary { background: #fff; color: #1f2430; border-color: var(--border); }
.btn-secondary:hover { background: #f4f5f9; }
.btn-danger { background: #fff; color: var(--red); border-color: #fecdca; }
.btn-danger:hover { background: #fef3f2; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Cards / panels ---------- */
.panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}

/* ---------- Page header row ---------- */
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.page-head h1 { font-size: 1.4rem; }

/* ---------- Auth pages ---------- */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, #eef0fe 0%, #f4f5f9 60%);
}
.auth-box {
    width: 100%;
    max-width: 380px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 2rem;
}
.auth-box h1 { font-size: 1.3rem; text-align: center; }
.auth-box .brand-sub { text-align: center; color: var(--muted); font-size: 0.85rem; margin-bottom: 1.5rem; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 0.35rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=file], select, textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: #1f2430;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--indigo);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
textarea { resize: vertical; min-height: 90px; }
.hint { font-size: 0.78rem; color: var(--muted); margin-top: 0.3rem; }

/* ---------- Kanban board ---------- */
.board-scroll {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    padding-bottom: 1rem;
    -webkit-overflow-scrolling: touch;
}
.stage-col {
    flex: 0 0 280px;
    background: #eceef5;
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 160px);
}
.stage-col.drag-over { background: #dfe2f5; outline: 2px dashed var(--indigo); }
.stage-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.85rem 0.9rem 0.6rem;
    font-weight: 700;
    font-size: 0.9rem;
}
.stage-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.stage-count { margin-left: auto; background: #fff; border-radius: 20px; padding: 0.1rem 0.55rem; font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.stage-value { padding: 0 0.9rem 0.6rem; font-size: 0.78rem; color: var(--muted); margin-top: -0.4rem; }
.stage-cards { padding: 0 0.6rem 0.6rem; overflow-y: auto; flex: 1; }

.lead-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 0.75rem 0.85rem;
    margin-bottom: 0.6rem;
    box-shadow: var(--shadow);
    cursor: grab;
}
.lead-card:active { cursor: grabbing; }
.lead-card.dragging { opacity: 0.4; }
.lead-card h4 { font-size: 0.92rem; margin-bottom: 0.15rem; }
.lead-card .lead-company { font-size: 0.78rem; color: var(--muted); margin-bottom: 0.5rem; }
.lead-card .lead-meta { display: flex; align-items: center; justify-content: space-between; font-size: 0.78rem; }
.lead-value { font-weight: 700; color: #067647; }
.lead-owner { width: 22px; height: 22px; border-radius: 50%; color: #fff; font-size: 0.65rem; font-weight: 700; display: flex; align-items: center; justify-content: center; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; }
th, td { padding: 0.7rem 0.9rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.88rem; white-space: nowrap; }
th { background: #f9fafc; font-weight: 700; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbff; }

.badge { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.2rem 0.6rem; border-radius: 20px; font-size: 0.75rem; font-weight: 700; color: #fff; }

/* ---------- Filters bar ---------- */
.filters { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; min-width: 160px; }

/* ---------- Client detail ---------- */
.detail-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.25rem; align-items: start; }
.info-list { list-style: none; margin: 0; padding: 0; }
.info-list li { display: flex; justify-content: space-between; padding: 0.5rem 0; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
.info-list li:last-child { border-bottom: none; }
.info-list .label { color: var(--muted); }

.activity-item { display: flex; gap: 0.75rem; padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: none; }
.activity-icon { width: 30px; height: 30px; border-radius: 50%; background: #eef0fe; color: var(--indigo-dark); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 0.85rem; }
.activity-body { flex: 1; }
.activity-meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }

.attachment-row { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.attachment-row:last-child { border-bottom: none; }

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

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15,17,26,0.5);
    display: none; align-items: center; justify-content: center; padding: 1rem; z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal-box { background: #fff; border-radius: 12px; padding: 1.5rem; width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto; }
.modal-close { float: right; background: none; border: none; font-size: 1.2rem; color: var(--muted); }

/* ---------- Product catalog ---------- */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}
.product-card { display: flex; flex-direction: column; }
.product-inactive { opacity: 0.6; }
.product-card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.product-card-head h4 { margin: 0; font-size: 1rem; }
.product-price { font-weight: 700; color: var(--indigo-dark); font-size: 1.1rem; margin: 0.25rem 0 0.6rem; }
.product-desc { font-size: 0.85rem; color: var(--muted); margin: 0 0 0.6rem; }
.product-features { margin: 0 0 0.6rem; padding-left: 1.1rem; font-size: 0.82rem; }
.product-features li { margin-bottom: 0.2rem; }

/* ---------- Tasks ---------- */
.task-row {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--border);
}
.task-row:last-child { border-bottom: none; }
.task-checkbox-form { flex-shrink: 0; margin-top: 0.15rem; }
.task-check {
    width: 20px; height: 20px; border-radius: 6px;
    border: 2px solid var(--border); background: #fff; padding: 0; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.task-check.checked { background: var(--green); border-color: var(--green); }
.task-check.checked::after { content: '✓'; color: #fff; font-size: 0.75rem; font-weight: 700; }
.task-body { flex: 1; min-width: 0; }
.task-title-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.task-title { font-weight: 600; }
.task-title.task-done { text-decoration: line-through; color: var(--muted); }
.task-desc { font-size: 0.85rem; color: var(--muted); margin-top: 0.2rem; }
.task-meta { font-size: 0.8rem; color: var(--muted); margin-top: 0.3rem; }
.task-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

/* ---------- Dashboard / charts ---------- */
.dashboard-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
.chart-card h3 { font-size: 0.95rem; margin-bottom: 1rem; }
.chart-legend { display: flex; flex-direction: column; gap: 0.5rem; font-size: 0.85rem; }
.chart-legend-item { display: flex; align-items: center; gap: 0.5rem; }
.chart-legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.chart-hero { font-size: 1.8rem; font-weight: 700; }
.chart-sub { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }
.donut-wrap { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.donut-center-label { font-size: 1.6rem; font-weight: 700; fill: #1f2430; font-family: inherit; }
.donut-center-sub { font-size: 0.7rem; fill: var(--muted); font-family: inherit; }

.bar-chart { display: flex; flex-direction: column; gap: 0.85rem; }
.bar-chart-row { display: grid; grid-template-columns: 44px 1fr 80px; align-items: center; gap: 0.6rem; }
.bar-chart-label { font-size: 0.82rem; color: var(--muted); }
.bar-chart-track { background: #f1f2f8; border-radius: 20px; height: 14px; overflow: hidden; }
.bar-chart-fill { height: 100%; border-radius: 20px; min-width: 4px; }
.bar-chart-value { font-size: 0.82rem; font-weight: 600; text-align: right; }

/* ---------- Proposal builder ---------- */
.item-row {
    display: grid;
    grid-template-columns: 2.5fr 1fr 90px 110px 32px;
    gap: 0.5rem;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}
.item-row:last-child { border-bottom: none; }
.item-row input, .item-row select { padding: 0.4rem 0.5rem; }
.item-remove {
    background: none; border: none; color: var(--red); font-size: 1.1rem; cursor: pointer;
    width: 28px; height: 28px; border-radius: 6px;
}
.item-remove:hover { background: #fef3f2; }
.totals-box { display: flex; flex-direction: column; gap: 0.35rem; align-items: flex-end; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.totals-row { display: flex; gap: 1.5rem; font-size: 0.9rem; }
.totals-row.grand { font-size: 1.1rem; font-weight: 700; }
.add-item-bar { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }
.add-item-bar select { flex: 1; min-width: 220px; }

/* ---------- Proposal branded view ---------- */
.proposal-doc {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 3rem;
    max-width: 860px;
    margin: 0 auto;
    font-family: 'Cabin', -apple-system, BlinkMacSystemFont, sans-serif;
    color: #180F4C;
}
.proposal-doc h1, .proposal-doc h2, .proposal-doc h3 { font-family: 'Raleway', -apple-system, sans-serif; color: #180F4C; }
.proposal-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid #2B6FD8; padding-bottom: 1.5rem; margin-bottom: 1.5rem; }
.proposal-head img { height: 48px; }
.proposal-head .proposal-meta { text-align: right; font-size: 0.85rem; color: #555; }
.proposal-head .proposal-meta .proposal-number { font-weight: 700; color: #2B6FD8; font-size: 1rem; }
.proposal-section { margin-bottom: 1.75rem; }
.proposal-section h3 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: #2B6FD8; margin-bottom: 0.5rem; }
.proposal-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.proposal-item-block { border: 1px solid #e5e7ee; border-radius: 10px; padding: 1rem 1.25rem; margin-bottom: 0.85rem; background: #F8F8F8; }
.proposal-item-block .pi-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.proposal-item-block .pi-head h4 { margin: 0; font-family: 'Raleway', sans-serif; }
.proposal-item-block .pi-price { font-weight: 700; color: #2B6FD8; white-space: nowrap; }
.proposal-item-block p { margin: 0.35rem 0 0; font-size: 0.88rem; color: #444; }
.proposal-totals { margin-left: auto; width: 100%; max-width: 320px; }
.proposal-totals .totals-row { justify-content: space-between; padding: 0.3rem 0; }
.proposal-totals .grand { border-top: 2px solid #180F4C; padding-top: 0.6rem; margin-top: 0.3rem; }
.proposal-footer { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid #e5e7ee; font-size: 0.8rem; color: #777; text-align: center; }
.status-pill { display: inline-block; padding: 0.25rem 0.75rem; border-radius: 20px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.status-draft { background: #eef0fe; color: #4338ca; }
.status-sent { background: #fef3c7; color: #92400e; }
.status-accepted { background: #dcfce7; color: #166534; }
.status-declined { background: #fee2e2; color: #991b1b; }

@media print {
    body { background: #fff; }
    .no-print { display: none !important; }
    .app-main { padding: 0; max-width: none; }
    .proposal-doc { box-shadow: none; border: none; padding: 0; max-width: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .form-row { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .nav-toggle { display: inline-flex; }
    .topnav {
        position: absolute; top: 100%; left: 0; right: 0;
        background: #fff; border-bottom: 1px solid var(--border);
        flex-direction: column; padding: 0.5rem; display: none;
        box-shadow: var(--shadow);
    }
    .topnav.open { display: flex; }
    .user-name { display: none; }
    .stage-col { flex: 0 0 82vw; max-height: none; }
    .item-row { grid-template-columns: 1fr; gap: 0.35rem; padding: 0.75rem 0; }
    .item-remove { justify-self: end; }
    .proposal-doc { padding: 1.5rem; }
    .proposal-head { flex-direction: column; gap: 1rem; }
    .proposal-head .proposal-meta { text-align: left; }
    .proposal-parties { grid-template-columns: 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .task-row { flex-wrap: wrap; }
    .task-actions { margin-left: calc(20px + 0.75rem); }
}

@media (prefers-color-scheme: dark) {
    body { background: #14161f; color: #000; }
    .topbar, .panel, .auth-box, .lead-card, table, th, .modal-box, .stage-col { background: #fffdf7; }
    .stage-col { background: #191c26; }
    :root { --border: #2b2f3d; --card-bg: #1c1f2b; --muted: #9a9db0; }
    .brand { color: #e7e8ee; }
    input, select, textarea { background: #14161f; color: #e7e8ee; }
    .topnav a:hover { background: #262a38; }
    th { background: #191c26; }
    tr:hover td { background: #20232f; }
    .stage-count, .lead-card { background: #1c1f2b; }
    .auth-box h1{color:#180F4C;}
}
