:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --border: #e2e5ea;
    --text: #1c2333;
    --muted: #6b7280;
    --primary: #8B1A2B;
    --primary-dark: #6f1422;
    --accent: #C9A227;
    --success: #16a34a;
    --danger: #dc2626;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
    --sidebar-w: 248px;
}

* { box-sizing: border-box; }

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------ layout */
.layout { display: flex; min-height: 100vh; }

.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.2s ease;
}

.content { padding: 24px; flex: 1; }

.footer {
    padding: 14px 24px;
    color: var(--muted);
    font-size: 12px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

/* ------------------------------------------------ sidebar */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: #181d28;
    color: #cbd2e0;
    overflow-y: auto;
    z-index: 50;
    transition: transform 0.2s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: #fff;
}

.sidebar-brand strong { display: block; font-size: 15px; }
.sidebar-brand small { display: block; color: #8a94a6; font-size: 11px; }

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    font-weight: 800;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}
.brand-mark.large { width: 56px; height: 56px; font-size: 20px; border-radius: 14px; }

.sidebar-nav { padding: 12px 10px 24px; }

.nav-section {
    padding: 12px 10px 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #6d778a;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    margin: 2px 0;
    border-radius: 8px;
    color: #cbd2e0;
    font-size: 13.5px;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.06); text-decoration: none; color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-icon { width: 20px; text-align: center; }

/* ------------------------------------------------ topbar */
.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 40;
}

.page-title { margin: 0; font-size: 18px; font-weight: 600; flex: 1; }

.topbar-right { display: flex; align-items: center; gap: 16px; }

.icon-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    font-size: 16px;
    cursor: pointer;
    color: var(--text);
}
.icon-btn:hover { background: var(--bg); }

.lang-link { font-weight: 600; font-size: 13px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); }
.lang-link:hover { background: var(--bg); text-decoration: none; }

.user-menu { position: relative; }

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 8px;
    font: inherit;
    color: var(--text);
}
.user-chip:hover { background: var(--bg); }

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
}
.user-name { font-weight: 600; }

.user-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 220px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(16, 24, 40, 0.12);
    padding: 8px;
}
.dropdown-header { padding: 8px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.dropdown-header strong, .dropdown-header small { display: block; }
.dropdown-header small { color: var(--muted); }
.dropdown-item {
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 9px 10px;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    color: var(--danger);
}
.dropdown-item:hover { background: var(--bg); }
.logout-form { margin: 0; }

/* ------------------------------------------------ cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.card-header {
    padding: 14px 18px;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.card-body { padding: 18px; }

/* ------------------------------------------------ grid / stat cards */
.row { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 20px; }
.col { flex: 1 1 200px; }
.col-8 { flex: 2 1 480px; }
.col-6 { flex: 1 1 420px; }
.col-4 { flex: 1 1 260px; }

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
}
.stat-label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-pos { color: #15803d; }
.stat-neg { color: #b91c1c; }

.table-scroll { overflow-x: auto; max-height: 340px; overflow-y: auto; }
.table-scroll .table th { position: sticky; top: 0; background: #fff; z-index: 1; }

/* ------------------------------------------------ timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
    position: relative;
    padding: 0 0 16px 22px;
    border-left: 2px solid var(--border);
}
.timeline li:last-child { padding-bottom: 0; border-left-color: transparent; }
.timeline li::before {
    content: '';
    position: absolute;
    left: -5px;
    top: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
}
.timeline-desc { color: var(--text); font-size: 13px; margin: 2px 0; }
.timeline small { display: block; margin-top: 2px; }

/* ------------------------------------------------ forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; }

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
    background: #fff;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139, 26, 43, 0.12);
}
.form-control.is-invalid { border-color: #dc2626; }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12); }
.form-row { display: flex; gap: 10px; }
.form-row .form-control { flex: 1; }

.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 6px 0; cursor: pointer; }

.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.search-form { display: flex; gap: 10px; margin-bottom: 16px; max-width: 420px; }
.search-form .form-control { flex: 1; }
.inline-form { display: inline; margin: 0; }

/* ------------------------------------------------ buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    background: var(--surface);
    color: var(--text);
}
.btn:hover { text-decoration: none; filter: brightness(0.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { border-color: var(--border); background: var(--surface); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }

/* ------------------------------------------------ table */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafbfc; }
.actions { white-space: nowrap; }
.actions .btn { margin-right: 4px; }

/* ------------------------------------------------ badges */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.badge-success { background: #dcfce7; color: #15803d; }
.badge-muted { background: #f3f4f6; color: #6b7280; }
.badge-open, .badge-unpaid { background: #fef9c3; color: #854d0e; }
.badge-preparing { background: #dbeafe; color: #1e40af; }
.badge-ready { background: #e9d5ff; color: #6b21a8; }
.badge-served, .badge-completed, .badge-paid { background: #dcfce7; color: #15803d; }
.badge-cancelled, .badge-refunded { background: #fee2e2; color: #b91c1c; }
.badge-partial { background: #fed7aa; color: #9a3412; }
.badge-pending, .badge-active { background: #dbeafe; color: #1e40af; }
.badge-overdue { background: #fee2e2; color: #b91c1c; }

/* ------------------------------------------------ alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 18px;
    border: 1px solid transparent;
}
.alert-success { background: #dcfce7; border-color: #bbf7d0; color: #15803d; }
.alert-error { background: #fee2e2; border-color: #fecaca; color: #b91c1c; }
.alert-list { margin: 0; padding-left: 18px; }

.muted { color: var(--muted); }
.text-danger { color: #dc2626; }

/* ------------------------------------------------ auth */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(160deg, #181d28 0%, #2a2131 55%, var(--primary-dark) 100%);
    padding: 24px;
}
.auth-wrap { width: 100%; max-width: 400px; }
.auth-card {
    background: var(--surface);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    padding: 32px;
}
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand h1 { margin: 12px 0 4px; font-size: 20px; }
.auth-brand p { margin: 0; color: var(--muted); font-size: 13px; }
.auth-hint { text-align: center; color: var(--muted); font-size: 12px; margin-top: 16px; }
.error-card { text-align: center; }
.error-code { font-size: 56px; font-weight: 800; color: var(--primary); line-height: 1; }

/* ------------------------------------------------ responsive */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .main { margin-left: 0; }
    .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0, 0, 0, 0.3); }
}
@media (max-width: 600px) {
    .content { padding: 16px; }
    .user-name { display: none; }
}
