/* Bit QR — app styles. Plain CSS (no build step) so it runs on any shared hosting. */

:root {
    --brand: #4f46e5;
    --brand-dark: #4338ca;
    --brand-soft: #eef2ff;
    --bg: #f4f6fb;
    --surface: #ffffff;
    --text: #0f172a;
    --text-2: #475569;
    --muted: #94a3b8;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --success: #16a34a;
    --success-soft: #dcfce7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --info: #2563eb;
    --info-soft: #dbeafe;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .06);
    --shadow-lg: 0 10px 40px rgba(15, 23, 42, .12);
    --topbar-h: 62px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0; background: var(--bg); color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { vertical-align: middle; }
.icon { width: 18px; height: 18px; flex: none; }
.icon-lg { width: 22px; height: 22px; }

/* ---------- Top bar & navigation ---------- */
.topbar {
    position: sticky; top: 0; z-index: 40; height: var(--topbar-h);
    display: flex; align-items: center; gap: 16px; padding: 0 20px;
    background: rgba(255, 255, 255, .92); backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; color: var(--text); letter-spacing: -.01em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff;
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 45%, #7c3aed 100%);
    box-shadow: 0 4px 12px rgba(79, 70, 229, .35);
}
.brand-mark svg { width: 20px; height: 20px; }

.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a {
    display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px;
    color: var(--text-2); font-weight: 600; font-size: 14px; white-space: nowrap;
}
.nav a:hover { background: #f1f5f9; color: var(--text); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-dark); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.menu-toggle { display: none; background: none; border: 0; padding: 8px; border-radius: 10px; cursor: pointer; color: var(--text); }
.menu-toggle:hover { background: #f1f5f9; }

.user-menu { position: relative; }
.user-menu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 4px 6px 4px 4px; border-radius: 999px; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: #f1f5f9; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
    background: linear-gradient(135deg, #e0e7ff, #c7d2fe); color: var(--brand-dark); font-weight: 800; font-size: 13px;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-meta strong { font-size: 14px; }
.user-meta small { color: var(--muted); font-size: 12px; }
.dropdown {
    position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; padding: 6px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.dropdown a, .dropdown button {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 8px;
    background: none; border: 0; font: inherit; font-size: 14px; color: var(--text); cursor: pointer; text-align: left;
}
.dropdown a:hover, .dropdown button:hover { background: #f1f5f9; text-decoration: none; }
.dropdown .danger { color: var(--danger); }
.dropdown hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.dropdown form { margin: 0; }

/* ---------- Layout ---------- */
.container { max-width: 1240px; margin: 22px auto 40px; padding: 0 18px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.page-head p { margin: 4px 0 0; color: var(--text-2); font-size: 14px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card h2 { margin: 0 0 14px; font-size: 17px; letter-spacing: -.01em; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.app-footer { text-align: center; color: var(--muted); font-size: 12px; padding: 0 0 24px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px;
    border: 1px solid transparent; border-radius: 10px; background: var(--brand); color: #fff;
    font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background .15s, box-shadow .15s, transform .05s;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 0; box-shadow: 0 0 0 3px rgba(79, 70, 229, .3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-light { background: #fff; color: var(--text); border-color: var(--border-strong); }
.btn-light:hover { background: #f8fafc; }
.btn-dark { background: #1e293b; }
.btn-dark:hover { background: #0f172a; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: var(--success); }
.btn-success:hover { background: #15803d; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-lg { padding: 13px 20px; font-size: 16px; border-radius: 12px; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
label { font-size: 13px; font-weight: 600; color: var(--text-2); display: block; margin-bottom: 6px; }
input, select, textarea {
    padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 10px; font: inherit; font-size: 14.5px;
    background: #fff; color: var(--text); transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }
input[type="checkbox"] { width: 17px; height: 17px; padding: 0; accent-color: var(--brand); vertical-align: -3px; margin-right: 6px; }
.checkbox-label { display: inline-flex; align-items: center; font-weight: 500; color: var(--text); }
.field { margin-bottom: 14px; }
.field input, .field select, .field textarea { width: 100%; }
.hint { display: block; color: var(--muted); font-size: 12.5px; margin-top: 5px; font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; align-items: start; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid input:not([type="checkbox"]), .form-grid select, .form-grid textarea { width: 100%; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters > div { min-width: 0; }
.error { color: var(--danger); font-size: 13px; margin-top: 6px; font-weight: 500; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 70px; }
.password-toggle {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: 0;
    color: var(--brand); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; padding: 6px 8px;
}

/* ---------- Alerts & badges ---------- */
.alert { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; font-size: 14px; border: 1px solid transparent; }
.alert-success { background: var(--success-soft); color: #166534; border-color: #bbf7d0; }
.alert-error { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }
.alert-warning { background: var(--warning-soft); color: #92400e; border-color: #fde68a; }
.alert-info { background: var(--info-soft); color: #1e40af; border-color: #bfdbfe; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge-received { background: var(--success-soft); color: #166534; }
.badge-pending { background: var(--danger-soft); color: #991b1b; }
.badge-draft { background: var(--warning-soft); color: #92400e; }
.badge-muted, .badge-inactive { background: #f1f5f9; color: #64748b; }
.badge-role-super { background: #ede9fe; color: #5b21b6; }
.badge-role-admin { background: #e0e7ff; color: #3730a3; }
.badge-role-sub { background: #e0f2fe; color: #075985; }
.badge-role-sender { background: #ffedd5; color: #9a3412; }
.badge-role-receiver { background: #dcfce7; color: #166534; }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.stats .card { margin-bottom: 0; }
.stat { display: flex; align-items: center; gap: 14px; padding: 18px; position: relative; overflow: hidden; }
.stat-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.stat-icon svg { width: 22px; height: 22px; }
.stat .label { font-size: 13px; color: var(--text-2); font-weight: 600; }
.stat .value { font-size: 30px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; color: var(--text); }
.stat.sent .stat-icon { background: var(--info-soft); color: var(--info); }
.stat.received .stat-icon { background: var(--success-soft); color: var(--success); }
.stat.pending .stat-icon { background: var(--danger-soft); color: var(--danger); }
.stat.draft .stat-icon { background: var(--warning-soft); color: var(--warning); }
.stat.pending.alerting { border-color: #fecaca; background: linear-gradient(180deg, #fff, #fff5f5); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: #f8fafc; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); font-weight: 700; white-space: nowrap; }
thead th:first-child { border-top-left-radius: 10px; }
thead th:last-child { border-top-right-radius: 10px; }
tbody tr:hover { background: #fafbff; }
tr.pending-row { background: #fff7f7; }
tr.pending-row:hover { background: #fff1f1; }
tr.inactive-row { opacity: .6; }
td form { display: inline; margin: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.text-right { text-align: right; }
.empty { text-align: center; padding: 36px 12px; color: var(--muted); }
.empty svg { width: 34px; height: 34px; display: block; margin: 0 auto 8px; opacity: .6; }

.pagination { display: flex; gap: 8px; list-style: none; padding: 0; margin: 16px 0 0; }
.pagination li a, .pagination li span { display: inline-block; padding: 7px 14px; border-radius: 9px; background: #fff; border: 1px solid var(--border-strong); color: var(--text); font-size: 14px; font-weight: 600; }
.pagination li.disabled span { opacity: .45; }

/* ---------- Trend chart (sent vs received, last 7 days) ---------- */
.trend { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; align-items: end; height: 170px; padding-top: 6px; border-bottom: 1px solid var(--border); }
.trend-day { display: flex; flex-direction: column; align-items: center; height: 100%; }
.trend-bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; position: relative; cursor: default; }
.trend-bar { width: min(18px, 38%); border-radius: 4px 4px 0 0; min-height: 2px; }
.trend-bar.sent { background: #2a78d6; }
.trend-bar.received { background: #eb6834; }
.trend-label { font-size: 11.5px; color: var(--text-2); padding-top: 6px; white-space: nowrap; }
.trend-day.is-selected .trend-label { color: var(--text); font-weight: 800; }
.trend-tip {
    display: none; position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); z-index: 5;
    background: #0f172a; color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 8px; white-space: nowrap; pointer-events: none;
}
.trend-bars:hover .trend-tip, .trend-bars:focus .trend-tip { display: block; }
.trend-bars:hover .trend-bar { filter: brightness(1.08); }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- Auth (login) ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(1200px 600px at 10% -10%, #c7d2fe 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #ddd6fe 0%, transparent 55%), var(--bg); }
.auth-card { width: 100%; max-width: 410px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-lg); padding: 30px 26px; }
.auth-card .brand { justify-content: center; font-size: 20px; margin-bottom: 6px; }
.auth-card .brand-mark { width: 44px; height: 44px; border-radius: 13px; }
.auth-card .brand-mark svg { width: 26px; height: 26px; }
.auth-sub { text-align: center; color: var(--text-2); font-size: 14px; margin: 0 0 22px; }

/* ---------- Mobile ---------- */
@media (max-width: 960px) {
    .menu-toggle { display: inline-flex; }
    .nav {
        display: none; position: fixed; top: var(--topbar-h); left: 0; right: 0; z-index: 39; flex-direction: column; gap: 2px; margin: 0;
        padding: 10px 12px 14px; background: #fff; border-bottom: 1px solid var(--border); box-shadow: var(--shadow-lg);
    }
    .nav.open { display: flex; }
    .nav a { padding: 12px; font-size: 15px; }
    .user-meta { display: none; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
    .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    body { font-size: 14.5px; }
    .topbar { padding: 0 12px; }
    .container { padding: 0 12px; margin-top: 14px; }
    .page-head h1 { font-size: 21px; }
    .card { padding: 16px; border-radius: 12px; }
    .stat { padding: 14px; gap: 10px; }
    .stat-icon { width: 38px; height: 38px; border-radius: 10px; }
    .stat .value { font-size: 24px; }
    .filters > div, .filters .btn { flex: 1 1 140px; }
    .filters input, .filters select { width: 100%; }
    .trend { height: 140px; gap: 6px; }

    /* Tables marked .table-stack turn into cards on phones; cells show their data-label. */
    .table-stack thead { display: none; }
    .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
    .table-stack tr { border: 1px solid var(--border); border-radius: 12px; padding: 6px 12px; margin-bottom: 10px; background: #fff; }
    .table-stack td { border: 0; padding: 6px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
    .table-stack td::before { content: attr(data-label); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; text-align: left; flex: none; }
    .table-stack td[data-label=""]::before { content: none; }
    .table-stack td.cell-main { justify-content: flex-start; text-align: left; font-weight: 600; }
    .table-stack td.cell-main::before { content: none; }
    .table-stack tr.pending-row { border-color: #fecaca; }
}

@media print {
    .no-print, .topbar, .nav, .app-footer { display: none !important; }
    body { background: #fff; }
    .card { box-shadow: none; }
}
