:root {
  --navy: #0b3a5b;
  --navy-dark: #082c45;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --paper: #f4f7fb;
  --line: #d7e2ee;
  --ink: #0f172a;
  --muted: #64748b;
  --danger: #b91c1c;
  --ok: #047857;
  --shadow: 0 18px 50px rgba(8, 44, 69, 0.12);
  --app-sticky-height: 0px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  overflow-x: clip;
  background: var(--paper);
  color: var(--ink);
  font-family: "Be Vietnam Pro", ui-sans-serif, system-ui, sans-serif;
}

.setup-banner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: #fef3c7;
}

.bg-login {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(20, 184, 166, 0.28), transparent 55%),
    radial-gradient(900px 400px at 100% 0%, rgba(11, 58, 91, 0.45), transparent 50%),
    linear-gradient(165deg, #082c45 0%, #0b3a5b 42%, #115e59 100%);
}

.glass-card {
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

.app-shell {
  min-height: 100vh;
  background:
    linear-gradient(180deg, #e8f1f8 0%, var(--paper) 220px);
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0f766e, #0b3a5b);
  color: white;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.app-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
}

.app-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.app-header-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.app-header-text {
  min-width: 0;
}

#app-title {
  font-size: 0.95rem;
  margin: 0;
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: auto;
}

.header-subline {
  display: block;
  margin: 0;
  line-height: 1.45;
  font-size: 12px;
}

.header-subline #greeting {
  color: #475569;
}

.header-subline-dot {
  margin: 0 4px;
  color: #94a3b8;
}

.header-context {
  font-weight: 600;
  color: #0f766e;
}

