:root {
  --accent: #00688d;
  --accent-soft: #e8f4f8;
  --bg: #f7f6f8;
  --surface: #fff;
  --border: #e5e9ed;
  --text: #222b32;
  --muted: #5c6670;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(26, 35, 41, 0.04);
  --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #f7f6f8;
  color: #222b32;
  min-height: 100vh;
}

/* [hidden] must win over display:flex — otherwise login + app show together */
[hidden] {
  display: none !important;
}

/* One screen at a time — html class set in <head> before paint */
#login-view,
#boot-view,
#shell {
  display: none !important;
}

html.portal-guest #login-view {
  display: flex !important;
}

html.portal-boot #boot-view {
  display: flex !important;
}

html.portal-app #shell {
  display: flex !important;
  flex-direction: column;
}

.boot-screen {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #f7f6f8;
}

.boot-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 32px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
}

.boot-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #e5e9ed;
  border-top-color: #00688d;
  border-radius: 50%;
  animation: portal-spin 0.75s linear infinite;
}

.boot-text {
  margin: 0;
  font-size: 0.95rem;
  color: #5c6670;
}

@keyframes portal-spin {
  to { transform: rotate(360deg); }
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.panel {
  width: min(100%, 360px);
  padding: 28px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
}

h1 { margin: 0 0 8px; font-size: 1.5rem; }
.sub { margin: 0; color: #5c6670; font-size: 0.9rem; line-height: 1.45; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 20px 0 12px;
}

.field input {
  padding: 10px 12px;
  border: 1px solid #c9d1d9;
  border-radius: 8px;
  font-size: 1rem;
}

button {
  padding: 10px 14px;
  border: 0;
  border-radius: 8px;
  background: #00688d;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
}

button:hover { filter: brightness(1.05); }

button.ghost {
  background: #fff;
  color: #00688d;
  border: 1px solid #ccd5de;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  padding: 0 12px;
  min-height: 34px;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

button.ghost:hover:not(:disabled) {
  filter: none;
  border-color: #00a8e1;
  background: #f0faff;
  box-shadow: 0 4px 12px rgba(0, 136, 141, 0.12);
}

button.danger {
  background: #fff;
  color: #b42318;
  border: 1px solid #f0c4c0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  padding: 0 12px;
  min-height: 34px;
  transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
}

button.danger:hover:not(:disabled) {
  filter: none;
  background: #fff5f5;
  border-color: #c8051e;
  color: #c8051e;
  box-shadow: 0 4px 12px rgba(200, 5, 30, 0.12);
}

.error { color: #b42318; font-size: 0.85rem; margin-top: 10px; }

.shell {
  min-height: 100vh;
  flex-direction: column;
}

.portal-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  min-height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

#nav-back {
  display: none !important;
}

.portal-weeks-back {
  flex-shrink: 0;
  white-space: nowrap;
  z-index: 1;
  margin-right: 4px;
}

.portal-topbar button,
.card-actions button,
.brand-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.portal-topbar button svg,
.card-actions button svg,
.brand-btn svg { flex-shrink: 0; }

.brand-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  background: transparent;
  border: 0;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
}

.brand-btn:hover { background: var(--accent-soft); }
.brand-btn:hover .nav-title { color: var(--accent); }
.brand-btn svg { color: var(--accent); }

.nav-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

#portal-reset-btn,
#pay-archive-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

#portal-reset-btn svg,
#pay-archive-btn svg {
  display: block;
  flex-shrink: 0;
}

#pay-archive-btn svg {
  width: 17px;
  height: 17px;
  transform: translateY(-1px);
}

.pay-archive-topbar {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.pay-archive-topbar-label {
  font-size: 16px;
  font-weight: 600;
  color: #00688d;
  white-space: nowrap;
}

.pay-archive-year-select {
  height: 34px;
  padding: 0 28px 0 10px;
  border: 1px solid #ccd5de;
  border-radius: 8px;
  background: #fff;
  color: #222b32;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
}

.portal-download-slot {
  display: flex;
  align-items: center;
}

.portal-download-slot .dai-st-save-wrap {
  position: relative;
}

.portal-download-slot #dai-st-saveas-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 12px !important;
  border: 1px solid #ccd5de;
  border-radius: 8px;
  background: #fff;
  color: #00688d;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.portal-download-slot #dai-st-saveas-btn:hover:not(:disabled) {
  border-color: #00a8e1;
  background: #f0faff;
  box-shadow: 0 4px 12px rgba(0, 136, 141, 0.12);
}

.portal-download-slot .dai-st-save-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 50;
  min-width: 120px;
  padding: 4px;
  border: 1px solid #ccd5de;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(26, 35, 41, 0.12);
}

.portal-download-slot .dai-st-save-menu button {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: #fff;
  color: #222b32;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.portal-download-slot .dai-st-save-menu button:hover {
  background: #f0faff;
  color: #00688d;
}

.page {
  flex: 1;
  padding: 20px;
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.company-card,
.week-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid #ccd5de;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(26, 35, 41, 0.04);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.company-card:has(.company-card-main:hover),
.week-card:has(.week-card-main:hover) {
  border-color: #00a8e1;
  background: #f0faff;
  box-shadow: 0 4px 12px rgba(0, 136, 141, 0.12);
}

.company-card-main,
.week-card-main {
  min-width: 0;
  cursor: pointer;
}

.week-card-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  flex-shrink: 0;
  padding-left: 8px;
}

