*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f5f5f5;
    --white: #fff;
    --border: #e0e0e0;
    --text: #333;
    --text-secondary: #888;
    --text-muted: #aaa;
    --green: #0f6e56;
    --green-bg: #e1f5ee;
    --red: #a32d2d;
    --red-bg: #fcebeb;
    --amber: #854f0b;
    --amber-bg: #faede7;
    --blue: #185fa5;
    --blue-bg: #e6f1fb;
    --teal: #1d9e75;
    --teal-bg: #e1f5ee;
    --gray: #5f5e5a;
    --gray-bg: #f1efe8;
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

/* Login page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 40px 32px;
    width: 100%;
    max-width: 380px;
    border: 0.5px solid var(--border);
}

.login-card h1 {
    font-size: 20px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 4px;
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 24px;
}

.login-card .hint {
    margin-top: 16px;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
}

/* Form */
.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 10px;
    border: 0.5px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    outline: none;
    background: var(--white);
    color: var(--text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--teal);
}

.form-row {
    display: flex;
    gap: 10px;
}

.form-row .form-group {
    flex: 1;
}

/* Alert */
.alert {
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 13px;
    margin-bottom: 14px;
}

.alert-error {
    background: var(--red-bg);
    color: var(--red);
}

.form-error {
    display: block;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    background: var(--red-bg);
    color: var(--red);
    margin-bottom: 10px;
}

.required {
    color: var(--red);
    font-weight: bold;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 7px 14px;
    border: 0.5px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    background: var(--white);
    color: var(--text);
    text-decoration: none;
}

