:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --text: #1c2733;
    --muted: #66788a;
    --border: #dde4ea;
    --primary: #1f7a3d;
    --primary-dark: #17622f;
    --danger: #b3261e;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(16, 36, 56, .08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 17px;
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.link-subtle { color: inherit; text-decoration: none; }
.link-subtle:hover { color: var(--primary); text-decoration: underline; }

/* ---- layout ---- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; font-size: 16px; }
.version { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { color: var(--muted); font-size: 14px; }

.sidebar {
    position: sticky;
    top: 48px;
    z-index: 9;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.sidebar ul {
    display: flex;
    gap: 4px;
    list-style: none;
    margin: 0;
    padding: 6px 10px;
    white-space: nowrap;
}

.nav-item {
    display: inline-block;
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--text);
    font-weight: 500;
}
.nav-item:hover { background: var(--bg); text-decoration: none; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item.disabled { color: var(--muted); cursor: not-allowed; }
.badge {
    font-size: 10px;
    text-transform: uppercase;
    background: var(--border);
    color: var(--muted);
    border-radius: 6px;
    padding: 2px 5px;
    margin-left: 6px;
    vertical-align: middle;
}

.content { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }

.page-head h1 { margin: 0 0 4px; font-size: 22px; }
.page-head { margin-bottom: 18px; }
/* Split page head: title left, action right */
.page-head.split { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.page-head.split h1 { margin: 0; }
/* Distinct add button — deep maroon, never the green nav-pill look */
.btn-add-distinct { display: inline-flex; align-items: center; gap: 8px; background: var(--primary, #8b1a1a); color: #fff; border: none; border-bottom: 3px solid #5c1010; padding: 11px 20px; border-radius: 10px; font-size: 15px; font-weight: 700; cursor: pointer; box-shadow: 0 2px 8px rgba(139,26,26,.3); transition: all .12s; white-space: nowrap; text-decoration: none; }
.btn-add-distinct:hover { background: #6d1515; text-decoration: none; }
.btn-add-distinct:active { border-bottom-width: 1px; margin-top: 2px; }

/* ---- cards ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}
.card-label { color: var(--muted); font-size: 13px; }
.card-value { font-size: 26px; font-weight: 700; margin: 4px 0 2px; }
.card-sub { font-size: 12px; }
.panel { margin-top: 18px; }
.panel h2 { margin-top: 0; font-size: 16px; }
.roadmap { padding-left: 20px; margin: 8px 0 0; }
.roadmap li { margin: 6px 0; }

/* ---- forms ---- */
.stack { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 500; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="email"], input[type="tel"], select, textarea {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    background: var(--surface);
    color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.btn {
    display: inline-block;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
/* Outline delete button (invoices, profiles) */
.btn-delete { border-color: #fca5a5 !important; color: #dc2626 !important; }
.btn-delete:hover { background: #fee2e2 !important; border-color: #dc2626 !important; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.inline { display: inline; }
code {
    background: #eef2f5;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 13px;
}

/* ---- alerts ---- */
.alert {
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 14px;
    font-size: 14px;
}
.alert-error { background: #fdeceb; border-color: #f5c2bf; color: var(--danger); }

/* ---- login ---- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(160deg, #e8f3ec 0%, var(--bg) 60%);
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 28px;
    width: min(92vw, 380px);
}
.login-card h1 { margin: 0 0 2px; font-size: 22px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table.data { width: 100%; border-collapse: collapse; font-size: 16px; }
table.data th {
    text-align: left; padding: 10px 12px; background: #f8fafb;
    border-bottom: 1px solid var(--border); color: var(--muted); font-size: 12px;
    text-transform: uppercase; letter-spacing: .03em; white-space: nowrap;
}
table.data td { padding: 9px 12px; border-bottom: 1px solid #eef2f5; vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: #fafcfd; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data th.num { text-align: right; }
.nowrap { white-space: nowrap; }

.tag {
    display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px;
    background: #e8f0ec; color: var(--primary-dark); white-space: nowrap;
}
.tag-danger { background: #fdeceb; color: var(--danger); }
.tag-muted { background: var(--border); color: var(--muted); }
.tag-pending { background: #fef3c7; color: #d97706; }

/* ---- toolbar / forms row ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar form { display: flex; gap: 8px; align-items: center; margin: 0; flex-wrap: wrap; }

/* ---- modern search input (global) ---- */
input[type="text"].search {
    flex: 1 1 220px;
    max-width: 420px;
    padding: 10px 14px 10px 38px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    font-size: 15px;
    background-color: var(--surface);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.5' y2='16.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
    background-size: 17px 17px;
    transition: border-color .15s, box-shadow .15s;
}
input[type="text"].search:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139, 26, 26, .12);
}
input[type="text"].search::placeholder { color: var(--muted); }

/* ---- modern select (global) ---- */
select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 34px !important;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background-color: var(--surface);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 15px 15px;
    cursor: pointer;
    font-weight: 500;
    transition: border-color .15s, box-shadow .15s;
}
select:hover { border-color: #c3ccd6; }
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139, 26, 26, .12);
}

/* ---- BS calendar popup (global) ---- */
.bs-wrap { display: inline-flex; align-items: center; gap: 6px; }
.bs-text { cursor: pointer; background: var(--surface); min-width: 170px; }
.bs-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; flex: 0 0 auto;
    border: 1.5px solid var(--border); border-radius: 10px; background: #fff;
    color: var(--primary, #8b1a1a); cursor: pointer; transition: all .15s;
}
.bs-btn:hover { border-color: var(--primary, #8b1a1a); background: #fdf3f3; }
.bs-cal {
    position: fixed; z-index: 2000; width: 300px;
    background: #fff; border: 1.5px solid var(--border); border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0,0,0,.2); padding: 12px;
    animation: bsIn .16s ease-out;
}
@keyframes bsIn { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }
.bs-cal-head { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.bs-title { flex: 1; text-align: center; font-size: 16px; font-weight: 800; color: var(--primary-dark, #5c1010); }
.bs-nav {
    width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 8px;
    background: #fff; color: #374151; font-size: 15px; font-weight: 700; cursor: pointer; line-height: 1;
}
.bs-nav:hover { background: #f3f4f6; border-color: var(--primary, #8b1a1a); color: var(--primary, #8b1a1a); }
.bs-week { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 4px; }
.bs-week span { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.bs-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.bs-empty { min-height: 34px; }
.bs-day {
    min-height: 34px; border: 0; border-radius: 8px; background: none;
    font-size: 15px; cursor: pointer; color: var(--text); transition: background .12s;
}
.bs-day:hover { background: #f1f5f9; }
.bs-day.today { box-shadow: inset 0 0 0 2px #16a34a; font-weight: 700; }
.bs-day.selected { background: var(--primary, #8b1a1a); color: #fff; font-weight: 700; }
.bs-day.disabled { color: #d1d5db; cursor: not-allowed; pointer-events: none; }
.bs-foot { display: flex; justify-content: space-between; margin-top: 10px; }
.bs-today, .bs-clear {
    border: 1.5px solid var(--border); background: #fff; border-radius: 8px;
    padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.bs-today { color: #15803d; border-color: #6ee7b7; }
.bs-today:hover { background: #f0fdf4; }
.bs-clear { color: var(--muted); }
.bs-clear:hover { background: #fee2e2; border-color: #fca5a5; color: #dc2626; }

/* ---- BS calendar popup (global) ---- */
.bs-wrap { display: inline-flex; align-items: center; gap: 6px; }
.bs-text { cursor: pointer; background: var(--surface); min-width: 170px; }
.bs-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; flex: 0 0 auto;
    border: 1.5px solid var(--border); border-radius: 10px; background: #fff;
    color: var(--primary, #8b1a1a); cursor: pointer; transition: all .15s;
}
.bs-btn:hover { border-color: var(--primary, #8b1a1a); background: #fdf3f3; }
.bs-cal {
    position: fixed; z-index: 2000; width: 300px;
    background: #fff; border: 1.5px solid var(--border); border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0,0,0,.2); padding: 12px;
    animation: bsIn .16s ease-out;
}
@keyframes bsIn { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }
.bs-cal-head { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.bs-title { flex: 1; text-align: center; font-size: 16px; font-weight: 800; color: var(--primary-dark, #5c1010); }
.bs-nav {
    width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 8px;
    background: #fff; color: #374151; font-size: 15px; font-weight: 700; cursor: pointer; line-height: 1;
}
.bs-nav:hover { background: #f3f4f6; border-color: var(--primary, #8b1a1a); color: var(--primary, #8b1a1a); }
.bs-week { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 4px; }
.bs-week span { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.bs-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.bs-empty { min-height: 34px; }
.bs-day {
    min-height: 34px; border: 0; border-radius: 8px; background: none;
    font-size: 15px; cursor: pointer; color: var(--text); transition: background .12s;
}
.bs-day:hover { background: #f1f5f9; }
.bs-day.today { box-shadow: inset 0 0 0 2px #16a34a; font-weight: 700; }
.bs-day.selected { background: var(--primary, #8b1a1a); color: #fff; font-weight: 700; }
.bs-day.disabled { color: #d1d5db; cursor: not-allowed; pointer-events: none; }
.bs-foot { display: flex; justify-content: space-between; margin-top: 10px; }
.bs-today, .bs-clear {
    border: 1.5px solid var(--border); background: #fff; border-radius: 8px;
    padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.bs-today { color: #15803d; border-color: #6ee7b7; }
.bs-today:hover { background: #f0fdf4; }
.bs-clear { color: var(--muted); }
.bs-clear:hover { background: #fee2e2; border-color: #fca5a5; color: #dc2626; }

/* ---- BS calendar popup (global) ---- */
.bs-wrap { display: inline-flex; align-items: center; gap: 6px; }
.bs-text { cursor: pointer; background: var(--surface); min-width: 170px; }
.bs-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; flex: 0 0 auto;
    border: 1.5px solid var(--border); border-radius: 10px; background: #fff;
    color: var(--primary, #8b1a1a); cursor: pointer; transition: all .15s;
}
.bs-btn:hover { border-color: var(--primary, #8b1a1a); background: #fdf3f3; }
.bs-cal {
    position: fixed; z-index: 2000; width: 300px;
    background: #fff; border: 1.5px solid var(--border); border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0,0,0,.2); padding: 12px;
    animation: bsIn .16s ease-out;
}
@keyframes bsIn { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }
.bs-cal-head { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.bs-title { flex: 1; text-align: center; font-size: 16px; font-weight: 800; color: var(--primary-dark, #5c1010); }
.bs-nav {
    width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 8px;
    background: #fff; color: #374151; font-size: 15px; font-weight: 700; cursor: pointer; line-height: 1;
}
.bs-nav:hover { background: #f3f4f6; border-color: var(--primary, #8b1a1a); color: var(--primary, #8b1a1a); }
.bs-week { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 4px; }
.bs-week span { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.bs-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.bs-empty { min-height: 34px; }
.bs-day {
    min-height: 34px; border: 0; border-radius: 8px; background: none;
    font-size: 15px; cursor: pointer; color: var(--text); transition: background .12s;
}
.bs-day:hover { background: #f1f5f9; }
.bs-day.today { box-shadow: inset 0 0 0 2px #16a34a; font-weight: 700; }
.bs-day.selected { background: var(--primary, #8b1a1a); color: #fff; font-weight: 700; }
.bs-day.disabled { color: #d1d5db; cursor: not-allowed; pointer-events: none; }
.bs-foot { display: flex; justify-content: space-between; margin-top: 10px; }
.bs-today, .bs-clear {
    border: 1.5px solid var(--border); background: #fff; border-radius: 8px;
    padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.bs-today { color: #15803d; border-color: #6ee7b7; }
.bs-today:hover { background: #f0fdf4; }
.bs-clear { color: var(--muted); }
.bs-clear:hover { background: #fee2e2; border-color: #fca5a5; color: #dc2626; }

/* ---- BS calendar popup (global) ---- */
.bs-wrap { display: inline-flex; align-items: center; gap: 6px; }
.bs-text { cursor: pointer; background: var(--surface); min-width: 170px; }
.bs-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; flex: 0 0 auto;
    border: 1.5px solid var(--border); border-radius: 10px; background: #fff;
    color: var(--primary, #8b1a1a); cursor: pointer; transition: all .15s;
}
.bs-btn:hover { border-color: var(--primary, #8b1a1a); background: #fdf3f3; }
.bs-cal {
    position: fixed; z-index: 2000; width: 300px;
    background: #fff; border: 1.5px solid var(--border); border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0,0,0,.2); padding: 12px;
    animation: bsIn .16s ease-out;
}
@keyframes bsIn { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }
.bs-cal-head { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.bs-title { flex: 1; text-align: center; font-size: 16px; font-weight: 800; color: var(--primary-dark, #5c1010); }
.bs-nav {
    width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 8px;
    background: #fff; color: #374151; font-size: 15px; font-weight: 700; cursor: pointer; line-height: 1;
}
.bs-nav:hover { background: #f3f4f6; border-color: var(--primary, #8b1a1a); color: var(--primary, #8b1a1a); }
.bs-week { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 4px; }
.bs-week span { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.bs-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.bs-empty { min-height: 34px; }
.bs-day {
    min-height: 34px; border: 0; border-radius: 8px; background: none;
    font-size: 15px; cursor: pointer; color: var(--text); transition: background .12s;
}
.bs-day:hover { background: #f1f5f9; }
.bs-day.today { box-shadow: inset 0 0 0 2px #16a34a; font-weight: 700; }
.bs-day.selected { background: var(--primary, #8b1a1a); color: #fff; font-weight: 700; }
.bs-day.disabled { color: #d1d5db; cursor: not-allowed; pointer-events: none; }
.bs-foot { display: flex; justify-content: space-between; margin-top: 10px; }
.bs-today, .bs-clear {
    border: 1.5px solid var(--border); background: #fff; border-radius: 8px;
    padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.bs-today { color: #15803d; border-color: #6ee7b7; }
.bs-today:hover { background: #f0fdf4; }
.bs-clear { color: var(--muted); }
.bs-clear:hover { background: #fee2e2; border-color: #fca5a5; color: #dc2626; }

/* ---- BS calendar popup (global) ---- */
.bs-wrap { display: inline-flex; align-items: center; gap: 6px; }
.bs-text { cursor: pointer; background: var(--surface); min-width: 170px; }
.bs-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; flex: 0 0 auto;
    border: 1.5px solid var(--border); border-radius: 10px; background: #fff;
    color: var(--primary, #8b1a1a); cursor: pointer; transition: all .15s;
}
.bs-btn:hover { border-color: var(--primary, #8b1a1a); background: #fdf3f3; }
.bs-cal {
    position: fixed; z-index: 2000; width: 300px;
    background: #fff; border: 1.5px solid var(--border); border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0,0,0,.2); padding: 12px;
    animation: bsIn .16s ease-out;
}
@keyframes bsIn { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }
.bs-cal-head { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.bs-title { flex: 1; text-align: center; font-size: 16px; font-weight: 800; color: var(--primary-dark, #5c1010); }
.bs-nav {
    width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 8px;
    background: #fff; color: #374151; font-size: 15px; font-weight: 700; cursor: pointer; line-height: 1;
}
.bs-nav:hover { background: #f3f4f6; border-color: var(--primary, #8b1a1a); color: var(--primary, #8b1a1a); }
.bs-week { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 4px; }
.bs-week span { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.bs-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.bs-empty { min-height: 34px; }
.bs-day {
    min-height: 34px; border: 0; border-radius: 8px; background: none;
    font-size: 15px; cursor: pointer; color: var(--text); transition: background .12s;
}
.bs-day:hover { background: #f1f5f9; }
.bs-day.today { box-shadow: inset 0 0 0 2px #16a34a; font-weight: 700; }
.bs-day.selected { background: var(--primary, #8b1a1a); color: #fff; font-weight: 700; }
.bs-day.disabled { color: #d1d5db; cursor: not-allowed; pointer-events: none; }
.bs-foot { display: flex; justify-content: space-between; margin-top: 10px; }
.bs-today, .bs-clear {
    border: 1.5px solid var(--border); background: #fff; border-radius: 8px;
    padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.bs-today { color: #15803d; border-color: #6ee7b7; }
.bs-today:hover { background: #f0fdf4; }
.bs-clear { color: var(--muted); }
.bs-clear:hover { background: #fee2e2; border-color: #fca5a5; color: #dc2626; }

/* ---- BS calendar popup (global) ---- */
.bs-wrap { display: inline-flex; align-items: center; gap: 6px; }
.bs-text { cursor: pointer; background: var(--surface); min-width: 170px; }
.bs-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; flex: 0 0 auto;
    border: 1.5px solid var(--border); border-radius: 10px; background: #fff;
    color: var(--primary, #8b1a1a); cursor: pointer; transition: all .15s;
}
.bs-btn:hover { border-color: var(--primary, #8b1a1a); background: #fdf3f3; }
.bs-cal {
    position: fixed; z-index: 2000; width: 300px;
    background: #fff; border: 1.5px solid var(--border); border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0,0,0,.2); padding: 12px;
    animation: bsIn .16s ease-out;
}
@keyframes bsIn { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }
.bs-cal-head { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.bs-title { flex: 1; text-align: center; font-size: 16px; font-weight: 800; color: var(--primary-dark, #5c1010); }
.bs-nav {
    width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 8px;
    background: #fff; color: #374151; font-size: 15px; font-weight: 700; cursor: pointer; line-height: 1;
}
.bs-nav:hover { background: #f3f4f6; border-color: var(--primary, #8b1a1a); color: var(--primary, #8b1a1a); }
.bs-week { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 4px; }
.bs-week span { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.bs-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.bs-empty { min-height: 34px; }
.bs-day {
    min-height: 34px; border: 0; border-radius: 8px; background: none;
    font-size: 15px; cursor: pointer; color: var(--text); transition: background .12s;
}
.bs-day:hover { background: #f1f5f9; }
.bs-day.today { box-shadow: inset 0 0 0 2px #16a34a; font-weight: 700; }
.bs-day.selected { background: var(--primary, #8b1a1a); color: #fff; font-weight: 700; }
.bs-day.disabled { color: #d1d5db; cursor: not-allowed; pointer-events: none; }
.bs-foot { display: flex; justify-content: space-between; margin-top: 10px; }
.bs-today, .bs-clear {
    border: 1.5px solid var(--border); background: #fff; border-radius: 8px;
    padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.bs-today { color: #15803d; border-color: #6ee7b7; }
.bs-today:hover { background: #f0fdf4; }
.bs-clear { color: var(--muted); }
.bs-clear:hover { background: #fee2e2; border-color: #fca5a5; color: #dc2626; }

/* ---- icon-only clear button (global) ---- */
.clear-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    border: 1.5px solid var(--border);
    border-radius: 50%;
    background: #fff;
    color: var(--muted);
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
    transition: all .15s;
}
.clear-icon:hover { background: #fee2e2; border-color: #fca5a5; color: #dc2626; box-shadow: 0 2px 8px rgba(220,38,38,.18); }
.clear-icon:active { transform: scale(.92); }

/* ---- custom dropdown (progressively enhances toolbar category selects) ---- */
.dd { position: relative; display: inline-block; }
.dd-btn {
    display: inline-flex;
    align-items: center;
    max-width: 240px;
    padding: 10px 36px 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    background-color: #fff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 11px center;
    background-size: 15px 15px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
    transition: border-color .15s, box-shadow .15s;
}
.dd-btn:hover { border-color: #c3ccd6; }
.dd.open .dd-btn { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(139,26,26,.12); }
.dd-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-all .dd-label { color: var(--muted); font-weight: 500; }
.dd-pop {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 100%;
    width: max-content;
    max-width: 280px;
    max-height: 264px;
    overflow-y: auto;
    background: #fff;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0,0,0,.14);
    z-index: 60;
    padding: 6px;
}
.dd.open .dd-pop { display: block; animation: ddIn .15s ease-out; }
@keyframes ddIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.dd-opt {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    border: 0;
    background: none;
    border-radius: 8px;
    font-size: 16px;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: background .12s;
}
.dd-opt:hover { background: #f1f5f9; }
.dd-opt.selected { background: #e7f4ea; color: var(--primary-dark); font-weight: 600; }
.dd-check { color: #16a34a; font-weight: 700; flex: 0 0 auto; }

/* ---- lot pills + active filter chip ---- */
.lot-pill {
    display: inline-block;
    padding: 2px 10px;
    margin: 1px 3px 1px 0;
    border-radius: 20px;
    background: #eef2f9;
    border: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    text-decoration: none;
    white-space: nowrap;
    transition: all .15s;
}
.lot-pill:hover { background: #e0e7f2; border-color: var(--primary); color: var(--primary); }
.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px 6px 14px;
    border-radius: 20px;
    background: #e7f4ea;
    border: 1.5px solid #16a34a;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-dark);
}
.filter-chip .clear-icon { width: 24px; height: 24px; font-size: 11px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; }
.row > * { flex: 1 1 220px; }
/* Inside narrow modals the 220px basis would force wrapping — smaller basis pairs up */
.modal-box .row > * { flex: 1 1 150px; min-width: 0; }
.actions { display: flex; gap: 6px; align-items: center; }
.form-note { font-size: 13px; color: var(--muted); }
.alert-success { background: #e7f4ea; border-color: #bfe0c8; color: var(--primary-dark); }
.alert-info { background: #e8f0fa; border-color: #c5d9ee; color: #1b4e86; }

/* ---- POS ---- */
.pos-grid { display: grid; grid-template-columns: 1fr 360px; gap: 16px; align-items: start; }
@media (max-width: 900px) { .pos-grid { grid-template-columns: 1fr; } }
.pos-left { min-width: 0; }
.sticky { position: sticky; top: 118px; }
.search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.search-row input { flex: 1; font-size: 16px; }
.prod-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 4px; border-bottom: 1px solid #eef2f5; }
.prod-row:last-child { border-bottom: 0; }
.qty-stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.qty-stepper button { border: 0; background: var(--surface); width: 28px; font-size: 16px; cursor: pointer; padding: 4px 0; }
.qty-stepper button:hover { background: var(--bg); }
.qty-stepper .qty-num { min-width: 30px; text-align: center; font-weight: 600; }
.amount { font-weight: 700; }
.cart-item { padding: 6px 0; border-bottom: 1px dashed var(--border); }
.total-row { display: flex; justify-content: space-between; padding: 4px 0; }
.total-row.grand { font-size: 17px; font-weight: 700; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 8px; }
.muted-btn { color: var(--muted); background: none; border: 0; cursor: pointer; font-size: 13px; text-decoration: underline; }

/* ---- receipt ---- */
.receipt {
    max-width: 420px; margin: 0 auto; background: #fff; border: 1px solid var(--border);
    padding: 18px 20px; font-size: 13px; box-shadow: var(--shadow);
}
.receipt h2 { margin: 0 0 2px; font-size: 17px; text-align: center; }
.receipt .shop-line { text-align: center; color: var(--muted); margin: 0 0 8px; }
.receipt table { width: 100%; border-collapse: collapse; margin: 6px 0; }
.receipt td { padding: 2px 0; vertical-align: top; }
.receipt tr.line td { border-bottom: 1px dotted #dfe6ec; }
.receipt .dotted-top { border-top: 1px dashed #98a6b3; margin-top: 6px; }
.print-bar { max-width: 420px; margin: 14px auto 0; text-align: center; }

@media print {
    body { background: #fff; }
    .topbar, .sidebar, .print-bar, .no-print { display: none !important; }
    .content { max-width: none; padding: 0; }
    .receipt { box-shadow: none; border: 0; max-width: 72mm; margin: 0; padding: 0; }
}

@media (min-width: 900px) {
    .sidebar ul { justify-content: center; }
}

/* ---- autocomplete (intake form) ---- */
.autocomplete-wrap { position: relative; }
.autocomplete-results {
    display: none;
    position: absolute;
    z-index: 110;
    left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-height: 240px;
    overflow-y: auto;
}
.autocomplete-results:has(.autocomplete-item) { display: block; }
.autocomplete-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}
.autocomplete-item:last-child { border-bottom: 0; }
.autocomplete-item:hover { background: #eef5ee; }
.ac-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}
.ac-item:last-child { border-bottom: 0; }
.ac-item:hover { background: #eef5ee; }
.ac-item .ac-cat {
    display: inline-block;
    font-size: 11px;
    color: var(--muted);
    background: var(--bg);
    padding: 1px 6px;
    border-radius: 4px;
    margin-left: 4px;
}
.ac-empty { color: var(--muted); cursor: default; }

/* ---- intake form layout ---- */
.intake-layout { display: grid; grid-template-columns: 1fr 200px; gap: 16px; align-items: start; }
@media (max-width: 900px) { .intake-layout { grid-template-columns: 1fr; } }
.input-full { width: 100% !important; }
.intake-sidebar .card { padding: 14px; }
.intake-sidebar h3 { margin: 0 0 10px; font-size: 15px; }
.admin-links { list-style: none; margin: 0; padding: 0; }
.admin-links li { margin: 0; }
.admin-links a { display: block; padding: 6px 0; font-size: 14px; color: var(--primary); border-bottom: 1px solid var(--border); }
.admin-links a:last-child { border-bottom: 0; }

/* ---- wider autocomplete ---- */
.autocomplete-results-wide { min-width: 100%; }
.ac-main { font-weight: 600; margin-bottom: 2px; }
.ac-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.ac-mfr {
    display: inline-block; font-size: 11px; color: #1b4e86; background: #e8f0fa;
    padding: 1px 6px; border-radius: 4px;
}
.ac-unit {
    display: inline-block; font-size: 11px; color: var(--muted); background: var(--bg);
    padding: 1px 6px; border-radius: 4px;
}

/* ---- stock table ---- */
.stock-summary { margin-bottom: 14px; }
.stock-product-card { margin-bottom: 16px; }
.stock-product-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.stock-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.stock-on-hand { font-weight: 700; font-size: 15px; margin-left: 8px; }
.row-expired { background: #fff5f5; }
.row-expiring { background: #fffde7; }
.lot-details { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.lot-chip {
    display: inline-block; font-size: 11px; padding: 2px 6px; border-radius: 4px;
    background: #e8f0ec; color: var(--primary-dark);
}
.lot-expired { background: #fdeceb; color: var(--danger); }
.lot-expiring { background: #fff3cd; color: #856404; }

/* ---- modal ---- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 100;
    justify-content: center;
    align-items: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 8px 30px rgba(0,0,0,.25);
    width: 100%;
    max-width: 440px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
    position: relative;
}
.modal-box h2 { margin: 0 0 16px; font-size: 18px; }
.modal-close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: none;
    border: 2px solid #8b1a1a;
    color: #8b1a1a;
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.modal-close:hover { background: #8b1a1a; color: #fff; }
