/* ===== Reset & Base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #4A90D9;
  --primary-dark: #3a7bc8;
  --primary-light: #e8f1fb;
  --success: #52c41a;
  --warning: #faad14;
  --danger: #ff4d4f;
  --text: #1a1a2e;
  --text-secondary: #666;
  --text-light: #999;
  --bg: #f5f7fa;
  --card-bg: #fff;
  --border: #e8ecf1;
  --sidebar-w: 220px;
  --header-h: 56px;
  --radius: 8px;
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; cursor: pointer; }

/* ===== Layout ===== */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: var(--sidebar-w); background: linear-gradient(180deg, #1a2332, #24344d); color: #c9d4e9; flex-shrink: 0; display: flex; flex-direction: column; z-index: 10; transition: transform .25s ease; }
.sidebar-header { padding: 20px 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: 10px; }
.sidebar-logo { width: 34px; height: 34px; border-radius: 8px; background: var(--primary); display: flex; align-items: center; justify-content: center; color:#fff; font-size: 18px; flex-shrink: 0; }
.sidebar-title { font-size: 15px; font-weight: 600; color: #fff; line-height: 1.3; white-space: nowrap; }
.sidebar-subtitle { font-size: 11px; color: rgba(255,255,255,.45); }
.nav-group { padding: 10px 0; }
.nav-label { padding: 12px 18px 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: rgba(255,255,255,.6); font-weight: 700; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 18px; color: #ffffff; cursor: pointer; transition: all .15s; font-size: 15px; font-weight: 600; position: relative; user-select: none; border-left: 3px solid transparent; }
.nav-item:hover { background: rgba(255,255,255,.08); color: #ffffff; }
.nav-item.active { background: rgba(74,144,217,.2); color: #ffffff; border-left-color: #4A90D9; font-weight: 700; }
.nav-icon { font-size: 17px; width: 22px; text-align: center; flex-shrink: 0; }

.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.header { height: var(--header-h); background: var(--card-bg); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; flex-shrink: 0; box-shadow: 0 1px 3px rgba(0,0,0,.04); z-index: 5; }
.header-title { font-size: 16px; font-weight: 600; }
.header-user { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--text-secondary); }
.header-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; }
.header-role { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--primary-light); color: var(--primary); }

.content { flex: 1; padding: 20px 24px; overflow-y: auto; overflow-x: hidden; }

/* ===== Invoice List ===== */
.stats-bar { position: sticky; top: 0; z-index: 10; background: var(--bg); padding-bottom: 12px; display: flex; gap: 12px; flex-wrap: wrap; }
.toolbar { position: sticky; top: 72px; z-index: 10; background: var(--bg); padding-bottom: 12px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar-search { flex: 1; min-width: 200px; max-width: 360px; position: relative; }
.toolbar-search input { width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: 14px; outline: none; background: #fafbfc; }
.toolbar-search input:focus { border-color: var(--primary); }
.invoice-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.invoice-table thead { position: sticky; top: 0; z-index: 5; }
.invoice-table th { position: sticky; top: 0; background: #f1f5f9; padding: 12px 10px; text-align: left; font-size: 14px; font-weight: 700; color: #1e293b; white-space: nowrap; cursor: pointer; user-select: none; border-bottom: 2px solid #e2e8f0; }
.invoice-table th:hover { background: #e2e8f0; }
.invoice-table th .sort-icon { display: inline-block; margin-left: 4px; color: #94a3b8; font-size: 11px; }
.invoice-table th .sort-icon.active { color: var(--primary); }
.invoice-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.invoice-table tr:hover { background: #f8fafc; }
.invoice-table tr.selected { background: #eff6ff; }
.invoice-table tr.row-danger { background: #fef2f2; }
.invoice-table tr.row-danger:hover { background: #fee2e2; }
.invoice-table tr.row-disabled { opacity: 0.55; }
.invoice-table tr.row-disabled .row-checkbox { cursor: not-allowed; opacity: 0.4; }
.invoice-table tr.row-disabled:hover { opacity: 0.65; }
.table-wrap { border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 340px); }

/* ===== Login Page ===== */
.login-page { display: flex; align-items: center; justify-content: center; height: 100vh; width: 100%; background: linear-gradient(135deg,#1a2332 0%,#2c3e50 50%,#34495e 100%); }
.login-card { background: #fff; border-radius: 16px; padding: 40px 36px 36px; width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card h2 { font-size: 22px; text-align: center; margin-bottom: 6px; color: var(--text); }
.login-card p.sub { text-align: center; color: var(--text-light); font-size: 13px; margin-bottom: 28px; }
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text-secondary); }
.form-control { width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: 14px; outline: none; transition: border-color .2s; background: #fafbfc; }
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(74,144,217,.12); background: #fff; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 18px; border-radius: var(--radius); border: none; font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s; white-space: nowrap; line-height: 1.4; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-default { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-default:hover { border-color: #ccc; background: #eee; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 11px 28px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

/* ===== Cards & Tables ===== */
.card { background: var(--card-bg); border-radius: 12px; border: 1px solid var(--border); padding: 20px; margin-bottom: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.03); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { background: #f8fafc; font-weight: 600; color: var(--text-secondary); text-align: left; padding: 11px 14px; border-bottom: 2px solid var(--border); white-space: nowrap; position: sticky; top: 0; z-index: 1; }
td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:hover td { background: #fafbfc; }
tr.selected td { background: var(--primary-light); }
.invoice-table tr.row-danger td { background: #fff1f0 !important; }
.invoice-table tr.row-danger:hover td { background: #ffe4e1 !important; }
.cc-select { padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; max-width: 150px; background: #fff; color: var(--text); cursor: pointer; }
.cc-select:focus { border-color: var(--primary); outline: none; }

/* ===== Toolbar ===== */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-search { flex: 1; min-width: 200px; max-width: 360px; position: relative; }
.toolbar-search input { width: 100%; padding: 8px 12px 8px 34px; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: 13px; outline: none; background: #fafbfc; }
.toolbar-search input:focus { border-color: var(--primary); }
.toolbar-search::before { content:'🔍'; position:absolute; left:10px; top:50%; transform:translateY(-50%); font-size:14px; pointer-events:none; }

/* ===== Tags / Badges ===== */
.tag { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.tag-primary { background: var(--primary-light); color: var(--primary); }
.tag-success { background: #f0fdf4; color: var(--success); }
.tag-warning { background: #fefce8; color: #b45309; }
.tag-danger { background: #fef2f2; color: var(--danger); }
.tag-info { background: #eff6ff; color: #2563eb; }
.tag-default { background: #f3f4f6; color: var(--text-secondary); }

/* ===== Stats Bar ===== */
.stats-bar { display: flex; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.stat-card { flex: 1; min-width: 140px; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 12px; color: var(--text-light); }
.stat-value.success { color: var(--success); }
.stat-value.danger { color: var(--danger); }
.stat-value.warning { color: #d97706; }

/* ===== Upload Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; animation: fadeIn .2s ease; backdrop-filter: blur(2px); }
@keyframes fadeIn { from{opacity:0} to{opacity:1} }
.modal { background: #fff; border-radius: 14px; width: 95%; max-width: 720px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 24px 80px rgba(0,0,0,.2); animation: slideUp .25s ease; }
@keyframes slideUp { from{transform:translateY(30px);opacity:.5} to{transform:translateY(0);opacity:1} }
.modal-header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.modal-header h3 { font-size: 17px; font-weight: 600; }
.modal-close { font-size: 24px; cursor: pointer; color: var(--text-light); line-height: 1; background: none; border: none; padding: 0 4px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0; }

/* ===== Drop Zone ===== */
.drop-zone { border: 2.5px dashed var(--border); border-radius: 14px; padding: 48px 24px; text-align: center; cursor: pointer; transition: all .2s; background: #fafbfc; position: relative; }
.drop-zone:hover, .drop-zone.dragover { border-color: var(--primary); background: var(--primary-light); }
.drop-zone-icon { font-size: 48px; margin-bottom: 12px; }
.drop-zone-text { font-size: 15px; color: var(--text-secondary); margin-bottom: 6px; }
.drop-zone-text strong { color: var(--warning); }
.drop-zone-hint { font-size: 12.5px; color: var(--text-light); line-height: 1.6; }
.file-list { margin-top: 14px; text-align: left; }
.file-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #f8fafc; border-radius: 8px; margin-bottom: 6px; font-size: 13px; }
.file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--text-light); font-size: 12px; flex-shrink: 0; }
.file-remove { cursor: pointer; color: var(--danger); background: none; border: none; font-size: 16px; }

/* ===== Progress Bar (OCR) ===== */
.progress-section { margin-top: 20px; display: none; }
.progress-summary { text-align: center; margin-bottom: 14px; font-size: 14px; }
.progress-stats { display: flex; justify-content: center; gap: 32px; font-size: 13px; }
.progress-stat { text-align: center; }
.progress-stat-num { font-size: 28px; font-weight: 700; display: block; }
.progress-stat-num.orange { color: var(--warning); }
.progress-stat-num.green { color: var(--success); }
.progress-stat-num.red { color: var(--danger); }
.progress-bar-track { height: 6px; background: #eef2f7; border-radius: 3px; overflow: hidden; margin-top: 12px; }
.progress-bar-fill { height: 100%; background: linear-gradient(90deg,var(--primary),var(--success)); border-radius: 3px; width: 0%; transition: width .4s ease; }
.progress-detail { margin-top: 10px; font-size: 12.5px; color: var(--text-light); max-height: 120px; overflow-y: auto; }

/* ===== Invoice Table ===== */
.invoice-table th:nth-child(1) { width: 40px; }
.invoice-table .inv-amount { font-weight: 700; color: var(--text); font-size: 14px; }
.inv-checkbox { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }
.inv-actions { display: flex; gap: 6px; }

/* ===== Batch Rename Dialog ===== */
.field-mapping { display: flex; flex-direction: column; gap: 8px; }
.field-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #fafbfc; border-radius: 8px; }
.field-drag-handle { cursor: grab; color: var(--text-light); font-size: 16px; }
.field-checkbox { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.field-label { flex: 1; font-size: 13.5px; }

/* ===== Toast ===== */
.toast-container { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; border-radius: 10px; font-size: 13.5px; color: #fff; box-shadow: 0 6px 24px rgba(0,0,0,.15); animation: toastIn .3s ease; min-width: 240px; max-width: 400px; }
.toast.success { background: linear-gradient(135deg,#22c55e,#16a34a); }
.toast.error { background: linear-gradient(135deg,#ef4444,#dc2626); }
.toast.warning { background: linear-gradient(135deg,#f59e0b,#d97706); color: #fff; }
@keyframes toastIn { from{transform:translateX(60px);opacity:0} to{transform:translateX(0);opacity:1} }

/* ===== Checkbox Toggle Switch ===== */
.toggle-switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--text-secondary); }
.toggle-input { appearance: none; width: 42px; height: 24px; background: #ddd; border-radius: 12px; position: relative; transition: background .2s; flex-shrink: 0; }
.toggle-input:checked { background: var(--primary); }
.toggle-input::after { content:''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle-input:checked::after { transform: translateX(18px); }

/* ===== Responsive ===== */
@media(max-width:768px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); z-index: 20; }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 14px; }
}

/* ===== Empty State ===== */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-light); }
.empty-state-icon { font-size: 56px; margin-bottom: 14px; }
.empty-state h3 { font-size: 17px; margin-bottom: 6px; color: var(--text-secondary); }

/* ===== Pagination ===== */
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 16px 0 4px; }
.pagination button { padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; font-size: 13px; }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-info { font-size: 12.5px; color: var(--text-light); margin: 0 8px; }

/* ===== Category Tag in Table ===== */
.cat-tag { display: inline-block; padding: 3px 10px; border-radius: 14px; font-size: 12px; font-weight: 500; background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.cat-tag.blue { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.cat-tag.green { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.cat-tag.gray { background: #f3f4f6; color: #374151; border-color: #e5e7eb; }

/* ===== Reimbursement Step Flow ===== */
.step-flow { display: flex; align-items: center; gap: 4px; margin: 14px 0; }
.step-dot { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; flex-shrink: 0; }
.step-dot.done { background: var(--success); color: #fff; }
.step-dot.current { background: var(--primary); color: #fff; ring: 2px solid var(--primary-light); box-shadow: 0 0 0 4px rgba(74,144,217,.2); }
.step-dot.pending { background: #e5e7eb; color: #9ca3af; }
.step-line { flex: 1; height: 2px; background: #e5e7eb; min-width: 20px; }
.step-line.done { background: var(--success); }
