/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #6366f1;
    --primary-light: #eef2ff;
    --primary-dark: #4f46e5;
    --success: #10b981;
    --success-light: #ecfdf5;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --bg: #f3f4f6;
    --card: #ffffff;
    --border: #e5e7eb;
    --text: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 30px rgba(0,0,0,.08);
    --transition: .2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* === Login === */
.login-page {
    display: flex; align-items: center; justify-content: center; min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-container { width: 100%; max-width: 400px; padding: 20px; }
.login-card { background: var(--card); border-radius: 20px; padding: 44px 36px; box-shadow: var(--shadow-lg); text-align: center; }
.login-card h1 { font-size: 24px; font-weight: 700; color: var(--text); margin-bottom: 4px; letter-spacing: -.5px; }
.login-subtitle { color: var(--text-secondary); margin-bottom: 28px; font-size: 14px; }
.login-form { text-align: left; }
.login-hint { margin-top: 18px; font-size: 13px; color: var(--text-muted); background: var(--primary-light); padding: 10px 14px; border-radius: var(--radius-sm); }

/* === Navbar === */
.navbar {
    background: var(--card); border-bottom: 1px solid var(--border); padding: 0 28px;
    padding-top: env(safe-area-inset-top, 0);
    display: flex; align-items: center; justify-content: space-between; height: 58px;
    position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
}
.nav-brand { font-size: 17px; font-weight: 700; letter-spacing: -.3px; white-space: nowrap; }
.nav-links { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.nav-links a {
    color: var(--text-secondary); text-decoration: none; padding: 7px 15px;
    border-radius: var(--radius-sm); font-size: 14px; font-weight: 500;
    transition: all var(--transition); white-space: nowrap;
}
.nav-links a:hover { background: var(--primary-light); color: var(--primary); }
.nav-links a.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-user { font-size: 13px; color: var(--text-muted); padding: 0 6px; }
.btn-logout { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.btn-logout:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-light); }
.badge { display: inline-flex; align-items: center; justify-content: center; background: var(--danger); color: #fff; font-size: 11px; min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px; margin-left: 4px; }
.chat-badge { display: inline-flex; align-items: center; justify-content: center; background: var(--primary); color: #fff; font-size: 11px; min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px; margin-left: 4px; }

/* === Container === */
.container { max-width: 1140px; margin: 0 auto; padding: 28px 24px 80px; padding-bottom: calc(80px + env(safe-area-inset-bottom, 0)); }
h2 { font-size: 20px; font-weight: 700; margin-bottom: 20px; letter-spacing: -.3px; }
h3 { font-size: 15px; font-weight: 600; margin-bottom: 14px; color: var(--text); }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.text-muted { color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }

/* === Cards === */
.card { background: var(--card); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; box-shadow: var(--shadow); border: 1px solid var(--border); }

/* === Stats === */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--card); border-radius: var(--radius); padding: 22px 18px; text-align: center; box-shadow: var(--shadow); border: 1px solid var(--border); }
.stat-number { font-size: 32px; font-weight: 800; color: var(--primary); letter-spacing: -1px; }
.stat-label { color: var(--text-secondary); font-size: 13px; margin-top: 2px; font-weight: 500; }

.quick-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* === Settle Stats === */
.settle-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 24px; }
.settle-card { background: var(--card); border-radius: var(--radius); padding: 22px 24px; text-align: center; box-shadow: var(--shadow); border: 1px solid var(--border); }
.settle-card.total { border-left: 4px solid var(--primary); }
.settle-card.settled { border-left: 4px solid var(--success); }
.settle-card.pending { border-left: 4px solid var(--warning); }
.settle-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; font-weight: 500; }
.settle-number { font-size: 28px; font-weight: 800; color: var(--text); letter-spacing: -1px; }
.settle-card.total .settle-number { color: var(--primary); }
.settle-card.settled .settle-number { color: var(--success); }
.settle-card.pending .settle-number { color: var(--warning); }
.settle-date { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* === Forms === */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--text-secondary); }
.form-group input[type="text"], .form-group input[type="password"], .form-group input[type="email"], .form-group input[type="number"], .form-group input[type="date"], .form-group select {
    width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 14px; transition: all var(--transition); background: #fff; color: var(--text);
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.flex-grow { flex: 1; min-width: 160px; }
.inline-form { display: inline; }
.inline-input { border: 1px solid transparent; padding: 5px 8px; border-radius: 6px; font-size: 13px; width: 120px; background: transparent; transition: all var(--transition); color: var(--text); }
.inline-input:hover, .inline-input:focus { border-color: var(--primary); background: #fff; outline: none; }
.inline-select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; background: #fff; cursor: pointer; color: var(--text); }
.inline-select:focus { outline: none; border-color: var(--primary); }

/* === Buttons === */
.btn { display: inline-block; padding: 10px 22px; border: none; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; transition: all var(--transition); text-align: center; letter-spacing: .2px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99,102,241,.3); }
.btn-secondary { background: #f9fafb; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f3f4f6; color: var(--text); }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 6px 14px; font-size: 12px; border-radius: 6px; }
.btn-full { width: 100%; }
.upload-btn { align-self: flex-end; height: 42px; }

/* === Alerts === */
.alert { padding: 12px 18px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; font-weight: 500; }
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid #a7f3d0; }
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #fecaca; }

/* === Tables === */
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background: #f9fafb; font-weight: 600; font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbff; }
.qr-thumb { width: 60px; height: 60px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.report-number { font-family: "SF Mono", "Fira Code", monospace; font-size: 15px; font-weight: 700; color: var(--primary); }
.action-cell { display: flex; gap: 6px; flex-wrap: wrap; }

/* === QR Thumb Clickable === */
.qr-thumb.clickable { cursor: zoom-in; transition: transform .15s, box-shadow .15s; }
.qr-thumb.clickable:hover { transform: scale(1.08); box-shadow: 0 4px 12px rgba(0,0,0,.15); }

/* === Status === */
.status-btn { border: none; border-radius: 20px; padding: 5px 14px; font-size: 13px; font-weight: 600; cursor: pointer; transition: all var(--transition); }
.status-btn.normal { background: var(--success-light); color: var(--success); }
.status-btn.normal:hover { background: #d1fae5; }
.status-btn.risk { background: var(--danger-light); color: var(--danger); }
.status-btn.risk:hover { background: #fee2e2; }
.status-tag { display: inline-block; border-radius: 20px; padding: 3px 12px; font-size: 12px; font-weight: 600; }
.status-tag.normal { background: var(--success-light); color: var(--success); }
.status-tag.risk { background: var(--danger-light); color: var(--danger); }

/* === Report Toggle === */
.report-toggle { background: var(--primary-light); color: var(--primary); border: none; border-radius: var(--radius-sm); padding: 6px 14px; font-size: 14px; font-weight: 700; cursor: pointer; transition: all var(--transition); }
.report-toggle:hover { background: var(--primary); color: #fff; }
.report-detail td { padding: 0; }
.detail-box { padding: 14px 20px; background: #fafbff; border-top: 1px solid var(--border); }
.detail-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.detail-table th { background: transparent; padding: 6px 12px; font-size: 11px; }
.detail-table td { padding: 6px 12px; border-bottom: 1px solid var(--border); }
.detail-table tr:last-child td { border-bottom: none; }
.note-input { transition: border-color .3s; }

/* === Staff === */
.staff-badge-inline { display: inline-block; margin-left: 6px; background: var(--success-light); color: var(--success); padding: 2px 10px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.staff-form { margin-top: 10px; }
.staff-form .form-row { gap: 8px; }
.staff-form input { flex: 1; min-width: 100px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; }
.staff-form input:focus { outline: none; border-color: var(--primary); }

/* === Empty === */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); font-size: 15px; }

/* === Notifications === */
.notif-list { display: flex; flex-direction: column; gap: 8px; }
.notif-item { background: var(--card); padding: 16px 22px; border-radius: var(--radius); display: flex; align-items: center; justify-content: space-between; gap: 12px; box-shadow: var(--shadow-sm); border: 1px solid var(--border); transition: all var(--transition); }
.notif-item.unread { border-left: 4px solid var(--primary); background: var(--primary-light); }
.notif-content { flex: 1; }
.notif-content p { font-size: 14px; margin-bottom: 4px; line-height: 1.5; }
.notif-time { font-size: 12px; color: var(--text-muted); }

/* === Modal === */
.modal, .modal-overlay { display: none; }
.modal.show, .modal-overlay.show { display: block; }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); backdrop-filter: blur(2px); z-index: 200; }
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 201; }
.modal-content { background: var(--card); border-radius: 16px; padding: 28px 32px; min-width: 340px; max-width: 480px; box-shadow: var(--shadow-lg); }
.modal-content h3 { margin-bottom: 6px; }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; justify-content: flex-end; }

/* === Zoom Modal === */
.zoom-content { min-width: 360px; max-width: 90vw; padding: 16px 20px 20px; }
.zoom-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.zoom-header h3 { margin: 0; font-size: 16px; }
.zoom-img { width: 100%; max-height: 70vh; object-fit: contain; border-radius: var(--radius-sm); background: #f8f8f8; }
.zoom-actions { margin-top: 16px; text-align: center; }

/* === Chat === */
.chat-container { display: flex; flex-direction: column; height: 65vh; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.chat-empty { text-align: center; color: var(--text-muted); padding: 48px; }
.chat-msg { display: flex; align-items: flex-start; gap: 8px; max-width: 80%; }
.chat-self { align-self: flex-end; flex-direction: row-reverse; }
.chat-other, .chat-admin { align-self: flex-start; }
.chat-bubble { background: #f3f4f6; border-radius: 16px; padding: 12px 18px; max-width: 100%; word-break: break-word; }
.chat-self .chat-bubble { background: var(--primary); color: #fff; }
.chat-self .chat-sender { color: rgba(255,255,255,.7); }
.chat-self .chat-time { color: rgba(255,255,255,.6); }
.chat-sender { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 3px; }
.chat-text { font-size: 14px; line-height: 1.55; }
.chat-time { font-size: 11px; color: var(--text-muted); margin-top: 4px; text-align: right; }
.chat-del { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 14px; padding: 2px 6px; border-radius: 4px; opacity: 0; transition: opacity var(--transition); }
.chat-msg:hover .chat-del { opacity: 1; }
.chat-del:hover { color: var(--danger); background: var(--danger-light); }
.chat-input-area { display: flex; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--border); background: #fafbfc; border-radius: 0 0 var(--radius) var(--radius); }
.chat-input-area textarea { flex: 1; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 14px; resize: none; font-family: inherit; transition: all var(--transition); }
.chat-input-area textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.chat-input-area button { height: auto; align-self: flex-end; }

/* === Chat Layout (Admin) === */
.chat-layout { display: flex; gap: 16px; height: 75vh; }
.chat-user-list { width: 260px; overflow-y: auto; flex-shrink: 0; }
.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.chat-header h3 { margin: 0; font-size: 15px; }
.chat-user-item { display: block; padding: 14px 18px; text-decoration: none; border-bottom: 1px solid var(--border); transition: all var(--transition); color: var(--text); }
.chat-user-item:hover { background: var(--primary-light); }
.chat-user-item.active { background: var(--primary-light); border-left: 3px solid var(--primary); }
.chat-user-name { font-weight: 600; font-size: 14px; }
.chat-user-preview { font-size: 12px; color: var(--text-muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* === Responsive === */
@media (max-width: 768px) {
    /* Nav: scrollable horizontal */
    .navbar { height: auto; padding: 8px 12px; gap: 6px; }
    .nav-brand { font-size: 15px; }
    .nav-links { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 2px; padding-bottom: 2px; justify-content: flex-start; width: 100%; scrollbar-width: none; }
    .nav-links::-webkit-scrollbar { display: none; }
    .nav-links a { padding: 8px 12px; font-size: 12px; flex-shrink: 0; border-radius: 6px; }
    .nav-links a.active { font-weight: 600; }
    .nav-user { display: none; }
    .btn-logout { margin-left: auto; }

    .container { padding: 14px 10px 90px; }
    h2 { font-size: 18px; margin-bottom: 14px; }

    /* Cards */
    .card { padding: 16px 14px; margin-bottom: 14px; border-radius: 10px; }

    /* Stats */
    .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .stat-card { padding: 14px 8px; border-radius: 10px; }
    .stat-number { font-size: 24px; }
    .stat-label { font-size: 11px; }

    .settle-stats { grid-template-columns: 1fr; gap: 8px; }
    .settle-card { padding: 16px; border-radius: 10px; }
    .settle-number { font-size: 24px; }

    /* Tables: keep scrollable with better touch */
    .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { min-width: 600px; }
    th, td { padding: 10px 12px; font-size: 13px; white-space: nowrap; }
    th { font-size: 11px; }
    table td.action-cell { white-space: nowrap; }
    .qr-thumb { width: 48px; height: 48px; }

    .report-detail td { padding: 0; display: block; }
    .report-detail td::before { display: none; }
    .detail-box { padding: 10px; }

    /* Forms */
    .form-row { flex-direction: column; gap: 10px; }
    .form-group input, .form-group select { padding: 12px 14px; font-size: 16px; }
    .upload-btn { width: 100%; height: 46px; }
    .btn { padding: 12px 20px; font-size: 14px; border-radius: 8px; min-height: 44px; }
    .btn-sm { padding: 8px 14px; font-size: 13px; min-height: 36px; }

    /* Modal */
    .modal-content { min-width: auto; max-width: calc(100vw - 32px); margin: 0; padding: 22px 18px; border-radius: 14px; }
    .zoom-content { max-width: calc(100vw - 16px); padding: 12px; }

    /* Chat */
    .chat-container { height: calc(100vh - 140px); border-radius: 10px; }
    .chat-messages { padding: 12px; gap: 8px; }
    .chat-msg { max-width: 88%; }
    .chat-bubble { padding: 10px 14px; border-radius: 14px; }
    .chat-input-area { padding: 10px; gap: 8px; }
    .chat-input-area textarea { padding: 10px 14px; font-size: 16px; border-radius: 10px; }
    .chat-input-area select { padding: 10px; font-size: 14px; height: 44px; }

    /* Notifications */
    .notif-item { padding: 12px 16px; flex-direction: column; gap: 8px; border-radius: 10px; }
    .notif-content p { font-size: 14px; }

    /* Empty state */
    .empty-state { padding: 40px 16px; font-size: 14px; }

    /* Quick staff form */
    .staff-form input { padding: 12px 14px; font-size: 16px; }
}

@media (max-width: 480px) {
    .login-card { padding: 28px 20px; border-radius: 16px; }
    .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
    .stat-card { padding: 12px 6px; }
    .stat-number { font-size: 22px; }
    .settle-number { font-size: 20px; }
    .status-btn { padding: 4px 10px; font-size: 12px; }
    table td { font-size: 13px; }
}