.btn:hover { background: #f0f0f0; }

.btn-primary {
    background: var(--teal);
    color: #fff;
    border-color: var(--teal);
}
.btn-primary:hover { background: #0b7d5e; }

.btn-outline {
    background: transparent;
    color: var(--text);
}
.btn-outline:hover { background: #f0f0f0; }

.btn-block {
    width: 100%;
    padding: 10px;
    font-size: 15px;
}

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Top bar */
.top-bar {
    background: var(--white);
    padding: 10px 20px;
    border-bottom: 0.5px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}

.logo {
    font-size: 16px;
    font-weight: 600;
}

.top-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-tag {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Main */
.main-content {
    padding: 16px 20px;
    max-width: 1400px;
    margin: 0 auto;
}

/* Stats */
.stat-grid {
    display: flex;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 12px 18px;
    text-align: center;
    flex: 1;
    min-width: 90px;
    border: 0.5px solid var(--border);
}

.stat-card-danger { background: var(--red-bg); border-color: #f0c5c5; }
.stat-card-warning { background: var(--amber-bg); border-color: #f5d4b3; }

.stat-num {
    font-size: 24px;
    font-weight: 600;
    display: block;
}
.stat-num.green { color: var(--green); }
.stat-num.red { color: var(--red); }
.stat-num.amber { color: var(--amber); }

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Transfer log */
.transfer-log {
    background: var(--white);
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 12px;
    color: var(--text-secondary);
}

.log-item {
    display: inline-block;
    background: #f0f0f0;
    padding: 2px 8px;
    border-radius: 4px;
    margin: 2px 4px;
    font-size: 11px;
}

/* Tabs */
.tab-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.tab {
    padding: 5px 12px;
    border: 0.5px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    background: var(--white);
    color: var(--text);
}

.tab:hover { background: #f0f0f0; }
.tab.active {
    background: var(--teal);
    color: #fff;
    border-color: var(--teal);
}

.tab-danger.active { background: var(--red); border-color: var(--red); }
.tab-warning.active { background: var(--amber); border-color: var(--amber); }

/* Table */
.table-wrap {
    background: var(--white);
    border-radius: var(--radius);
    border: 0.5px solid var(--border);
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 900px;
}

th {
    text-align: left;
    padding: 10px 8px;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 8px;
    border-bottom: 0.5px solid #f0f0f0;
    vertical-align: middle;
}

tr:hover { background: #fafafa !important; }

.phone-cell {
    font-family: monospace;
    font-size: 12px;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-teal { background: var(--teal-bg); color: var(--teal); }
.badge-info { background: #e8f4fd; color: #1a7bb9; }
.badge-gray { background: var(--gray-bg); color: var(--gray); }

.tag-new {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    background: var(--red-bg);
    color: var(--red);
    margin-left: 4px;
}

/* Inventory bar */
.inventory-bar {
    background: var(--white);
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.inv-item {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.inv-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.inv-num {
    font-size: 18px;
    font-weight: 600;
}

.inv-max {
    font-size: 13px;
    color: var(--text-muted);
}

.inv-num-warn { color: var(--amber); }
.inv-num-danger { color: var(--red); }
.inv-num-teal { color: var(--teal); }

.inv-msg {
    margin-left: auto;
    font-size: 12px;
}

.warn-text {
    color: var(--red);
    font-weight: 500;
}

/* Filter bar */
.filter-bar {
    background: var(--white);
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.filter-group {
    display: flex;
    align-items: center;
    gap: 6px;
}
.filter-group label {
    font-size: 12px;
    color: var(--text-secondary);
}
.filter-group select {
    padding: 4px 8px;
    border: 0.5px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    background: var(--white);
    cursor: pointer;
}

/* Stat row: all cards in one line */
.stat-row {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.stat-row .stat-card {
    flex: 0 1 auto;
    min-width: 80px;
}

/* Clickable stat card */
.stat-clickable {
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}
.stat-clickable:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* Duplicate stat card */
.stat-card-dup { background: #f3e5f5; border-color: #e1bee7; }
.stat-num.purple { color: #7b1fa2; }

/* Section title */
.section-title-sm {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

/* Monthly consultant section - table layout */
.con-monthly-section {
    background: var(--white);
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 12px;
}

.con-monthly-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.con-monthly-table th {
    text-align: center;
    padding: 6px 4px;
    font-weight: 600;
    font-size: 11px;
    color: var(--text-secondary);
    background: #fafafa;
    border-bottom: 1px solid var(--border);
}

.con-monthly-table td {
    text-align: center;
    padding: 6px 8px;
    border-bottom: 0.5px solid #f0f0f0;
    font-size: 13px;
}

.con-monthly-table td:first-child {
    text-align: left;
    font-weight: 500;
}

.con-entry-total {
    color: var(--blue) !important;
    font-weight: 700 !important;
}

.con-assign-total {
    color: var(--teal) !important;
    font-weight: 700 !important;
}

/* Daily stats section */
.daily-stats-section {
    background: var(--white);
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 10px;
}

.daily-table-wrap {
    overflow-x: auto;
}

.daily-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    min-width: 600px;
}

.daily-table th {
    text-align: center;
    padding: 6px 4px;
    font-weight: 600;
    color: var(--text-secondary);
    background: #fafafa;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    font-size: 11px;
}

.daily-table td {
    padding: 5px 4px;
    text-align: center;
    border-bottom: 0.5px solid #f0f0f0;
    vertical-align: middle;
}

.daily-date-cell {
    text-align: left !important;
    white-space: nowrap;
    font-weight: 500;
    line-height: 1.3;
}
.daily-dow {
    font-size: 10px;
    color: var(--text-muted);
}

.daily-cell {
    white-space: nowrap;
}
.daily-empty {
    color: #eee;
}
.daily-boss, .daily-store {
    display: inline-block;
    padding: 0 4px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    margin: 1px;
}
.daily-boss { background: var(--blue-bg); color: var(--blue); }
.daily-store { background: #fff3e0; color: #e65100; }

.daily-total-cell {
    font-weight: 700 !important;
    color: var(--teal) !important;
}

/* Duplicate cell */
.dup-cell {
    text-align: center !important;
}
.dup-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
}
.dup-low {
    background: #fce4ec;
    color: #c2185b;
}
.dup-high {
    background: #f3e5f5;
    color: #7b1fa2;
}

/* Monthly stats */
.monthly-stats {
    background: var(--white);
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 16px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.month-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.month-stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

.month-stat-item strong {
    color: var(--text);
}

.month-stat-sep {
    color: var(--border);
}

.month-stat-tag {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.tag-entry {
    background: var(--blue-bg);
    color: var(--blue);
}

.tag-assign {
    background: var(--teal-bg);
    color: var(--teal);
}

/* Protection */
.protect-ok { color: var(--green); font-weight: 500; }
.protect-expired { color: var(--red); font-weight: 600; }

/* Follow note */
.follow-note {
    display: flex;
    align-items: center;
    gap: 6px;
}

.fn-text { font-size: 12px; color: var(--text-secondary); max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fn-empty { font-size: 12px; color: var(--text-muted); }

/* Action cell */
.action-cell {
    white-space: nowrap;
}

.action-cell select {
    padding: 3px 6px;
    border: 0.5px solid var(--border);
    border-radius: 4px;
    font-size: 11px;
    max-width: 96px;
    background: var(--white);
    cursor: pointer;
}

.action-cell select:focus {
    outline: none;
    border-color: var(--teal);
}

.status-select {
    padding: 3px 6px;
    border: 0.5px solid var(--border);
    border-radius: 4px;
    font-size: 11px;
    background: var(--white);
    color: var(--text);
    cursor: pointer;
}

.status-select:focus {
    outline: none;
    border-color: var(--teal);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.3);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.modal.show { display: flex; }

.modal-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 440px;
    margin: 20px;
}

.modal-card h3 {
    font-size: 16px;
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 16px;
}

/* Responsive */
@media (max-width: 1000px) {
    .stat-row { gap: 6px; }
    .con-monthly-table { font-size: 12px; }
}

@media (max-width: 600px) {
    .main-content { padding: 10px; }
    .stat-row { gap: 4px; flex-wrap: nowrap; overflow-x: auto; }
    .stat-row .stat-card { min-width: 60px; padding: 6px 8px; }
    .stat-num { font-size: 18px; }
    .top-bar { padding: 8px 10px; }
    .tab-bar { gap: 2px; }
    .tab { padding: 4px 8px; font-size: 11px; }
    .inventory-bar { gap: 8px; padding: 10px 12px; }
    .inv-msg { margin-left: 0; width: 100%; }

    th, td { padding: 6px 4px; font-size: 11px; }
    td .btn-xs { padding: 2px 5px; font-size: 10px; }

    .daily-table { font-size: 9px; min-width: 500px; }
    .con-monthly-table { font-size: 11px; }
}