.week-card:not(:has(.week-card-badge)) {
  grid-template-columns: 1fr;
}

.card-title {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 700;
}

.card-meta {
  margin: 0;
  font-size: 0.85rem;
  color: #5c6670;
}

.phase-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 0;
  padding: 3px 10px;
  font-size: 14px;
  font-weight: 400;
  line-height: 20px;
  color: #222b32;
  background: #fff;
  border: 1px solid;
  border-radius: 999px;
  vertical-align: middle;
  text-transform: none;
  letter-spacing: normal;
}

.phase-badge::before {
  content: '';
  width: 1cap;
  height: 1cap;
  min-width: 9px;
  min-height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.phase-preliminary,
.phase-pending {
  border-color: #ccd5de;
}

.phase-preliminary::before,
.phase-pending::before {
  background: #6e777f;
}

.phase-paid {
  border-color: #c3eb5e;
}

.phase-paid::before {
  background: #ade422;
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.weeks-company {
  margin: 0 0 14px;
  font-size: 1.05rem;
  font-weight: 700;
}

#open-archive-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

#open-archive-btn svg {
  display: block;
  flex-shrink: 0;
}

/* Portal statement: back nav lives in topbar; hide in-panel header strip */
#portal-statement-mount #dai-statement-panel[data-portal-week-view] .dai-st-header,
#portal-statement-mount #dai-statement-panel[data-portal-archive-nav] .dai-st-header {
  display: none !important;
}

#portal-statement-mount #dai-statement-panel[data-portal-week-view] #dai-st-back,
#portal-statement-mount #dai-statement-panel[data-portal-archive-nav] #dai-st-back {
  display: none !important;
}

.empty {
  margin: 24px 0;
  padding: 20px;
  text-align: center;
  color: #5c6670;
  background: #fff;
  border: 1px dashed #ccd5de;
  border-radius: 10px;
}

.statement-page {
  max-width: none;
  padding: 0;
}

#portal-statement-mount {
  min-height: calc(100vh - 56px);
}

#portal-statement-mount #dai-statement-panel {
  min-height: calc(100vh - 56px);
}

#portal-statement-mount #dai-st-status.dai-st-kpi-bar-wrap {
  padding: 0 20px;
  margin-top: 4px;
}

#portal-statement-mount #dai-st-status.dai-st-kpi-bar-wrap .dai-st-kpi-bar {
  width: 100%;
}

#portal-statement-mount #dai-st-result {
  padding: 16px 20px 24px;
}

/* Pay Archive only — do not affect week statements */
#portal-statement-mount #dai-statement-panel[data-portal-archive-nav] #dai-st-result {
  padding: 16px 24px 24px;
  display: flex;
  justify-content: stretch;
}

#portal-statement-mount #dai-statement-panel[data-portal-archive-nav] .dai-st-pay-archive-layout {
  width: 100%;
  max-width: none;
  margin: 0;
}

#portal-statement-mount #dai-statement-panel[data-portal-archive-nav] .dai-st-archive-cards {
  width: 100%;
  max-width: none;
  margin: 0;
}

#portal-statement-mount #dai-statement-panel[data-portal-archive-nav] .dai-st-msg {
  width: 100%;
  max-width: none;
  margin: 0;
}

#pay-archive-download-all-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

#pay-archive-download-all-btn svg {
  display: block;
  flex-shrink: 0;
}

#portal-statement-mount .dai-st-msg {
  padding: 20px;
  text-align: center;
  color: #5c6670;
  background: #fff;
  border: 1px dashed #ccd5de;
  border-radius: 10px;
}

.home-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding-top: 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid #ccd5de;
}

.list-summary {
  margin: 12px 0 0 12px;
  padding: 0;
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  line-height: 1.4;
}

.list-toolbar {
  display: flex;
  gap: 10px;
  flex: 1;
  min-width: 0;
  max-width: 520px;
  justify-content: flex-end;
}

.search-wrap {
  position: relative;
  display: flex;
  flex: 1;
  min-width: 0;
}

.search-wrap svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.toolbar-search {
  flex: 1;
  min-width: 0;
  padding: 9px 12px 9px 34px;
  border: 1px solid #c9d1d9;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background: var(--surface);
}

.toolbar-select {
  padding: 9px 12px;
  border: 1px solid #c9d1d9;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.toolbar-search:focus,
.toolbar-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 104, 141, 0.12);
}

.skeleton-card {
  height: 72px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, #eef1f4 25%, #f6f8fa 37%, #eef1f4 63%);
  background-size: 400% 100%;
  animation: portal-shimmer 1.3s ease-in-out infinite;
}

@keyframes portal-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

@media (max-width: 640px) {
  .company-card,
  .week-card {
    grid-template-columns: 1fr;
  }
  .card-actions {
    justify-content: flex-end;
  }
  .page-head {
    flex-direction: column;
    align-items: stretch;
  }
  .home-head {
    flex-direction: column;
    align-items: stretch;
  }
  .list-toolbar {
    flex-direction: column;
    max-width: none;
  }
  .topbar-right button span { display: none; }
}
