:root {
  --ink: #1d2925;
  --muted: #63716c;
  --subtle: #89958f;
  --paper: #f3f6f4;
  --surface: #ffffff;
  --line: #dce4df;
  --green: #176b50;
  --green-dark: #103f33;
  --green-soft: #e7f3ed;
  --coral: #cc644c;
  --coral-soft: #faebe7;
  --gold: #a87526;
  --gold-soft: #faf1dc;
  --blue: #3d6f91;
  --blue-soft: #e8f0f5;
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  letter-spacing: 0;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--paper); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { color: inherit; }
button, select { cursor: pointer; }
svg { width: 18px; height: 18px; stroke-width: 1.8; }
[hidden] { display: none !important; }

.login-view { min-height: 100vh; display: grid; grid-template-columns: minmax(390px, 520px) minmax(0, 1fr); background: var(--surface); }
.login-panel { width: 100%; max-width: 430px; margin: auto; padding: 44px 34px; }
.admin-login .login-view { grid-template-columns: minmax(0, 1fr); }
.admin-login .login-panel { max-width: 460px; }
.portal-brand { display: flex; align-items: center; gap: 11px; }
.portal-mark { width: 40px; height: 40px; display: grid; place-items: center; flex: 0 0 40px; border-radius: 50%; background: #f0c5ad; color: var(--green-dark); font-family: Georgia, serif; font-size: 24px; font-weight: 700; }
.portal-brand strong, .portal-brand small { display: block; }
.portal-brand strong { font-size: 16px; }
.portal-brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.login-copy { margin-top: 52px; }
.login-copy > span { color: var(--green); font-size: 11px; font-weight: 800; }
.login-copy h1 { margin: 7px 0 0; font-size: 29px; line-height: 1.25; }
.login-copy p { margin: 9px 0 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.role-segment { margin-top: 25px; padding: 4px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.role-option { height: 42px; display: flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 13px; }
.role-option.is-active { background: var(--surface); color: var(--green); box-shadow: 0 2px 7px rgba(30, 58, 48, .08); font-weight: 700; }
.login-form { margin-top: 20px; display: grid; gap: 15px; }
.login-form label > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.login-form select, .login-form input { width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; outline: 0; background: var(--surface); color: var(--ink); }
.login-form select:focus, .login-form input:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.password-field { position: relative; }
.password-field input { padding-right: 44px; }
.password-field button { position: absolute; top: 4px; right: 4px; width: 36px; height: 36px; display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); }
.password-field button svg { width: 16px; }
.login-error { min-height: 17px; margin: -5px 0 -4px; color: var(--coral); font-size: 11px; }
.portal-primary, .portal-secondary { min-height: 38px; padding: 0 13px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border-radius: 6px; font-size: 12px; font-weight: 800; }
.portal-primary { border: 1px solid var(--green); background: var(--green); color: white; }
.portal-primary:hover { background: var(--green-dark); }
.portal-primary:disabled { cursor: not-allowed; opacity: .48; }
.portal-secondary { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.portal-secondary:hover { border-color: var(--green); color: var(--green); }
.portal-danger { border-color: #e4b6aa; color: var(--coral); }
.login-submit { width: 100%; height: 44px; justify-content: space-between; padding: 0 15px; }
.demo-credential { margin-top: 15px; padding: 10px 11px; display: flex; gap: 8px; border-left: 3px solid var(--gold); background: var(--gold-soft); color: #79551d; }
.demo-credential svg { width: 15px; flex: 0 0 15px; }
.demo-credential p, .security-note { margin: 0; font-size: 11px; line-height: 1.55; }
.security-note { margin-top: 12px; color: var(--subtle); text-align: center; }
.login-context { position: relative; padding: 56px; display: flex; flex-direction: column; justify-content: flex-end; overflow: hidden; background: var(--green-dark); color: white; }
.login-context::before { content: "TEMPS"; position: absolute; top: 4vh; right: -15px; color: rgba(255,255,255,.055); font-family: Georgia, serif; font-size: 150px; font-weight: 700; }
.context-brand { position: relative; }
.context-brand span, .context-brand strong { display: block; }
.context-brand span { color: #a9c5b9; font-size: 12px; font-weight: 700; }
.context-brand strong { max-width: 520px; margin-top: 10px; font-family: Georgia, "Microsoft YaHei", serif; font-size: 37px; line-height: 1.3; }
.context-metrics { position: relative; margin-top: 40px; padding: 22px 0; display: grid; grid-template-columns: repeat(3, minmax(0, 150px)); gap: 30px; border-top: 1px solid rgba(255,255,255,.17); border-bottom: 1px solid rgba(255,255,255,.17); }
.context-metrics strong, .context-metrics span { display: block; }
.context-metrics strong { font-family: Georgia, serif; font-size: 30px; color: #f0c5ad; }
.context-metrics span { margin-top: 4px; color: #b7ccc3; font-size: 11px; }
.context-flow { position: relative; margin-top: 25px; display: flex; align-items: center; flex-wrap: wrap; gap: 10px; color: #dbe8e2; font-size: 11px; }
.context-flow svg { width: 14px; color: #f0c5ad; }

.portal-shell { min-height: 100vh; display: grid; grid-template-columns: 218px minmax(0, 1fr); }
.portal-sidebar { position: sticky; top: 0; height: 100vh; padding: 22px 14px 18px; display: flex; flex-direction: column; background: var(--green-dark); color: white; }
.portal-brand-light { padding: 0 8px 21px; border-bottom: 1px solid rgba(255,255,255,.13); }
.portal-brand-light small { color: #a9c5b9; }
.portal-nav { margin-top: 20px; display: grid; gap: 5px; }
.portal-nav button { min-height: 42px; padding: 0 11px; display: flex; align-items: center; gap: 10px; border: 0; border-radius: 6px; background: transparent; color: #b8cec5; text-align: left; font-size: 13px; }
.portal-nav button:hover { background: rgba(255,255,255,.08); color: white; }
.portal-nav button.is-active { background: var(--paper); color: var(--green-dark); font-weight: 800; }
.portal-nav button span:last-child { margin-left: auto; min-width: 20px; padding: 2px 6px; border-radius: 10px; background: var(--coral); color: white; font-size: 10px; text-align: center; }
.portal-sidebar-note { margin-top: auto; padding: 13px 10px 0; display: flex; align-items: flex-start; gap: 8px; border-top: 1px solid rgba(255,255,255,.13); color: #b8cec5; }
.portal-sidebar-note svg { width: 15px; flex: 0 0 15px; }
.portal-sidebar-note p { margin: 0; font-size: 10px; line-height: 1.6; }
.portal-workspace { min-width: 0; }
.portal-topbar { min-height: 72px; padding: 13px 28px; display: flex; align-items: center; gap: 18px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.97); }
.portal-topbar p { margin: 0 0 3px; color: var(--muted); font-size: 10px; }
.portal-topbar h1 { margin: 0; font-size: 21px; line-height: 1.25; }
.portal-top-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.local-status { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; }
.local-status i { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); }
.local-status:not(.is-offline) i { background: var(--green); }
.local-status.is-offline { color: var(--coral); }
.local-status.is-offline i { background: var(--coral); }
.user-menu { padding-left: 12px; border-left: 1px solid var(--line); }
.user-menu span, .user-menu strong { display: block; }
.user-menu span { color: var(--muted); font-size: 9px; }
.user-menu strong { margin-top: 2px; font-size: 12px; }
.icon-action { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: white; color: var(--muted); }
.icon-action:hover { border-color: var(--green); color: var(--green); }
.portal-content { max-width: 1500px; margin: 0 auto; padding: 25px 28px 44px; }
.page-intro { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; }
.page-intro span { color: var(--green); font-size: 10px; font-weight: 800; }
.page-intro h2 { margin: 5px 0 0; font-size: 18px; }
.page-intro p { max-width: 750px; margin: 6px 0 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.scope-badge { padding: 5px 8px; border-radius: 4px; background: var(--blue-soft); color: var(--blue) !important; white-space: nowrap; }
.kpi-grid { margin-top: 16px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; }
.kpi-card { min-height: 108px; padding: 15px; border: 1px solid var(--line); border-top: 3px solid var(--green); border-radius: 7px; background: white; }
.kpi-card.risk { border-top-color: var(--coral); }
.kpi-card.warn { border-top-color: var(--gold); }
.kpi-card span, .kpi-card strong, .kpi-card small { display: block; }
.kpi-card span { color: var(--muted); font-size: 10px; }
.kpi-card strong { margin-top: 9px; font-family: Georgia, serif; font-size: 27px; }
.kpi-card small { margin-top: 7px; color: var(--subtle); font-size: 9px; }
.toolbar { margin-top: 16px; padding: 11px; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; border: 1px solid var(--line); border-radius: 7px; background: white; }
.toolbar input, .toolbar select, .portal-select { height: 36px; min-width: 155px; padding: 0 10px; border: 1px solid var(--line); border-radius: 5px; background: white; color: var(--ink); outline: 0; font-size: 11px; }
.toolbar input { flex: 1; min-width: 210px; }
.toolbar-count { margin-left: auto; color: var(--subtle); font-size: 10px; }
.work-list { margin-top: 12px; display: grid; gap: 8px; }
.customer-row { min-width: 0; padding: 13px 14px; display: grid; grid-template-columns: minmax(155px,1.35fr) 90px 90px 105px 120px 110px; align-items: center; gap: 11px; border: 1px solid var(--line); border-radius: 7px; background: white; }
.customer-row:hover { border-color: #b6c9bf; }
.customer-identity strong, .customer-identity small { display: block; }
.customer-identity strong { font-size: 13px; }
.customer-identity small { margin-top: 4px; color: var(--subtle); font-size: 9px; }
.cell-label { display: block; margin-bottom: 3px; color: var(--subtle); font-size: 8px; }
.cell-value { font-size: 11px; }
.status-chip { display: inline-flex; padding: 4px 7px; border-radius: 4px; font-size: 9px; font-weight: 800; }
.status-chip.idle { background: var(--paper); color: var(--muted); }
.status-chip.progress { background: var(--gold-soft); color: var(--gold); }
.status-chip.booked { background: var(--blue-soft); color: var(--blue); }
.status-chip.done { background: var(--green-soft); color: var(--green); }
.status-chip.issue { background: var(--coral-soft); color: var(--coral); }
.date-overdue { color: var(--coral); font-weight: 800; }
.date-today { color: var(--gold); font-weight: 800; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.row-actions button { min-height: 33px; }
.empty-state { padding: 52px 20px; border: 1px dashed var(--line); border-radius: 7px; background: rgba(255,255,255,.6); text-align: center; color: var(--muted); }
.empty-state svg { width: 27px; height: 27px; color: var(--subtle); }
.empty-state strong, .empty-state span { display: block; }
.empty-state strong { margin-top: 10px; font-size: 13px; }
.empty-state span { margin-top: 5px; font-size: 10px; }
.section-band { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.security-card { margin-top: 18px; max-width: 720px; padding: 18px; border: 1px solid var(--line); border-radius: 7px; background: white; }
.security-card > .section-heading { align-items: flex-start; }
.security-card > .section-heading > svg { width: 22px; color: var(--green); }
.security-form { margin-top: 18px; display: grid; gap: 13px; }
.security-form label > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 9px; font-weight: 700; }
.security-form input { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 5px; background: white; outline: 0; color: var(--ink); font-size: 12px; }
.security-form input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(39,103,78,.1); }
.security-form small { display: block; margin-top: 5px; color: var(--subtle); font-size: 9px; }
.security-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 5px; }
.security-actions > span { color: var(--muted); font-size: 10px; }
.section-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 15px; }
.section-heading h3 { margin: 0; font-size: 15px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 10px; }
.staff-grid { margin-top: 12px; display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 9px; }
.staff-item { padding: 13px; border: 1px solid var(--line); border-radius: 7px; background: white; }
.staff-item.is-disabled { background: #f7f6f5; }
.staff-item-head { display: flex; justify-content: space-between; gap: 8px; }
.staff-item strong, .staff-item small { display: block; }
.staff-item strong { font-size: 13px; }
.staff-item small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.staff-item dl { margin: 14px 0 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.staff-item dt { color: var(--subtle); font-size: 8px; }
.staff-item dd { margin: 3px 0 0; font-size: 11px; font-weight: 800; }
.staff-item button { width: 100%; }
.handover-form { margin-top: 12px; padding: 14px; display: grid; grid-template-columns: minmax(0,1fr) minmax(150px,.55fr) 18px minmax(150px,.55fr) auto; align-items: end; gap: 10px; border-left: 3px solid var(--coral); background: var(--coral-soft); }
.handover-form h4 { margin: 0; font-size: 12px; }
.handover-form p { margin: 5px 0 0; color: var(--muted); font-size: 9px; line-height: 1.5; }
.handover-form label span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 9px; }
.handover-form svg { align-self: center; color: var(--coral); }
.audit-list { margin-top: 12px; overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: white; }
.audit-item { padding: 10px 12px; display: grid; grid-template-columns: 125px minmax(130px,1fr) minmax(150px,1fr) 90px; gap: 12px; border-top: 1px solid var(--line); font-size: 10px; }
.audit-item:first-child { border-top: 0; }
.audit-item time, .audit-item span:last-child { color: var(--subtle); }
.notice-band { margin-top: 16px; padding: 11px 12px; display: flex; align-items: flex-start; gap: 8px; border-left: 3px solid var(--gold); background: var(--gold-soft); color: #6f511f; }
.notice-band svg { width: 15px; flex: 0 0 15px; }
.notice-band p { margin: 0; font-size: 10px; line-height: 1.6; }

.portal-dialog { width: min(760px, calc(100vw - 30px)); max-height: calc(100vh - 30px); padding: 0; overflow: auto; border: 0; border-radius: 8px; background: white; box-shadow: 0 20px 60px rgba(13,45,35,.22); }
.portal-dialog::backdrop { background: rgba(13,31,25,.52); }
.dialog-title-row { position: sticky; top: 0; z-index: 2; padding: 15px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); background: white; }
.dialog-title-row span { color: var(--green); font-size: 9px; font-weight: 800; }
.dialog-title-row h2 { margin: 4px 0 0; font-size: 17px; }
#dialogContent { padding: 18px; }
.customer-summary { padding-bottom: 15px; display: grid; grid-template-columns: minmax(150px,1.4fr) repeat(3, minmax(80px,.6fr)); gap: 10px; border-bottom: 1px solid var(--line); }
.customer-summary > div span, .customer-summary > div strong { display: block; }
.customer-summary > div span { color: var(--subtle); font-size: 8px; }
.customer-summary > div strong { margin-top: 5px; font-size: 12px; }
.customer-summary .summary-name strong { font-size: 16px; }
.customer-summary .summary-name small { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; }
.tracking-steps { margin-top: 16px; display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 6px; }
.tracking-step { min-height: 64px; padding: 9px 7px; display: grid; place-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 6px; text-align: center; cursor: pointer; }
.tracking-step input { position: absolute; opacity: 0; pointer-events: none; }
.tracking-step i { width: 20px; height: 20px; display: grid; place-items: center; border-radius: 50%; background: var(--paper); color: var(--muted); font-size: 9px; font-style: normal; }
.tracking-step span { font-size: 9px; font-weight: 700; }
.tracking-step:has(input:checked) { border-color: #a4c8b8; background: var(--green-soft); color: var(--green); }
.tracking-step:has(input:checked) i { background: var(--green); color: white; }
.tracking-form { margin-top: 15px; display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 11px; }
.tracking-form label > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 9px; font-weight: 700; }
.tracking-form select, .tracking-form input, .tracking-form textarea { width: 100%; min-height: 38px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 5px; background: white; outline: 0; color: var(--ink); font-size: 11px; }
.tracking-form textarea { resize: vertical; line-height: 1.55; }
.tracking-form .wide-field { grid-column: 1 / -1; }
.issue-field { padding: 11px; grid-column: 1 / -1; display: grid; grid-template-columns: 150px minmax(0,1fr); gap: 10px; background: var(--coral-soft); }
.history-block { margin-top: 15px; padding-top: 14px; border-top: 1px solid var(--line); }
.history-block > strong { font-size: 11px; }
.history-list { margin-top: 8px; display: grid; gap: 6px; }
.history-item { padding: 8px 10px; background: var(--paper); font-size: 9px; line-height: 1.55; }
.history-item time { color: var(--subtle); }
.dialog-actions { margin-top: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-actions span { color: var(--muted); font-size: 9px; }
.portal-toast { position: fixed; z-index: 100; left: 50%; bottom: 24px; min-width: 230px; max-width: min(420px, calc(100vw - 30px)); padding: 11px 14px; border-radius: 6px; background: var(--green-dark); color: white; text-align: center; font-size: 11px; opacity: 0; pointer-events: none; transform: translate(-50%, 15px); transition: opacity .2s, transform .2s; }
.portal-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1050px) {
  .staff-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .customer-row { grid-template-columns: minmax(150px,1.5fr) 90px 95px 105px 100px; }
  .customer-row .hide-mid { display: none; }
  .handover-form { grid-template-columns: 1fr 18px 1fr; }
  .handover-form > div { grid-column: 1 / -1; }
  .handover-form .portal-primary { grid-column: 1 / -1; justify-self: end; }
}

@media (max-width: 760px) {
  .login-view { display: block; background: var(--paper); }
  .login-panel { max-width: none; min-height: 100vh; padding: 26px 20px 34px; background: white; }
  .login-copy { margin-top: 38px; }
  .login-copy h1 { font-size: 25px; }
  .login-context { display: none; }
  .portal-shell { display: block; padding-bottom: 69px; }
  .portal-sidebar { position: fixed; top: auto; bottom: 0; left: 0; right: 0; z-index: 20; width: auto; height: 69px; padding: 7px 8px max(7px, env(safe-area-inset-bottom)); display: block; border-top: 1px solid var(--line); background: white; color: var(--ink); }
  .portal-sidebar .portal-brand, .portal-sidebar-note { display: none; }
  .portal-nav { height: 100%; margin: 0; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; overflow-x: auto; }
  .portal-nav button { min-width: 66px; min-height: 50px; padding: 5px 3px; flex-direction: column; justify-content: center; gap: 3px; color: var(--muted); font-size: 8px; text-align: center; }
  .portal-nav button svg { width: 17px; height: 17px; }
  .portal-nav button.is-active { background: var(--green-soft); color: var(--green); }
  .portal-nav button span:last-child { position: absolute; margin: -27px 0 0 26px; min-width: 16px; padding: 1px 4px; font-size: 8px; }
  .portal-topbar { min-height: 62px; padding: 10px 14px; }
  .portal-topbar h1 { font-size: 17px; }
  .local-status, .user-menu span { display: none; }
  .user-menu { padding-left: 0; border-left: 0; }
  .portal-top-actions { gap: 8px; }
  .portal-content { padding: 17px 14px 30px; }
  .page-intro { align-items: flex-start; flex-direction: column; gap: 8px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi-card { min-height: 92px; padding: 12px; }
  .kpi-card strong { font-size: 23px; }
  .toolbar { align-items: stretch; }
  .toolbar input, .toolbar select { width: 100%; min-width: 0; flex: 1 1 100%; }
  .toolbar-count { width: 100%; margin-left: 0; }
  .customer-row { padding: 13px; grid-template-columns: 1fr auto; gap: 10px; }
  .customer-row > div:not(.customer-identity):not(.mobile-status):not(.row-actions) { display: none; }
  .mobile-status { grid-column: 1; }
  .row-actions { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
  .staff-grid { grid-template-columns: 1fr 1fr; }
  .handover-form { grid-template-columns: 1fr; }
  .handover-form > svg { display: none; }
  .handover-form .portal-primary { grid-column: auto; justify-self: stretch; }
  .audit-item { grid-template-columns: 1fr 1fr; gap: 5px 10px; }
  .tracking-steps { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .tracking-form { grid-template-columns: 1fr; }
  .tracking-form .wide-field { grid-column: auto; }
  .issue-field { grid-column: auto; grid-template-columns: 1fr; }
  .customer-summary { grid-template-columns: 1fr 1fr; }
  .summary-name { grid-column: 1 / -1; }
  .dialog-actions { align-items: stretch; flex-direction: column; }
  .dialog-actions .portal-primary { width: 100%; }
  .security-actions { align-items: stretch; flex-direction: column; }
  .security-actions .portal-primary { width: 100%; }
}

@media (max-width: 430px) {
  .staff-grid { grid-template-columns: 1fr; }
  .tracking-steps { grid-template-columns: 1fr 1fr; }
  .tracking-step:last-child { grid-column: 1 / -1; }
}
