:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d8dee8;
  --text: #17202a;
  --muted: #687385;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --danger: #b42318;
  --warn: #b7791f;
  --ok: #137333;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { border: 0; border-radius: 6px; background: var(--primary); color: #fff; padding: 9px 14px; cursor: pointer; }
button:hover { background: var(--primary-dark); }
button.secondary { background: #1f2937; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--danger); }
button.icon-btn { background: transparent; color: var(--muted); padding: 4px 8px; font-size: 24px; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; background: #fff; color: var(--text); }
textarea { min-height: 88px; resize: vertical; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

.hidden { display: none !important; }
.login-view { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #f8fafc, #dce9e6); padding: 24px; }
.login-panel { width: min(380px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 28px; display: grid; gap: 16px; box-shadow: 0 18px 60px rgba(15, 23, 42, .12); }
.login-panel h1 { margin: 0; font-size: 28px; }
.login-panel p { margin: -8px 0 8px; color: var(--muted); }
.login-panel small { color: var(--muted); }

.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: #fff; border-right: 1px solid var(--line); padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.brand { display: grid; gap: 4px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.brand strong { font-size: 20px; }
.brand span { color: var(--muted); font-size: 13px; }
#nav { display: grid; gap: 6px; }
.nav-btn { width: 100%; text-align: left; background: transparent; color: var(--text); border-radius: 6px; display: flex; justify-content: space-between; align-items: center; }
.nav-btn.active, .nav-btn:hover { background: #e8f3f1; color: #064e48; }
.badge { min-width: 22px; padding: 1px 6px; border-radius: 999px; background: var(--danger); color: #fff; text-align: center; font-size: 12px; }
.main { min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 22px 28px; border-bottom: 1px solid var(--line); background: #fff; }
.topbar h2 { margin: 0; font-size: 24px; }
.topbar p { margin: 5px 0 0; color: var(--muted); }
#content { padding: 24px 28px 40px; }

.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel, .card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px; }
.metric strong { display: block; font-size: 28px; margin-top: 8px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 14px; }
th { color: var(--muted); background: #f9fafb; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.status { display: inline-block; border-radius: 999px; padding: 3px 8px; font-size: 12px; background: #eef2f7; }
.status.approved { background: #dcfce7; color: var(--ok); }
.status.rejected { background: #fee2e2; color: var(--danger); }
.status.pending_manager, .status.pending_finance { background: #fff7ed; color: var(--warn); }
.status.cancelled { background: #f1f5f9; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.muted { color: var(--muted); }
.pill { display: inline-flex; align-items: center; min-height: 30px; padding: 3px 10px; border-radius: 999px; background: #e8f3f1; color: #064e48; font-size: 13px; }
.pill.warn { background: #fff7ed; color: var(--warn); }
.employee-board { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.employee-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 16px; display: grid; gap: 12px; }
.employee-head, .employee-foot { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.employee-head h3 { margin: 0 0 4px; font-size: 18px; }
.employee-head p, .employee-foot span { margin: 0; color: var(--muted); font-size: 13px; }
.employee-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; color: var(--muted); font-size: 13px; }
.progress { height: 7px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--primary); }
.hr-form h4, .hr-detail h4 { margin: 4px 0 0; color: var(--text); }
.hr-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.hr-summary > div { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #f9fafb; display: grid; gap: 4px; }
.hr-summary b { font-size: 16px; }
.hr-summary span { color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tab { background: transparent; color: var(--text); border-radius: 6px 6px 0 0; border: 1px solid transparent; }
.tab.active { background: #e8f3f1; color: #064e48; border-color: var(--line); border-bottom-color: #e8f3f1; }
.profile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.info-block { border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.info-block h4 { margin-bottom: 10px; }
.audit-detail { display: grid; gap: 14px; }
.audit-json pre { max-height: 360px; overflow: auto; margin: 8px 0 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #f9fafb; white-space: pre-wrap; word-break: break-word; font-size: 12px; line-height: 1.5; }
.info-block p { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 10px; margin: 7px 0; font-size: 13px; }
.info-block span { color: var(--muted); }
.info-block b { font-weight: 500; overflow-wrap: anywhere; }
.task-list { display: grid; gap: 8px; }
.task-row { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; grid-template-columns: minmax(220px, 1.2fr) minmax(180px, .8fr) minmax(180px, 1fr); gap: 10px; align-items: center; }
.task-row.done { background: #f0fdf4; }
.task-row.overdue { border-color: #fed7aa; background: #fff7ed; }
.checkline { display: flex; grid-template-columns: auto 1fr; align-items: center; color: var(--text); font-size: 14px; }
.checkline input { width: auto; }
.task-row small { color: var(--muted); }
.upload-row, .doc-tools { display: grid; grid-template-columns: 150px minmax(180px, 1fr) minmax(180px, 1fr) auto; gap: 10px; align-items: end; margin-bottom: 14px; }
.file-list { display: grid; gap: 8px; }
.file-row { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.file-row .full { flex-basis: 100%; }
.file-row div { display: grid; gap: 4px; min-width: 0; }
.file-row span { color: var(--muted); font-size: 12px; }
.invoice-list { display: grid; gap: 10px; }
.invoice-row { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fff; }
.invoice-edit-row { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; align-items: end; }
.invoice-edit-row .full { grid-column: 1 / -1; color: var(--muted); }
.invoice-row-actions { display: grid; gap: 6px; min-width: 110px; }
.invoice-row-actions span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; margin-bottom: 16px; align-items: stretch; }
.template-card { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: grid; grid-template-rows: auto 1fr auto; gap: 8px; min-height: 132px; }
.template-action { cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.template-action:hover { border-color: var(--primary); box-shadow: 0 8px 24px rgba(15, 23, 42, .08); }
.template-card span { width: fit-content; border-radius: 999px; padding: 2px 8px; background: #eef2f7; color: var(--muted); font-size: 12px; }
.template-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.template-check { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.template-check input { width: auto; }
.generated-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.generated-card { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: grid; gap: 8px; background: #fff; }
.generated-card span { color: var(--muted); font-size: 12px; line-height: 1.4; }
.doc-preview { width: min(760px, 100%); margin: 0 auto; background: #fff; color: #111827; line-height: 1.8; font-size: 15px; }
.doc-preview p { margin: 0 0 10px; min-height: 1em; }
.doc-preview p:first-child { text-align: center; font-size: 22px; font-weight: 700; margin-bottom: 18px; }
.doc-preview table { width: 100%; min-width: 0; border-collapse: collapse; margin: 10px 0 16px; }
.doc-preview td { border: 1px solid #d1d5db; padding: 7px 9px; font-size: 14px; vertical-align: top; }
.doc-preview td:nth-child(odd) { background: #f9fafb; color: #374151; width: 22%; }
.doc-editor-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.doc-editor [contenteditable="true"] { outline: 1px dashed transparent; border-radius: 4px; }
.doc-editor [contenteditable="true"]:hover { outline-color: #b6c2d2; background: #f9fafb; }
.doc-editor [contenteditable="true"]:focus { outline: 2px solid var(--primary); background: #fff; }
.approval-detail-block { display: grid; gap: 10px; }
.approval-detail-block h4 { margin: 6px 0 0; }
.attachment-preview-frame { width: min(980px, 100%); height: 74vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.attachment-preview-image { display: block; max-width: 100%; max-height: 74vh; margin: 0 auto; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; }

.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; padding: 20px; z-index: 20; }
.modal-panel { width: min(1080px, 100%); max-height: min(90vh, 980px); overflow: auto; background: #fff; border-radius: 8px; padding: 20px; position: relative; }
.modal-panel > .icon-btn { position: absolute; top: 8px; right: 10px; }
.modal-panel h3 { margin: 0 36px 16px 0; }
.toast { position: fixed; right: 20px; bottom: 20px; background: #111827; color: #fff; padding: 10px 14px; border-radius: 6px; opacity: 0; transform: translateY(10px); transition: .18s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; border-right: 0; border-bottom: 1px solid var(--line); }
  .grid.cols-4, .grid.cols-2, .form-grid, .hr-summary, .profile-grid, .task-row, .upload-row, .doc-tools, .invoice-edit-row { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; padding: 18px; }
  #content { padding: 18px; }
}
