:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #fff;
  --line: #afc0d4;
  --line-soft: #dce5ef;
  --ink: #122033;
  --muted: #64748b;
  --primary: #1f5eff;
  --teal: #0f8b7e;
  --danger: #c62828;
  --navy: #17395f;
  font-family: "Microsoft YaHei UI", "Noto Sans CJK SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
h1, h2, h3, p { margin-top: 0; }

.user-shell { width: min(1920px, 100%); min-height: 100vh; margin: 0 auto; padding: 12px; }
.panel, .card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.page-header { min-height: 90px; padding: 12px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.page-header h1 { margin: 2px 0 4px; font-size: 20px; font-weight: 600; }
.eyebrow { margin-bottom: 2px; color: var(--teal); font-size: 11px; font-weight: 800; letter-spacing: .15em; }
.subtle, .muted { color: var(--muted); }
.header-side { min-width: 360px; display: grid; justify-items: end; gap: 8px; text-align: right; }
.version-chip, .badge { display: inline-flex; min-height: 24px; align-items: center; padding: 3px 9px; color: #2458a8; background: #e9f1ff; border: 1px solid #c7dcf8; border-radius: 999px; font-size: 12px; font-weight: 700; }

.primary-nav { margin-top: 10px; padding: 8px; display: flex; justify-content: flex-end; gap: 14px; overflow-x: auto; }
.primary-nav button { min-width: 150px; min-height: 44px; padding: 0 18px; color: var(--ink); background: #eaf1fa; border: 1px solid #d5dde8; border-radius: 6px; font-weight: 700; white-space: nowrap; }
.primary-nav button.active { color: #fff; background: var(--navy); border-color: var(--navy); }
.page-root { min-height: calc(100vh - 166px); margin-top: 10px; }
.page { min-height: calc(100vh - 176px); display: grid; gap: 10px; }

.card { min-width: 0; padding: 12px; }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 10px; }
.section-head h2 { margin-bottom: 4px; font-size: 17px; }
.toolbar, .button-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.button, button.action { min-height: 34px; padding: 0 14px; color: var(--ink); background: #eef4fc; border: 1px solid #d4deea; border-radius: 6px; font-weight: 700; }
.button.primary, button.primary { color: #fff; background: var(--primary); border-color: var(--primary); }
.button.success, button.success { color: #fff; background: var(--teal); border-color: var(--teal); }
.button.danger, button.danger { color: #fff; background: var(--danger); border-color: var(--danger); }

label { display: grid; gap: 4px; color: #435166; font-size: 12px; font-weight: 700; }
.search-row { display: grid; grid-template-columns: auto 210px auto; align-items: center; gap: 8px; }

table { width: 100%; border-collapse: collapse; font-size: 12px; white-space: nowrap; }
tbody tr:nth-child(even) { background: #fafcff; }
tbody tr:hover { background: #f4f8ff; }
tbody tr.selected { background: #e9f1ff; }
.empty-cell { height: 100px; color: var(--muted); text-align: center; }

.accounts-page { grid-template-rows: minmax(0, 1fr); }
.employee-card { min-height: calc(100vh - 176px); display: grid; grid-template-rows: auto minmax(0, 1fr); }
.employee-summary { margin-bottom: 0; color: var(--muted); }

.authorization-page { grid-template-rows: auto minmax(0, 1fr); }
.action-bar { padding: 12px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.authorization-grid { min-height: 650px; display: grid; grid-template-columns: 360px 390px minmax(560px, 1fr); gap: 10px; }
.work-column { min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.account-column { grid-template-rows: auto auto minmax(0, 1fr); }
.notice { margin-bottom: 10px; padding: 10px; color: #24437a; background: #f5f8ff; border: 1px solid #c7d7fe; border-radius: 6px; }
.permission-detail { min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.permission-check { width: 18px; height: 18px; min-height: auto; }

.approval-page { grid-template-rows: minmax(360px, 1fr) minmax(250px, .45fr); }
.approval-card { min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.approval-records { grid-template-rows: auto minmax(0, 1fr); }
.roles-page { grid-template-rows: auto minmax(0, 1fr); }
.roles-grid { min-height: 650px; display: grid; grid-template-columns: 330px 340px minmax(620px, 1fr); gap: 10px; }
.roles-grid .work-column { padding: 12px; }
.compact-form { align-content: start; padding-top: 6px; }
.role-permission-card { grid-column: 1 / -1; }

.form-dialog { width: min(620px, 94vw); max-height: 92vh; padding: 0; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; }
.form-dialog::backdrop { background: rgba(15, 23, 42, .72); }
.form-dialog form { padding: 16px; display: grid; gap: 12px; }
.dialog-head, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dialog-head h2 { margin: 0; }
.dialog-actions { justify-content: flex-end; }
.dialog-body { max-height: 65vh; overflow: auto; display: grid; gap: 10px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.form-grid .wide { grid-column: 1 / -1; }
.error-text { min-height: 18px; margin: 0; color: var(--danger); }
.status-ok { color: var(--teal); }
.status-warning { color: #b45309; }
.status-error { color: var(--danger); }

/* === T-0903-03 公司授權獨立分組（照 B 圖） === */
.company-group { border: 2px solid var(--primary); border-radius: 8px; padding: 12px; margin-bottom: 10px; background: #fbfdff; }
.company-group-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.company-group-head h3 { margin: 0; font-size: 14px; color: var(--primary); display: flex; align-items: center; gap: 6px; }
.tag-new { display: inline-flex; align-items: center; min-height: 20px; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; background: var(--primary); color: #fff; }
.company-create-btn { border-color: var(--primary); color: var(--primary); }
.company-group-note { margin: 0 0 8px; font-size: 12px; }
.company-chip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 14px; font-size: 13px; }
.company-chip { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--ink); font-size: 13px; min-height: 28px; }
.company-chip-head { font-size: 11px; color: var(--muted); font-weight: 700; }
.company-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 香港會計兩把鎖：公司授權未勾 → 賬套行鎖死（灰行） */
tr.ledger-locked td { background: #f1f3f6 !important; color: var(--muted); }
tr.ledger-locked:hover td { background: #eceff3 !important; }
.ledger-locked-text { color: var(--danger) !important; font-weight: 700; }
.ledger-allowed-text { color: var(--teal); font-weight: 700; }

@media (max-width: 1450px) {
  .authorization-grid { grid-template-columns: 320px 340px minmax(520px, 1fr); }
}
@media (max-width: 1180px) {
  .authorization-grid { grid-template-columns: 1fr; }
  .roles-grid { grid-template-columns: 1fr; }
  .role-permission-card { grid-column: auto; }
  .work-column { min-height: 500px; }
}
@media (max-width: 760px) {
  .user-shell { padding: 7px; }
  .page-header, .section-head, .action-bar { align-items: flex-start; flex-direction: column; }
  .header-side { min-width: 0; justify-items: start; text-align: left; }
  .primary-nav { justify-content: flex-start; }
  .search-row, .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
}

/* === 桌面版DataGrid对齐 === */
thead tr { background: #f3f7fc; }
th { color: #435166; font-weight: 600; text-align: left; padding: 0 8px; height: 34px; border-bottom: 1px solid #afc0d4; }
td { padding: 0 8px; height: 25px; border-bottom: 1px solid #e8eef5; }
tbody tr:nth-child(even) { background: #fafcff; }
tbody tr:hover { background: #f4f8ff; }
