:root {
  font-family: "Inter", "Microsoft JhengHei", system-ui, sans-serif;
  color: #142536;
  background: #f0efee;
  --navy: #112739;
  --teal: #007c74;
  --teal-dark: #005d54;
  --border: #cbd3dc;
  --warn-bg: #fff3d6;
  --warn-fg: #7a4f01;
  --danger-bg: #ffe9e4;
  --danger-fg: #7e2520;
  --ok-bg: #e1f3ee;
  --ok-fg: #005d54;
  --neutral-bg: #e8ebf0;
  --neutral-fg: #3e4e60;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
aside { background: var(--navy); color: #fff; padding: 32px 14px; }
.brand { color: white; font-size: 28px; font-weight: 800; margin: 2px 12px 33px; }
nav { display: grid; gap: 7px; }
nav button { width: 100%; border: 0; text-align: left; background: transparent; color: white; font-size: 17px; padding: 14px 24px; border-radius: 8px; }
nav button:hover, nav button[aria-current="page"] { background: var(--teal); }
.nav-link { display: block; margin-top: 18px; padding: 12px 24px; border-radius: 8px; color: #b6d8d4; text-decoration: none; font-size: 15px; border: 1px solid rgba(255,255,255,.18); }
.nav-link:hover { background: rgba(255,255,255,.1); color: white; }
.portal-body { display: block; background: #f0efee; }
.portal-wrap { max-width: 960px; margin: 0 auto; padding: 28px 18px 48px; }
.portal-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 22px; }
.portal-main { padding: 0; max-width: none; }
.login-card { max-width: 440px; margin: 36px auto; }
.file-list { display: grid; gap: 10px; }
.file-item { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px; background: #fafbfc; }
.btn-link { display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); text-decoration: none; font-weight: 700; background: white; color: inherit; }
.btn-link.primary { background: var(--teal); border-color: var(--teal); color: white; }
.btn-link.primary:hover { background: var(--teal-dark); }
main { padding: 36px; max-width: 1600px; min-width: 0; }
.page-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 24px; }
h1 { font-size: clamp(28px, 3.6vw, 44px); margin: 0; letter-spacing: .025em; }
header p { margin: 4px 0 0; font-size: 18px; color: #435366; }
.context-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
h2 { margin: 0 0 16px; font-size: 22px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.panel, .metric { background: #fff; border: 1px solid var(--border); border-radius: 13px; padding: 20px 22px; }
.panel { margin-bottom: 22px; }
.metric h2 { font-size: 16px; margin-bottom: 8px; color: #435366; }
.metric strong { color: var(--teal); font-size: 40px; line-height: 1.1; }
.metric.warn strong { color: #b4690e; }
.metric small { color: #526273; font-size: 16px; font-weight: 700; margin-left: 6px; }
.filters { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin: 0 0 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.panel-head h2 { margin: 0; }
label { display: grid; gap: 6px; font-weight: 650; font-size: 14px; }
input, select, textarea, button { font: inherit; border-radius: 8px; border: 1px solid var(--border); padding: 8px 12px; }
input, select, textarea { min-height: 40px; background: white; color: inherit; max-width: 100%; }
textarea { min-height: 76px; resize: vertical; }
button { cursor: pointer; background: white; color: inherit; font-weight: 700; }
button:disabled { opacity: .5; cursor: default; }
button.small { padding: 5px 10px; font-size: 13px; }
.primary { background: var(--teal); color: white; border-color: var(--teal); }
.primary:hover:not(:disabled) { background: var(--teal-dark); }
:focus-visible { outline: 3px solid #399ed9; outline-offset: 2px; }
a { color: #006a62; font-weight: 700; }
.table { overflow: auto; max-inline-size: 100%; max-block-size: min(560px, 72vh); border: 1px solid var(--border); border-radius: 9px; background: #fff; }
table { width: 100%; border-collapse: separate; border-spacing: 0; text-align: left; }
thead { position: sticky; inset-block-start: 0; z-index: 1; }
th, td { padding: 10px 14px; border-bottom: 1px solid #e0e6ec; white-space: nowrap; }
th { background: #e8ebf0; font-weight: 700; }
tr:last-child td { border-bottom: 0; }
.muted { color: #526273; }
#notice { margin-bottom: 14px; padding: 12px 14px; border-radius: 8px; background: #d9f0eb; font-weight: 600; }
#notice.error { background: var(--danger-bg); color: var(--danger-fg); }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge.warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge.danger { background: var(--danger-bg); color: var(--danger-fg); }
.badge.neutral { background: var(--neutral-bg); color: var(--neutral-fg); }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 13px; margin: 16px 0; }
.form-grid { display: grid; gap: 12px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

/* Native Modal Dialog */
dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 24px;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  box-shadow: 0 18px 42px rgba(17, 39, 57, .22);
  color: inherit;
}
dialog:modal {
  overscroll-behavior: contain;
}
dialog::backdrop {
  background: rgba(17, 39, 57, .45);
  overflow: hidden;
  overscroll-behavior: contain;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.modal-title { font-size: 22px; margin: 0; }
.modal-close { border: 0; background: transparent; font-size: 20px; padding: 4px 8px; line-height: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

@media (max-width: 760px) {
  body { display: block; }
  aside { padding: 12px; }
  .brand { font-size: 20px; margin: 0 4px 8px; }
  nav { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; }
  nav button { font-size: 13px; text-align: center; padding: 8px 2px; }
  main { padding: 16px; }
  .metrics { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .panel, .metric { padding: 14px; }
  .metric h2 { font-size: 13px; }
  .metric strong { font-size: 28px; }
  .metric small { font-size: 12px; }
}