.header-date {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: 12px;
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  color: #0f766e;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}

.header-date-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.header-date input[type="date"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  border: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: #0b3a5b;
  cursor: pointer;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.icon-btn:hover {
  background: #f8fafc;
}

.icon-btn-logout {
  color: #b91c1c;
  border-color: #fecaca;
  background: #fff1f2;
}

.icon-btn-label {
  display: none;
  font-size: 0.8rem;
  font-weight: 600;
}

.icon-btn.is-spinning svg {
  animation: spin-reload 0.8s linear infinite;
}

@keyframes spin-reload {
  to { transform: rotate(360deg); }
}

.role-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #115e59;
  font-size: 0.8rem;
  font-weight: 600;
}

.app-sticky-top > header {
  position: sticky;
  top: 0;
  z-index: 20;
}

.kpi-summary {
  width: 100%;
  padding: 12px 16px 0;
}

.kpi-summary-inner {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem 1.1rem;
  box-shadow: 0 8px 24px rgba(11, 58, 91, 0.04);
}

.stat-card-label {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-card-value {
  margin: 0.35rem 0 0;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.15;
}

.panel {
  background: white;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th {
  text-align: left;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
  white-space: nowrap;
}

.data-table td {
  padding: 0.8rem 0.85rem;
  border-bottom: 1px solid #eef3f8;
  vertical-align: middle;
}

.data-table tbody tr:hover td {
  background: #f0fdfa;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  min-width: 1280px;
}

.report-table th,
.report-table td {
  border: 1px solid #cbd5e1;
  padding: 4px 6px;
  text-align: center;
  white-space: nowrap;
}

.report-table thead th {
  background: #f8fafc;
  font-weight: 600;
  color: #0f172a;
  line-height: 1.25;
}

.report-table td:nth-child(2),
.report-table th.sticky-col-2 {
  text-align: left;
}

.report-table .tree-parent {
  cursor: pointer;
}

.report-table .tree-parent.tree-l1 td {
  background: #0b3a5b;
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.report-table .tree-parent.tree-l1:hover td {
  background: #082c45 !important;
}

.report-table .tree-parent.tree-l1 td:nth-child(n+3) {
  text-transform: none;
  letter-spacing: 0;
}

.report-table .tree-parent.tree-l1 td:first-child {
  text-transform: none;
  letter-spacing: 0;
}

.report-table .tree-parent.tree-l1 td.cell-green { background: #86efac !important; color: #0f172a; text-transform: none; }
.report-table .tree-parent.tree-l1 td.cell-cyan { background: #67e8f9 !important; color: #0f172a; text-transform: none; }
.report-table .tree-parent.tree-l1 td.cell-orange { background: #fdba74 !important; color: #0f172a; text-transform: none; }

.report-table .tree-parent.tree-l2 td {
  background: #e0f2fe;
  font-weight: 700;
  color: #0c4a6e;
}

.report-table .tree-parent.tree-l2:hover td {
  background: #bae6fd !important;
}

.report-table .tree-parent.tree-l2 td.cell-green { background: #86efac !important; }
.report-table .tree-parent.tree-l2 td.cell-cyan { background: #67e8f9 !important; }
.report-table .tree-parent.tree-l2 td.cell-orange { background: #fdba74 !important; }

.report-table .tree-parent.tree-l2 td:nth-child(2) {
  padding-left: 22px;
}

.report-table .tree-parent.tree-l2-root td:nth-child(2) {
  padding-left: 12px;
}

.report-table .tree-child td {
  background: #ffffff;
  font-weight: 400;
}

.report-table .tree-child td:nth-child(2) {
  padding-left: 44px;
}

.report-table .tree-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-right: 6px;
  border-radius: 4px;
  border: 1px solid #93c5fd;
  background: #fff;
  color: #1d4ed8;
  font-size: 11px;
  line-height: 1;
  flex-shrink: 0;
}

.report-table .tree-l1 .tree-toggle {
  border-color: #99f6e4;
  color: #0f766e;
}

.report-table .tree-name {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.report-table .tree-count {
  margin-left: 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.85;
}

.report-table .tree-l1 .tree-count {
  color: #99f6e4;
}

.report-table .tree-l2 .tree-count {
  color: #0369a1;
}

.report-table .tree-leaf-mark {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 8px;
  margin-left: 4px;
  border-radius: 999px;
  background: #94a3b8;
}

.report-table tfoot td {
  font-weight: 800;
  background: #0b3a5b;
  color: #fff;
}

.report-table tfoot td.cell-green,
.report-table tfoot td.cell-cyan,
.report-table tfoot td.cell-orange {
  color: #0f172a;
}

.cell-green { background: #bbf7d0 !important; }
.cell-cyan { background: #a5f3fc !important; }
.cell-orange { background: #fed7aa !important; }

.report-table tbody tr:hover td { background: #f8fafc; }
.report-table tbody tr.tree-parent.tree-l1:hover td { background: #082c45 !important; }
.report-table tbody tr.tree-parent.tree-l1:hover td.cell-green { background: #86efac !important; }
.report-table tbody tr.tree-parent.tree-l1:hover td.cell-cyan { background: #67e8f9 !important; }
.report-table tbody tr.tree-parent.tree-l1:hover td.cell-orange { background: #fdba74 !important; }
.report-table tbody tr.tree-parent.tree-l2:hover td { background: #bae6fd !important; }
.report-table tbody tr.tree-parent.tree-l2:hover td.cell-green { background: #86efac !important; }
.report-table tbody tr.tree-parent.tree-l2:hover td.cell-cyan { background: #67e8f9 !important; }
.report-table tbody tr.tree-parent.tree-l2:hover td.cell-orange { background: #fdba74 !important; }
.report-table tbody tr:hover td.cell-green { background: #86efac !important; }
.report-table tbody tr:hover td.cell-cyan { background: #67e8f9 !important; }
.report-table tbody tr:hover td.cell-orange { background: #fdba74 !important; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-on { background: #dcfce7; color: #166534; }
.badge-off { background: #fee2e2; color: #991b1b; }

.hidden { display: none !important; }

.table-wrap { overflow-x: auto; }

#toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 60;
}

.toast-item {
  background: #0f172a;
  color: white;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  margin-top: 0.5rem;
  box-shadow: 0 12px 30px rgba(0,0,0,.2);
  font-size: 0.875rem;
}

select:disabled,
select.is-locked {
  background: #f1f5f9;
  color: #334155;
  cursor: not-allowed;
  opacity: 1;
  pointer-events: none;
}

input:focus, select:focus, button:focus-visible {
  outline: 2px solid #14b8a6;
  outline-offset: 1px;
}

.emp-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-left: 6px;
  border: 1px solid #99f6e4;
  border-radius: 999px;
  background: #f0fdfa;
  color: #0f766e;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}

.emp-toggle:hover,
.emp-toggle.is-open {
  background: #0f766e;
  color: #fff;
  border-color: #0f766e;
}

.emp-eye-icon {
  width: 14px;
  height: 14px;
}

.emp-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid #99f6e4;
  border-top-color: #0f766e;
  border-radius: 50%;
  animation: spin-reload 0.6s linear infinite;
}

.emp-detail-row td {
  padding: 0 !important;
  background: #f8fafc !important;
  text-align: left !important;
  white-space: normal !important;
  font-weight: 400 !important;
  text-transform: none !important;
}

.emp-sub {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
}

.emp-sub.is-open {
  max-height: 420px;
  overflow: auto;
  opacity: 1;
  animation: emp-slide 0.28s ease;
  padding: 8px 10px 12px;
}

@keyframes emp-slide {
  from { max-height: 0; opacity: 0; }
  to { max-height: 420px; opacity: 1; }
}

.emp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
}

.emp-table th,
.emp-table td {
  border: 1px solid #e2e8f0;
  padding: 6px 8px;
  text-align: left;
  white-space: nowrap;
}

.emp-table th {
  background: #ecfeff;
  color: #0f766e;
  font-weight: 700;
}

.emp-table td.emp-name,
.emp-table th.emp-name {
  white-space: normal;
  min-width: 9.5rem;
  width: 38%;
}

.emp-table td.emp-name {
  font-weight: 600;
  color: #0b3a5b;
}

.emp-status {
  margin: 0;
  padding: 8px 4px;
  font-size: 12px;
  color: #64748b;
}

.emp-error {
  color: #b91c1c;
}

.emp-caption {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  color: #0b3a5b;
}

.emp-caption b {
  color: #0f766e;
}

td.emp-kpi {
  cursor: pointer;
}

td.emp-kpi.is-active {
  outline: 2px solid #0f766e;
  outline-offset: -2px;
}

@media (min-width: 768px) {
  .icon-btn-logout {
    width: auto;
    padding: 0 12px;
    color: #334155;
    border-color: var(--line);
    background: #fff;
  }

  .icon-btn-label {
    display: inline;
  }

  .mobile-report {
    display: none;
  }

  .desktop-table {
    display: block;
  }
}

@media (max-width: 767px) {
  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    font-size: 12px;
  }

  .app-header-text #app-title,
  #app-title {
    font-size: 0.82rem;
  }

  .header-subline,
  .header-subline #greeting {
    font-size: 0.72rem;
  }

  .role-pill,
  #report-caption {
    display: none !important;
  }

  .header-date {
    min-height: 36px;
    padding: 0 8px;
    font-size: 12px;
  }

  @media (max-width: 400px) {
    .header-date-icon { display: none; }
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }

  .scope-text,
  .filter-hint,
  .desktop-table,
  #report-title,
  .page-info {
    display: none !important;
  }

  .filter-hint {
    margin: 0 !important;
  }

  .filter-dropdowns select {
    max-width: 100%;
    text-overflow: ellipsis;
  }

  .app-sticky-top {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    background: #e8f1f8;
    box-shadow: 0 8px 18px rgba(8, 44, 69, 0.1);
  }

  .app-sticky-top > header {
    position: static;
    background: #fff;
  }

  #app-view.app-shell {
    padding-top: var(--app-sticky-height);
  }

  .kpi-summary {
    padding: 6px 10px 8px;
    background: #e8f1f8;
    border-bottom: 1px solid var(--line);
  }

  .kpi-summary-inner {
    gap: 6px;
  }

  .stat-card {
    padding: 0.32rem 0.4rem;
    border-radius: 10px;
  }

  .stat-card-label {
    font-size: 0.58rem;
    letter-spacing: 0.02em;
  }

  .stat-card-value {
    margin-top: 1px;
    font-size: 1.02rem;
  }

  .report-toolbar {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .report-toolbar > div:first-child {
    display: none !important;
  }

  .report-toolbar h2 {
    font-size: 0.85rem;
  }

  .report-table {
    min-width: 0;
  }

  .mobile-report {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
  }

  .m-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    overflow: hidden;
  }

  .m-card-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px 8px;
  }

  .m-card .tree-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: 1px solid #93c5fd;
    background: #fff;
    color: #1d4ed8;
    font-size: 14px;
    line-height: 1;
    flex-shrink: 0;
  }

  .m-card-head h3 {
    margin: 0;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--navy);
    line-height: 1.3;
    flex: 1;
  }

  .m-card-sub {
    margin: 0;
    padding: 0 12px 8px;
    font-size: 11px;
    color: var(--muted);
  }

  .m-card-l1 {
    background: #0b3a5b;
    border-color: #0b3a5b;
  }

  .m-card-l1 .m-card-head h3,
  .m-card-l1 .m-card-count {
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  .m-card-l1 .tree-toggle {
    border-color: #99f6e4;
    color: #0f766e;
  }

  .m-card-l2 {
    background: #e0f2fe;
    border-color: #7dd3fc;
  }

  .m-card-l2 .m-card-head h3 {
    color: #0c4a6e;
  }

  .m-card-l1,
  .m-card-l2 {
    cursor: pointer;
  }

  .m-card-count {
    font-size: 10px;
    font-weight: 600;
    opacity: 0.85;
    white-space: nowrap;
  }

  .kpi-strip {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 0 10px 10px;
  }

  .kpi {
    border: 0;
    width: 100%;
    font: inherit;
    cursor: pointer;
    border-radius: 12px;
    padding: 8px 6px;
    text-align: center;
    background: #f8fafc;
    -webkit-tap-highlight-color: transparent;
  }

  .kpi-static {
    cursor: default;
    pointer-events: none;
  }

  .kpi.is-active {
    box-shadow: inset 0 0 0 2px #0f766e;
  }

  .kpi b {
    display: block;
    font-size: 1.15rem;
    font-weight: 800;
    line-height: 1.1;
  }

  .kpi span {
    display: block;
    margin-top: 2px;
    font-size: 10px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
  }

  .kpi-navy { background: #e8f1f8; }
  .kpi-navy b { color: #0b3a5b; }
  .kpi-rose { background: #ffe4e6; }
  .kpi-rose b { color: #be123c; }
  .kpi-amber { background: #ffedd5; }
  .kpi-amber b { color: #c2410c; }

  .m-card-l1 .kpi-navy { background: rgba(255,255,255,.12); }
  .m-card-l1 .kpi-navy b { color: #fff; }
  .m-card-l1 .kpi-navy span { color: #99f6e4; }
  .m-card-l1 .kpi-rose { background: rgba(254, 202, 202, .25); }
  .m-card-l1 .kpi-rose b { color: #fecaca; }
  .m-card-l1 .kpi-rose span { color: #fecaca; }
  .m-card-l1 .kpi-amber { background: rgba(253, 186, 116, .28); }
  .m-card-l1 .kpi-amber b { color: #fdba74; }
  .m-card-l1 .kpi-amber span { color: #fdba74; }

  .m-details {
    border-top: 1px dashed #e2e8f0;
    padding: 8px 12px 10px;
  }

  .m-details summary {
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #0f766e;
    list-style: none;
  }

  .m-details summary::-webkit-details-marker { display: none; }

  .m-chip-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
  }

  .m-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 999px;
    background: #f1f5f9;
    padding: 4px 8px;
    font-size: 11px;
    color: #334155;
  }

  .m-chip b {
    color: var(--navy);
  }

  .m-total {
    background: #0b3a5b;
    color: #fff;
  }

  .m-card .emp-sub.is-open {
    padding: 0 10px 10px;
  }

  .m-card .emp-table {
    font-size: 11px;
  }

  .m-card .emp-table th,
  .m-card .emp-table td {
    padding: 5px 6px;
  }

  .m-total .m-card-head h3 { color: #fff; }
  .m-total .kpi-navy { background: rgba(255,255,255,.12); }
  .m-total .kpi-navy b, .m-total .kpi-navy span { color: #fff; }
  .m-total .kpi.is-active { box-shadow: inset 0 0 0 2px #99f6e4; }
  .m-card-l1 .kpi.is-active { box-shadow: inset 0 0 0 2px #99f6e4; }
}

@media print {
  .no-print { display: none !important; }
  body { background: white; }
  .panel { box-shadow: none; border: none; }
  .mobile-report { display: none !important; }
  .desktop-table { display: block !important; }
  .app-sticky-top { position: static !important; box-shadow: none !important; }
  #app-view.app-shell { padding-top: 0 !important; }
}
