:root {
    --color-bg: #f6f7fb;
    --color-surface: #ffffff;
    --color-border: #e5e7eb;
    --color-border-strong: #d1d5db;
    --color-text: #1f2937;
    --color-text-soft: #6b7280;
    --color-primary: #1d4ed8;
    --color-primary-soft: #eef2ff;
    --color-success: #10b981;
    --color-danger: #dc2626;
    --color-warning: #f59e0b;
    --color-info: #0ea5e9;
    --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.05), 0 1px 1px rgba(15, 23, 42, 0.04);
    --radius: 10px;
    --radius-sm: 6px;
    --transition: 150ms ease;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem 0; line-height: 1.25; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 .75rem 0; }
small { color: var(--color-text-soft); }

/* Layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: #0f172a; color: #cbd5e1; padding: 1.25rem 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { font-weight: 700; font-size: 1.05rem; color: #fff; padding: 0 1.25rem 1rem; border-bottom: 1px solid #1e293b; }
.sidebar .brand small { display: block; font-weight: 400; color: #94a3b8; margin-top: 2px; }
.sidebar nav { padding: 1rem 0; }
.sidebar nav a { display: flex; align-items: center; gap: .6rem; color: #cbd5e1; padding: .55rem 1.25rem; font-weight: 500; border-left: 3px solid transparent; }
.sidebar nav a:hover { background: #1e293b; color: #fff; text-decoration: none; }
.sidebar nav a.active { background: #1e293b; color: #fff; border-left-color: #60a5fa; }
.sidebar .nav-group { padding: .75rem 1.25rem .25rem; font-size: .7rem; text-transform: uppercase; color: #64748b; letter-spacing: .04em; }
.sidebar .userbox { margin-top: auto; padding: 1rem 1.25rem; border-top: 1px solid #1e293b; font-size: .85rem; color: #cbd5e1; }
.sidebar .userbox form { margin-top: .5rem; }

.main { padding: 1.5rem 2rem; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.topbar .crumbs { color: var(--color-text-soft); font-size: .9rem; }

/* Cards */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow-card); }
.card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.card-body { padding: 1.25rem; }
.card-footer { padding: .85rem 1.25rem; border-top: 1px solid var(--color-border); display: flex; align-items: center; justify-content: flex-end; gap: .5rem; background: #fafafa; border-radius: 0 0 var(--radius) var(--radius); }

/* Grid utilities */
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

.flex { display: flex; gap: .75rem; align-items: center; }
.flex.between { justify-content: space-between; }
.flex.end { justify-content: flex-end; }
.flex.col { flex-direction: column; align-items: stretch; }
.gap-sm { gap: .5rem; }
.gap-lg { gap: 1.5rem; }

.muted { color: var(--color-text-soft); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; border-radius: var(--radius-sm); border: 1px solid var(--color-border-strong); background: #fff; color: var(--color-text); font-weight: 500; cursor: pointer; transition: var(--transition); font-size: .9rem; }
.btn:hover { border-color: var(--color-primary); color: var(--color-primary); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn-primary:hover { background: #1e40af; border-color: #1e40af; color: #fff; }
.btn-success { background: var(--color-success); border-color: var(--color-success); color: #fff; }
.btn-success:hover { background: #059669; border-color: #059669; color: #fff; }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--color-danger); }
.btn-danger:hover { background: var(--color-danger); border-color: var(--color-danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-icon { padding: .35rem; width: 32px; height: 32px; }
.btn-link { background: none; border: none; color: var(--color-primary); padding: 0; cursor: pointer; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: .35rem; font-size: .85rem; }
.input, select.input, textarea.input {
    width: 100%; padding: .55rem .75rem;
    border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
    background: #fff; font-size: .9rem; color: var(--color-text);
    transition: var(--transition);
}
.input:focus, textarea.input:focus, select.input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-soft); }
textarea.input { resize: vertical; min-height: 80px; }
.input-error { border-color: var(--color-danger); }
.form-help { font-size: .8rem; color: var(--color-text-soft); margin-top: .25rem; }
.form-error { color: var(--color-danger); font-size: .8rem; margin-top: .25rem; }

.input-group { display: flex; }
.input-group .input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .input + select.input { border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-group select.input { width: auto; min-width: 80px; }

/* Tables */
.table { width: 100%; border-collapse: collapse; background: var(--color-surface); }
.table th, .table td { padding: .75rem 1rem; text-align: left; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.table th { font-size: .75rem; font-weight: 600; color: var(--color-text-soft); text-transform: uppercase; letter-spacing: .04em; background: #fafafa; }
.table tr:hover td { background: #fafbff; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: .15rem .55rem; border-radius: 100px; font-size: .72rem; font-weight: 600; line-height: 1.4; }
.badge-draft { background: #f1f5f9; color: #475569; }
.badge-sent { background: #dbeafe; color: #1d4ed8; }
.badge-viewed { background: #cffafe; color: #0e7490; }
.badge-accepted { background: #dcfce7; color: #15803d; }
.badge-rejected { background: #fee2e2; color: #b91c1c; }
.badge-expired { background: #fef3c7; color: #92400e; }
.badge-converted { background: #ede9fe; color: #6d28d9; }
.badge-archived { background: #e5e7eb; color: #4b5563; }

/* Stats */
.stat { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1rem 1.25rem; box-shadow: var(--shadow-card); }
.stat .label { font-size: .75rem; text-transform: uppercase; color: var(--color-text-soft); letter-spacing: .04em; }
.stat .value { font-size: 1.5rem; font-weight: 700; margin-top: .35rem; }
.stat .delta { font-size: .8rem; color: var(--color-text-soft); margin-top: .35rem; }

/* Alerts */
.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; border: 1px solid transparent; }
.alert-success { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.alert-danger { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.alert-info { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%); padding: 2rem; }
.login-card { width: 100%; max-width: 420px; background: #fff; border-radius: 14px; padding: 2rem; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, .25); }
.login-card h1 { font-size: 1.4rem; margin-bottom: .25rem; }
.login-card .subtitle { color: var(--color-text-soft); margin-bottom: 1.5rem; }

/* Quote editor */
.editor-grid { display: grid; grid-template-columns: 1fr 360px; gap: 1.5rem; }
@media (max-width: 1100px) { .editor-grid { grid-template-columns: 1fr; } }
.lines-table { width: 100%; border-collapse: collapse; }
.lines-table thead th { font-size: .72rem; text-transform: uppercase; color: var(--color-text-soft); padding: .5rem .5rem; border-bottom: 1px solid var(--color-border); text-align: left; }
.lines-table thead th.num { text-align: right; }
.lines-table tbody tr { border-bottom: 1px solid var(--color-border); }
.lines-table tbody tr:last-child { border-bottom: none; }
.lines-table td { padding: .5rem .5rem; vertical-align: middle; }
.lines-table .drag { cursor: grab; color: var(--color-text-soft); user-select: none; padding: 0 .25rem; }
.lines-table .line-image { width: 44px; height: 44px; border-radius: 6px; background: #f3f4f6 center/cover no-repeat; }
.lines-table .line-title input { font-weight: 500; border: 1px solid transparent; }
.lines-table .line-title input:hover, .lines-table input:focus { border-color: var(--color-border); }
.lines-table input.input-cell { padding: .35rem .5rem; border: 1px solid transparent; border-radius: 4px; background: transparent; width: 100%; font-size: .88rem; }
.lines-table input.input-cell:hover { background: #fff; border-color: var(--color-border); }
.lines-table input.input-cell:focus { background: #fff; border-color: var(--color-primary); outline: none; }
.lines-table input.num-cell { text-align: right; font-variant-numeric: tabular-nums; }
.lines-table .line-total { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.lines-table .line-actions { text-align: right; white-space: nowrap; }

.totals { background: var(--color-surface); border-radius: var(--radius); border: 1px solid var(--color-border); padding: 1rem 1.25rem; box-shadow: var(--shadow-card); position: sticky; top: 1rem; }
.totals-row { display: flex; justify-content: space-between; padding: .35rem 0; font-size: .9rem; }
.totals-row.total { border-top: 1px solid var(--color-border); margin-top: .5rem; padding-top: .75rem; font-size: 1.1rem; font-weight: 700; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: none; align-items: center; justify-content: center; padding: 2rem; z-index: 1000; }
.modal-backdrop.open { display: flex; }
.modal { background: #fff; border-radius: var(--radius); width: 100%; max-width: 600px; max-height: 90vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; }
.modal-body { padding: 1.25rem; overflow-y: auto; }
.modal-footer { padding: .85rem 1.25rem; border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: .5rem; background: #fafafa; }
.modal-large { max-width: 800px; }

.product-result { display: flex; gap: .75rem; align-items: center; padding: .55rem; border-radius: 6px; cursor: pointer; }
.product-result:hover { background: #f3f4f6; }
.product-result .img { width: 44px; height: 44px; border-radius: 6px; background: #e5e7eb center/cover no-repeat; flex-shrink: 0; }
.product-result .info { flex: 1; min-width: 0; }
.product-result .info strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-result .info small { color: var(--color-text-soft); }
.product-result .price { font-weight: 600; }

/* Timeline */
.timeline { position: relative; padding-left: 1.5rem; }
.timeline::before { content: ""; position: absolute; left: .5rem; top: 0; bottom: 0; width: 2px; background: var(--color-border); }
.timeline-item { position: relative; padding-bottom: 1rem; }
.timeline-item::before { content: ""; position: absolute; left: -1.25rem; top: .35rem; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid var(--color-primary); }
.timeline-item .meta { font-size: .75rem; color: var(--color-text-soft); }
.timeline-item.event-viewed::before { border-color: var(--color-info); }
.timeline-item.event-sent::before { border-color: var(--color-primary); }
.timeline-item.event-accepted::before { border-color: var(--color-success); }
.timeline-item.event-rejected::before { border-color: var(--color-danger); }
.timeline-item.event-converted::before { border-color: #6d28d9; }

/* Pagination */
.pagination { display: flex; gap: .25rem; align-items: center; }
.pagination a, .pagination span { padding: .35rem .65rem; border: 1px solid var(--color-border); border-radius: 4px; font-size: .85rem; }
.pagination .current { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }

/* Public proposal */
.public-page { background: var(--color-bg); min-height: 100vh; padding: 2rem 1rem; }
.public-wrap { max-width: 880px; margin: 0 auto; }
.public-header { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 2rem; margin-bottom: 1rem; box-shadow: var(--shadow-card); }
.public-header .logo { max-width: 180px; max-height: 60px; }
.proposal-status { display: inline-flex; padding: .5rem 1rem; border-radius: 100px; font-weight: 600; }

.toggle { display: inline-flex; gap: .25rem; background: #f1f5f9; padding: .25rem; border-radius: 100px; }
.toggle button { padding: .25rem .75rem; border-radius: 100px; border: 0; background: transparent; cursor: pointer; font-size: .8rem; color: var(--color-text-soft); font-weight: 500; }
.toggle button.active { background: var(--color-surface); color: var(--color-text); box-shadow: 0 1px 2px rgba(0,0,0,.06); }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid #e5e7eb; border-top-color: var(--color-primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tag { display: inline-block; padding: .15rem .5rem; background: #f3f4f6; border-radius: 4px; font-size: .75rem; color: var(--color-text-soft); }

[hidden] { display: none !important; }
