/* Paper CRM — plain CSS, no framework. Functional first; polish later.
   Sections: tokens · base · layout · components · print */

/* ---------- tokens ---------- */
:root {
    --bg: #f4f5f7;
    --surface: #fff;
    --border: #d9dce1;
    --text: #1c2430;
    --muted: #6b7280;
    --primary: #1f5fbf;
    --primary-text: #fff;
    --danger: #b42318;
    --success-bg: #e7f6ec;
    --success-text: #14532d;
    --error-bg: #fdecea;
    --error-text: #7a1a12;
    --radius: 6px;
    --space: 1rem;
    --font: system-ui, -apple-system, "Segoe UI", "Noto Sans Bengali", sans-serif;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.danger { color: var(--danger); }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 210px; flex-shrink: 0; background: #1c2430; color: #fff; padding: var(--space) 0; }
.sidebar .brand { display: block; padding: 0 var(--space) var(--space); color: #fff; font-weight: 700; font-size: 1.1rem; }
.sidebar nav a, .sidebar nav summary { display: flex; align-items: center; gap: .6rem; padding: .45rem var(--space); color: #c9d1dc; cursor: pointer; }
.sidebar nav .icon { flex-shrink: 0; opacity: .8; }
.sidebar nav a:hover, .sidebar nav summary:hover, .sidebar nav a.active { background: #2b3646; color: #fff; text-decoration: none; }
.sidebar nav a:hover .icon, .sidebar nav a.active .icon, .sidebar nav summary.active .icon { opacity: 1; }
.sidebar nav summary.active { color: #fff; }
.sidebar nav summary { list-style: none; }
.sidebar nav summary::-webkit-details-marker { display: none; }
.sidebar nav summary::after { content: "›"; margin-left: auto; transition: transform .15s; }
.sidebar nav details[open] > summary::after { transform: rotate(90deg); }
.sidebar .menu-children { background: #161d27; }
.sidebar .menu-children a, .sidebar .menu-children summary { padding-left: 2.6rem; font-size: .93rem; }
.sidebar .menu-children .menu-children a { padding-left: 3.4rem; font-size: .9rem; }
.sidebar .menu-children a.active { background: var(--primary); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: var(--space); padding: .75rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar h1 { margin: 0; }
.topbar-user { display: flex; align-items: center; gap: .75rem; }
.content { padding: 1.25rem; }
.guest { display: grid; place-items: center; min-height: 100vh; }
.guest-card { width: min(380px, 92vw); }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; justify-content: space-between; margin-bottom: var(--space); }
.toolbar form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.stack { display: grid; gap: .75rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .75rem var(--space); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space); margin-bottom: var(--space); }
.inline { display: inline; }
@media (max-width: 720px) {
    .shell { flex-direction: column; }
    .sidebar { width: 100%; }
    .sidebar nav { display: flex; flex-wrap: wrap; }
}

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space); margin-bottom: var(--space); }
.card.empty { text-align: center; padding: 2rem; }
.stat b { display: block; font-size: 1.4rem; }
.btn { display: inline-block; padding: .4rem .8rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.btn:hover { text-decoration: none; background: #eef0f3; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: #184c99; }
.btn-link { border: 0; background: none; padding: 0; color: var(--primary); }
.btn-link.danger { color: var(--danger); }
.btn.disabled { opacity: .5; cursor: default; }
.field { display: grid; gap: .2rem; }
.field > span { font-weight: 600; font-size: .9rem; }
.field small { color: var(--muted); }
.field small.error { color: var(--danger); }
input, select, textarea { font: inherit; padding: .4rem .55rem; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; width: 100%; }
input[type=checkbox], input[type=radio] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.check { display: flex; gap: .5rem; align-items: center; }
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
th, td { padding: .5rem .65rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: #eef0f3; font-size: .85rem; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
td.actions > * + * { margin-left: .6rem; }
.table-wrap { overflow-x: auto; margin-bottom: var(--space); }
.badge { display: inline-block; padding: 0 .45rem; border-radius: 999px; background: #e5e7eb; font-size: .8rem; }
.badge.on { background: var(--success-bg); color: var(--success-text); }
.badge.off { background: var(--error-bg); color: var(--error-text); }
.alert { padding: .6rem .8rem; border-radius: var(--radius); margin-bottom: var(--space); }
.alert ul { margin: 0; padding-left: 1.1rem; }
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-error { background: var(--error-bg); color: var(--error-text); }
.pagination { display: flex; gap: .75rem; align-items: center; justify-content: flex-end; margin-top: .75rem; }

/* ---------- CRM ---------- */
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .75rem var(--space); }
.narrow { max-width: 420px; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.toolbar .field > span { font-size: .8rem; }
.toolbar input[type=search] { min-width: 220px; }
.avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); display: inline-grid; place-items: center; }
.avatar-lg { width: 96px; height: 96px; }
.avatar-empty { background: #eef0f3; color: var(--muted); font-weight: 700; font-size: 1.3rem; }
.photo-cell { width: 80px; }
dl.details { display: grid; grid-template-columns: max-content 1fr; gap: .15rem .75rem; margin: 0; font-size: .92rem; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; }
table.mini { border: 0; min-width: 220px; font-size: .88rem; }
table.mini th, table.mini td { padding: .15rem .4rem; border-bottom: 1px solid #eef0f3; background: none; font-weight: normal; }
table.mini tr.total th, table.mini tr.total td { border-bottom: 0; }
tfoot th { background: #eef0f3; }
.statement-head { display: flex; justify-content: space-between; gap: var(--space); flex-wrap: wrap; margin-bottom: var(--space); }
.statement-party { text-align: right; }

/* ---------- print ---------- */
@media print {
    .sidebar, .topbar, .toolbar, .pagination, .actions, .btn { display: none !important; }
    body { background: #fff; }
    .content { padding: 0; }
    .alert { display: none; }
    .table-wrap { overflow: visible; }
}
