/* ===== Frontland 财务管理 — 全局样式 ===== */
* { box-sizing: border-box; }
:root {
  --sidebar-bg: #1e293b;
  --sidebar-fg: #cbd5e1;
  --sidebar-active: #334155;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
}
html, body { margin: 0; padding: 0; height: 100%; }
body { font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

#app { display: flex; min-height: 100vh; }

/* ===== 侧边栏 ===== */
#sidebar { width: 200px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-fg); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 18px 16px 10px; font-size: 20px; font-weight: 700; color: #fff; }
.brand #brand-sub { display: block; font-size: 12px; font-weight: 400; color: #94a3b8; margin-top: 2px; }
.brand .ver { font-size: 11px; font-weight: 400; color: #64748b; background: #0f172a; border-radius: 8px; padding: 1px 7px; vertical-align: middle; }
.lang-switch { display: flex; gap: 6px; padding: 0 16px 12px; border-bottom: 1px solid #334155; }
.lang-switch button { flex: 1; padding: 4px 0; font-size: 12px; background: #0f172a; color: #94a3b8; border: 1px solid #334155; border-radius: 6px; cursor: pointer; }
.lang-switch button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
#nav { flex: 1; padding: 8px 0; overflow-y: auto; }
#nav a { display: block; padding: 10px 16px; color: var(--sidebar-fg); text-decoration: none; font-size: 14px; border-left: 3px solid transparent; }
#nav a:hover { background: var(--sidebar-active); color: #fff; }
#nav a.active { background: var(--sidebar-active); color: #fff; border-left-color: var(--accent); }
.sidebar-foot { padding: 12px 16px; font-size: 12px; color: #94a3b8; border-top: 1px solid #334155; }

/* ===== 主区域 ===== */
#main { flex: 1; padding: 24px; min-width: 0; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { font-size: 20px; margin: 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.card h2 { font-size: 15px; margin: 0 0 12px; }

/* ===== 按钮 ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); font-size: 13px; cursor: pointer; text-decoration: none; }
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== 表单 ===== */
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], input[type=email], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }

/* 空日期框：隐藏浏览器语言化的占位符（如 yyyy/mm/日），统一显示 yyyy/mm/dd（Chrome/Edge） */
@supports selector(input::-webkit-datetime-edit) {
  input[type="date"].empty-date:not(:focus)::-webkit-datetime-edit { color: transparent; }
  input[type="date"].empty-date:not(:focus) {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="92" height="18"><text x="0" y="13" font-size="13" font-family="Segoe UI, Arial, sans-serif" fill="%2394a3b8">yyyy/mm/dd</text></svg>');
    background-repeat: no-repeat;
    background-position: 10px center;
  }
}
textarea { resize: vertical; min-height: 60px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.checkbox-row { display: flex; align-items: center; gap: 6px; margin: 6px 0; font-size: 13px; }
.radio-group { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; }
.radio-group label { display: flex; align-items: center; gap: 4px; cursor: pointer; }

/* ===== 表格 ===== */
table.list { width: 100%; border-collapse: collapse; background: var(--card); }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; font-size: 13px; }
table.list th { background: #f8fafc; color: var(--muted); font-weight: 600; white-space: nowrap; }
table.list tr:hover td { background: #f8fafc; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list .actions { white-space: nowrap; text-align: right; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: 8px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ===== 筛选栏 ===== */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filter-bar label { font-size: 12px; color: var(--muted); display: block; }
.filter-bar label > * { margin-top: 3px; }
.filter-bar input, .filter-bar select { width: auto; min-width: 140px; }

/* ===== 标签/状态 ===== */
.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: #e2e8f0; color: #334155; white-space: nowrap; }
.tag.green { background: #dcfce7; color: #15803d; }
.tag.blue { background: #dbeafe; color: #1d4ed8; }
.tag.orange { background: #fef3c7; color: #b45309; }
.tag.red { background: #fee2e2; color: #b91c1c; }
.tag.gray { background: #e2e8f0; color: #64748b; }

/* ===== 模态框 ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; padding: 20px; width: 100%; max-width: 620px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal.wide { max-width: 860px; }
.modal h2 { margin: 0 0 14px; font-size: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ===== Toast ===== */
#toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1e293b; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 4px 12px rgba(0,0,0,.25); animation: slidein .2s ease; max-width: 340px; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===== 工时表 ===== */
.week-nav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.week-nav .week-label { font-weight: 600; font-size: 15px; }
.btn.wk-nav { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }
.btn.wk-nav:hover { background: #dbeafe; }
.btn.wk-today { background: #dcfce7; border-color: #86efac; color: #15803d; font-weight: 600; }
.btn.wk-today:hover { background: #bbf7d0; }
.ts-drag-handle { cursor: grab; color: var(--muted); user-select: none; text-align: center; font-size: 15px; width: 26px; }
.ts-drag-handle:active { cursor: grabbing; }
tr.dragging { opacity: .45; }
tr.dragging td { background: #eff6ff !important; }
table.timesheet input[type=number] { width: 58px; padding: 4px 6px; text-align: right; }
table.timesheet select { min-width: 110px; }
table.timesheet .ts-notes { min-width: 140px; }
table.timesheet td { vertical-align: middle; }
.ts-summary { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 10px; font-size: 13px; color: var(--muted); }
.ts-summary b { color: var(--text); }

/* ===== 单据编辑器 ===== */
.doc-lines input.line-desc { min-width: 220px; }
.doc-lines input[type=number] { width: 100px; text-align: right; }
.doc-totals { max-width: 340px; margin-left: auto; font-size: 14px; }
.doc-totals .row { display: flex; justify-content: space-between; padding: 4px 0; }
.doc-totals .row.total { font-weight: 700; font-size: 16px; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 8px; }
.doc-totals .row.aud { color: var(--muted); font-size: 13px; }
.inline-fields { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.inline-fields label.field { margin-bottom: 0; flex: 1; min-width: 130px; }
.hint { font-size: 12px; color: var(--muted); }
.logo-preview { max-height: 60px; max-width: 200px; display: block; margin-top: 6px; border: 1px solid var(--border); border-radius: 4px; padding: 4px; }

/* ===== 打印区域 ===== */
#print-area { display: none; }

@media print {
  body > #app, #toast-wrap, .modal-overlay { display: none !important; }
  #print-area { display: block !important; }
  body { background: #fff; }
  @page { margin: 15mm; }
}

/* 单据打印模板 */
.doc-print { font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif; color: #111; max-width: 800px; margin: 0 auto; font-size: 13px; }
.doc-print .dp-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.doc-print .dp-company { font-size: 12px; color: #333; line-height: 1.6; }
.doc-print .dp-company .dp-name { font-size: 20px; font-weight: 700; color: #111; margin-bottom: 4px; }
.doc-print .dp-logo { max-height: 70px; max-width: 220px; }
.doc-print .dp-title { text-align: right; }
.doc-print .dp-title h1 { margin: 0 0 8px; font-size: 26px; letter-spacing: 1px; color: #1e293b; }
.doc-print .dp-meta { font-size: 12px; line-height: 1.8; }
.doc-print .dp-meta b { display: inline-block; min-width: 80px; color: #555; font-weight: 600; }
.doc-print .dp-parties { display: flex; gap: 40px; margin-bottom: 20px; }
.doc-print .dp-parties .block { flex: 1; }
.doc-print .dp-parties h3 { font-size: 11px; text-transform: uppercase; color: #888; margin: 0 0 6px; letter-spacing: .5px; }
.doc-print table.dp-lines { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.doc-print table.dp-lines th { background: #1e293b; color: #fff; padding: 8px 10px; text-align: left; font-size: 12px; }
.doc-print table.dp-lines th.num, .doc-print table.dp-lines td.num { text-align: right; }
.doc-print table.dp-lines td { padding: 8px 10px; border-bottom: 1px solid #e5e7eb; }
.doc-print .dp-totals { max-width: 300px; margin-left: auto; margin-bottom: 24px; }
.doc-print .dp-totals .row { display: flex; justify-content: space-between; padding: 3px 0; }
.doc-print .dp-totals .row.grand { font-weight: 700; font-size: 16px; border-top: 2px solid #1e293b; margin-top: 4px; padding-top: 6px; }
.doc-print .dp-totals .row.aud-eq { color: #666; font-size: 12px; }
.doc-print .dp-banks { border-top: 1px solid #e5e7eb; padding-top: 12px; margin-top: 12px; }
.doc-print .dp-banks h3 { font-size: 12px; margin: 0 0 8px; color: #333; }
.doc-print .dp-bank { font-size: 12px; line-height: 1.7; margin-bottom: 10px; color: #333; }
.doc-print .dp-bank b { color: #111; }
.doc-print .dp-notes { font-size: 12px; color: #555; margin-top: 12px; white-space: pre-wrap; }
.doc-print .dp-paid-stamp { display: inline-block; border: 3px solid #16a34a; color: #16a34a; font-size: 18px; font-weight: 700; padding: 4px 16px; border-radius: 6px; transform: rotate(-6deg); margin-top: 8px; }

/* ===== 仪表盘 ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.kpi .kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kpi .kpi-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.red .kpi-value { color: var(--danger); }
.kpi.green .kpi-value { color: var(--success); }
tr.overdue-row td { background: #fef2f2 !important; }

/* ===== 报表 ===== */
.profit-pos { color: var(--success); font-weight: 600; }
.profit-neg { color: var(--danger); font-weight: 600; }

/* ===== 响应式 ===== */
@media (max-width: 800px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; height: auto; position: static; }
  #nav { display: flex; flex-wrap: wrap; }
  #nav a { border-left: none; border-bottom: 3px solid transparent; }
  #nav a.active { border-bottom-color: var(--accent); }
  #main { padding: 14px; }
}
