:root {
    --bg: #f5f6f8;
    --card: #fff;
    --text: #1f2933;
    --muted: #6b7785;
    --border: #e1e5ea;
    --primary: #2563eb;
    --success: #16a34a;
    --danger: #dc2626;
    --warn: #d97706;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { color: var(--primary); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 24px 0 4px; }

.topbar {
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
    padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); }
.topbar nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.topbar nav a:not(.btn) { padding: 6px 10px; border-radius: var(--radius); color: var(--muted); }
.topbar nav a.active { color: var(--text); background: var(--bg); font-weight: 600; }
.logout-form { margin: 0 0 0 4px; }

.auth-card { max-width: 380px; margin: 40px auto 0; }
.auth-card h1 { text-align: center; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card .btn { width: 100%; padding: 9px; }
.narrow { max-width: 420px; }
.narrow form { display: flex; flex-direction: column; gap: 14px; }

.container { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }

input, select, textarea {
    font: inherit; color: inherit; width: 100%;
    padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfd3fb; border-color: var(--primary); }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
label small { font-weight: 400; }

.btn {
    display: inline-block; padding: 7px 14px; border: 1px solid var(--border); border-radius: 6px;
    background: #fff; color: var(--text); font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(.96); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger  { color: var(--danger); border-color: #f3c4c4; }
.btn-light   { background: transparent; }
.btn-sm { padding: 3px 9px; font-size: 13px; }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.flash-ok    { background: #e7f6ec; color: #14532d; }
.flash-error { background: #fdecec; color: #7f1d1d; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filters input[type=search] { flex: 1 1 240px; width: auto; }
.filters select, .filters input[type=month] { width: auto; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat span { display: block; color: var(--muted); font-size: 13px; }
.stat strong { font-size: 18px; }
.stat-warn strong { color: var(--warn); }
.stats { margin-bottom: 4px; }
.stats-note { margin: 0 0 16px; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 600; background: #fafbfc; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.is-today { background: #fffbea; }
.table td input { min-width: 120px; }
.num { text-align: right !important; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.actions form { display: inline-flex; gap: 6px; margin: 0; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-chua_coc        { background: #eef0f3; color: #4b5563; }
.badge-da_coc          { background: #e0ecff; color: #1e40af; }
.badge-chua_thanh_toan { background: #fff1db; color: #9a5b00; }
.badge-da_thanh_toan   { background: #dcf5e4; color: #166534; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.span-2 { grid-column: span 2; }

.staff-table { margin-top: 8px; }
.staff-table td:nth-child(2) { width: 200px; }
.staff-table td:last-child { width: 50px; }
.staff-table .pay { text-align: right; }
.staff-table tfoot td { border-bottom: 0; }

.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; padding: 12px; }
.inline-form input { flex: 1 1 160px; width: auto; }

/* ===================== Điện thoại / màn hình nhỏ ===================== */
@media (max-width: 720px) {
    /* 16px để iOS không tự phóng to khi chạm vào ô nhập */
    input, select, textarea { font-size: 16px; padding: 9px 10px; }
    .btn { padding: 9px 14px; }
    .btn-sm { padding: 6px 12px; font-size: 14px; }

    .container { padding: 12px 12px 40px; }
    h1 { font-size: 20px; }

    /* Thanh menu: logo một dòng, menu cuộn ngang bên dưới */
    .topbar { padding: 10px 12px 0; position: sticky; top: 0; z-index: 10; }
    .topbar nav {
        width: 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 8px;
        -webkit-overflow-scrolling: touch; scrollbar-width: none;
    }
    .topbar nav::-webkit-scrollbar { display: none; }
    .topbar nav > * { flex: 0 0 auto; }

    /* Bộ lọc: ô tìm kiếm full, trạng thái + tháng chia đôi */
    .filters input[type=search] { flex: 1 1 100%; }
    .filters select, .filters input[type=month] { flex: 1 1 calc(50% - 4px); width: auto; min-width: 0; }
    .filters .btn { flex: 1 1 auto; }

    .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat { padding: 10px 12px; }
    .stat strong { font-size: 16px; }
    .stat:last-child:nth-child(odd) { grid-column: span 2; }

    .card { padding: 14px; }
    .grid { grid-template-columns: 1fr; gap: 12px; }
    .span-2 { grid-column: auto; }

    /* ---------- Bảng -> thẻ (card) ---------- */
    .table-wrap { background: none; border: 0; overflow: visible; }
    .table.cards, .table.cards tbody, .table.cards tfoot { display: block; }
    .table.cards thead { display: none; }
    .table.cards tbody tr {
        display: grid; gap: 6px 12px; position: relative;
        background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
        padding: 12px; margin-bottom: 10px;
    }
    .table.cards td { display: block; width: auto !important; padding: 0; border: 0; text-align: left !important; }
    .table.cards td[data-label]::before {
        content: attr(data-label); display: block; margin-bottom: 2px;
        font-size: 12px; font-weight: 600; color: var(--muted);
    }
    .table.cards td input { min-width: 0; }
    .table.cards td.actions { display: flex; }
    .table.cards tfoot tr { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; }
    .table.cards tfoot td { padding: 0; }
    .table.cards tfoot td:empty { display: none; }

    /* Danh sách job */
    .jobs-table tbody tr {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "event   status"
            "date    date"
            "staff   staff"
            "price   cost"
            "actions actions";
    }
    .table.jobs-table tbody tr.is-today { background: #fffbea; border-left: 4px solid var(--warn); }
    .jobs-table .c-event   { grid-area: event; }
    .jobs-table .c-event strong { font-size: 16px; }
    .jobs-table .c-status  { grid-area: status; justify-self: end; }
    .jobs-table .c-date    { grid-area: date; }
    .jobs-table .c-staff   { grid-area: staff; }
    .jobs-table .c-price   { grid-area: price; }
    .jobs-table .c-cost    { grid-area: cost; }
    .jobs-table .c-actions {
        grid-area: actions; justify-content: stretch;
        border-top: 1px solid var(--border); padding-top: 10px; margin-top: 4px;
    }
    .jobs-table .c-actions > *, .jobs-table .c-actions form .btn { flex: 1; text-align: center; }

    /* Form job: mỗi nhân sự là một thẻ gọn trên một hàng */
    .staff-table tbody tr {
        grid-template-columns: 1fr 120px auto;
        grid-template-areas: "name pay rm";
    }
    .staff-table .c-name { grid-area: name; }
    .staff-table .c-pay  { grid-area: pay; }
    .staff-table .c-rm   { grid-area: rm; align-self: end; }

    /* Trang nhân sự */
    .staff-list tbody tr {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "name    name"
            "phone   pay"
            "count   total"
            "actions actions";
    }
    .staff-list .c-name    { grid-area: name; }
    .staff-list .c-phone   { grid-area: phone; }
    .staff-list .c-pay     { grid-area: pay; }
    .staff-list .c-count   { grid-area: count; }
    .staff-list .c-total   { grid-area: total; }
    .staff-list .c-actions { grid-area: actions; justify-content: flex-end; }

    .inline-form input { flex: 1 1 100%; }
    .inline-form .btn { width: 100%; }

    /* Nút Lưu luôn nằm ở đáy màn hình khi điền form dài */
    .form-actions {
        position: sticky; bottom: 0; z-index: 5;
        margin: 16px -14px -14px; padding: 10px 14px;
        background: var(--card); border-top: 1px solid var(--border);
        border-radius: 0 0 var(--radius) var(--radius);
    }
    .form-actions .btn { flex: 1; text-align: center; }

    .auth-card { margin-top: 16px; }
}
