/* =========================================================================
   CPWD Portal — Dashboard page styles
   ========================================================================= */

.dashboard-content { width: 100%; min-width: 0; max-width: 100%; padding: calc(var(--header-height) + 12px) 16px 16px; overflow-x: hidden; }

h2 { margin: 0; font-size: 13px; color: var(--heading); text-transform: uppercase; }
.info { font-weight: 400; }

/* ---- Work type switch (Construction / Maintenance / Both) --------------*/
.work-type-switch { padding: 10px 14px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.work-type-label { font-size: 11px; font-weight: 800; color: var(--heading); text-transform: uppercase; letter-spacing: .04em; }
.work-type-toggle { flex: 0 0 auto; }
.work-type-toggle button { min-width: 150px; }
@media (max-width: 600px) {
  .work-type-switch { flex-direction: column; align-items: stretch; }
  .work-type-toggle { width: 100%; }
  .work-type-toggle button { min-width: 0; flex: 1; }
}

/* ---- Scope badge + per-scope blocks inside matrix panels ----------------*/
.scope-badge { flex: 0 0 auto; padding: 5px 10px; border-radius: 999px; background: var(--blue-soft); color: var(--blue); font-size: 10px; font-weight: 800; white-space: nowrap; }
.matrix-block + .matrix-block { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--border); }
.matrix-block-label { margin: 0 0 8px; font-size: 10px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---- Filter panel ----------------------------------------------------- */
.filter-panel { padding: 10px 12px; overflow: visible; }
.more-filter-control { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.filter-primary-row { display: grid; grid-template-columns: minmax(190px,1fr) minmax(190px,1fr) auto auto; gap: 10px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field span { font-size: 10px; color: var(--heading); font-weight: 800; }
.field select { width: 100%; height: 36px; background: var(--t-input-bg); border: 1px solid var(--t-input-border); border-radius: 6px; color: var(--text); padding: 0 30px 0 10px; }
.filter-actions { display: flex; align-items: end; justify-self: end; gap: 8px; }
.filter-actions .button { height: 36px; padding-inline: 15px; }

.show-more-filter { height: 36px; min-width: 150px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid #b9cce3; border-radius: 6px; background: var(--control-bg); color: var(--blue); font-size: 11px; font-weight: 800; white-space: nowrap; cursor: pointer; user-select: none; }
.show-more-filter:hover { background: #eaf3fd; border-color: #86acd7; }
.filter-button-icon { font-size: 14px; }
.show-less-text { display: none; }
.filter-chevron { transition: transform .18s ease; }
.more-filter-grid { display: none; grid-template-columns: repeat(6,minmax(125px,1fr)); gap: 10px; margin-top: 10px; padding-top: 10px; border-top: 1px solid #e2e9f2; }
#more-filter-toggle:checked ~ .filter-primary-row .show-more-text { display: none; }
#more-filter-toggle:checked ~ .filter-primary-row .show-less-text { display: inline; }
#more-filter-toggle:checked ~ .filter-primary-row .filter-chevron { transform: rotate(180deg); }
#more-filter-toggle:checked ~ .more-filter-grid { display: grid; }

/* ---- KPI cards ---------------------------------------------------------*/
.kpi-grid { width: 100%; display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 10px; margin-top: 10px; }
.kpi-card { min-width: 0; min-height: 90px; padding: 16px 20px; display: flex; flex-direction: column; justify-content: center; }
.kpi-card span { display: block; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.kpi-card strong { display: block; color: var(--heading); font-size: clamp(18px, 1.8vw, 26px); font-weight: 800; line-height: 1.15; white-space: normal; overflow-wrap: anywhere; }

/* ---- Lifecycle + matrix row --------------------------------------------*/
.upper-grid { width: 100%; min-width: 0; display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 10px; align-items: start; }

.lifecycle-panel { grid-column: 1 / -1; width: 100%; min-width: 0; padding: 16px 18px 18px; overflow: hidden; }
.lifecycle-panel h2 { margin-bottom: 14px; }
.lifecycle-flow.lifecycle-flow-five {
  width: 100%; min-width: 0; display: grid; grid-template-columns: repeat(5,minmax(0,1fr));
  gap: 12px; margin: 0; padding: 0; align-items: stretch; justify-content: stretch; overflow: visible;
}
.stage {
  position: relative; min-width: 0; min-height: 126px; display: grid;
  grid-template-columns: 44px minmax(0,1fr); grid-template-rows: auto 1fr auto; column-gap: 12px;
  align-items: center; padding: 14px 14px 13px; border: 1px solid #d8e3ef; border-radius: 10px;
  background: var(--surface-tint); text-align: left;
}
.stage:not(:last-child)::after {
  content: "\2192"; position: absolute; z-index: 2; top: 50%; right: -19px; width: 26px; height: 26px;
  display: grid; place-items: center; transform: translateY(-50%); color: #5d9bd3; background: var(--white);
  border-radius: 50%; font-size: 18px; font-weight: 800;
}
.stage-icon { grid-column: 1; grid-row: 1 / span 2; width: 42px; height: 42px; margin: 0; border-radius: 50%; display: grid; place-items: center; background: var(--white); font-weight: 900; }
.stage span { grid-column: 2; grid-row: 1 / span 2; min-height: 0; display: block; color: var(--text); font-size: 13px; line-height: 1.28; font-weight: 800; }
.stage span small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.2; font-weight: 600; }
.stage strong { grid-column: 1 / -1; grid-row: 3; display: block; margin: 12px 0 0; color: var(--heading); font-size: 20px; line-height: 1; text-align: center; }

.blue-outline { color: var(--blue); border: 1px solid var(--blue); }
.teal-outline { color: var(--teal); border: 1px solid var(--teal); }
.green-outline { color: var(--green); border: 1px solid var(--green); }
.orange-outline { color: var(--orange); border: 1px solid var(--orange); }
.purple-outline { color: var(--purple); border: 1px solid var(--purple); }
.amber-outline { color: var(--amber); border: 1px solid var(--amber); }

.matrix-stack { grid-column: 1 / -1; width: 100%; min-width: 0; display: grid; grid-template-rows: auto auto; gap: 12px; }
.matrix-panel { padding: 10px 12px; min-width: 0; overflow: hidden; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 10px; }
.segmented { display: inline-flex; border: 1px solid #a9bfd8; border-radius: 6px; overflow: hidden; flex: 0 0 auto; }
.segmented button { min-width: 150px; height: 30px; border: 0; background: var(--control-bg); color: var(--heading); font-size: 11px; font-weight: 800; cursor: pointer; }
.segmented button.selected { background: var(--blue); color: var(--on-accent); }
.table-scroll { overflow-x: auto; }
table { width: 100%; }
.matrix-table { min-width: 900px; table-layout: fixed; font-size: 11px; }
.matrix-table th { background: var(--navy-2); color: #fff; border: 1px solid var(--table-border-strong); padding: 7px 6px; text-align: center; }
.matrix-table th:first-child { width: 28%; text-align: left; }
.matrix-table td { border: 1px solid var(--border); padding: 6px 8px; text-align: right; }
.matrix-table td:first-child { text-align: left; }
.matrix-table tbody tr:nth-child(even) { background: var(--row-alt); }
.matrix-table tbody td:nth-child(2n) { color: var(--blue); }
.total-row { font-weight: 800; background: var(--row-total) !important; }

/* ---- Analytics row (state tables + fund distribution) -------------------*/
.analytics-grid { display: grid; grid-template-columns: 1fr 1fr 2.7fr; gap: 10px; margin-top: 10px; align-items: stretch; }
.state-panel { padding: 12px; min-width: 0; }
.state-panel .panel-heading select { width: 160px; height: 32px; font-size: 9px; border: 1px solid var(--input-border); border-radius: 6px; }
.simple-table { font-size: 11px; }
.simple-table th { background: var(--navy-2); color: #fff; padding: 9px 10px; text-align: left; border: 1px solid var(--table-border-strong); }
.simple-table th:not(:first-child), .simple-table td:not(:first-child) { text-align: right; }
.simple-table td { padding: 7px 10px; border: 1px solid var(--border); }
.simple-table tbody tr:nth-child(even) { background: var(--row-alt); }
.top-state { font-weight: 800; }
.top-state td:last-child { color: var(--red); }
.pagination { text-align: center; color: var(--t-icon); font-size: 9px; padding-top: 8px; word-spacing: 6px; }
.view-all { display: block; text-align: center; color: var(--t-icon); font-weight: 800; font-size: 9px; margin-top: 15px; }

/* ---- Fund distribution -------------------------------------------------*/
.fund-distribution-panel { grid-column: 3; padding: 12px; min-width: 0; }
.fund-control, .work-control { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.fund-distribution-layout { display: grid; grid-template-columns: minmax(270px,.82fr) minmax(430px,1.48fr); gap: 20px; margin-top: 13px; align-items: start; }
.fund-chart-area { min-width: 0; display: grid; grid-template-columns: 190px minmax(180px,1fr); gap: 18px; align-items: center; }
.fund-donut {
  position: relative; width: 180px; aspect-ratio: 1; border-radius: 50%; overflow: hidden;
  background: conic-gradient(var(--blue) 0 44.72%, var(--teal) 44.72% 67.72%, var(--purple) 67.72% 85.35%, var(--orange) 85.35% 95.43%, #7a8798 95.43% 100%);
  box-shadow: inset 0 0 0 2px rgba(0,59,115,.1), 0 2px 8px rgba(0,59,115,.1);
}
.fund-donut-hole { position: absolute; inset: 37px; z-index: 2; border-radius: 50%; background: var(--white); display: grid; place-content: center; text-align: center; box-shadow: 0 0 0 1px var(--border); }
.fund-donut-hole strong { font-size: 22px; color: var(--heading); }
.fund-donut-hole span { margin-top: 4px; color: var(--muted); font-size: 9px; font-weight: 700; }
.fund-legend { display: grid; gap: 8px; }
.fund-legend label { min-height: 32px; display: grid; grid-template-columns: 12px minmax(0,1fr) auto; gap: 10px; align-items: center; padding: 7px 10px; border: 1px solid transparent; border-radius: 8px; cursor: pointer; color: var(--text); font-size: 9px; transition: all .2s ease; }
.fund-legend label:hover { background: #f0f5fa; border-color: #b8d4e8; }
.fund-legend label > span { width: 12px; height: 12px; border-radius: 50%; transition: transform .2s ease; }
.fund-legend label:hover > span { transform: scale(1.2); }
.fund-legend b { font-size: 8px; font-weight: 700; }
.fund-legend strong { font-size: 9px; color: var(--heading); }
.legend-budgetary > span { background: var(--blue); } .legend-loa > span { background: var(--teal); }
.legend-deposit > span { background: var(--purple); } .legend-css > span { background: var(--orange); } .legend-others > span { background: #7a8798; }
#fund-budgetary:checked ~ .fund-distribution-layout .legend-budgetary,
#fund-loa:checked ~ .fund-distribution-layout .legend-loa,
#fund-deposit:checked ~ .fund-distribution-layout .legend-deposit,
#fund-css:checked ~ .fund-distribution-layout .legend-css,
#fund-others:checked ~ .fund-distribution-layout .legend-others { background: var(--blue-soft); border-color: #9fc1e7; }

.fund-table-area { min-width: 0; }
.fund-table-header { min-height: 34px; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.table-eyebrow { display: block; color: var(--muted); font-size: 7px; text-transform: uppercase; font-weight: 800; letter-spacing: .04em; }
.selected-fund-name { display: none; margin-top: 2px; color: var(--heading); font-size: 11px; }
#fund-budgetary:checked ~ .fund-distribution-layout .name-budgetary,
#fund-loa:checked ~ .fund-distribution-layout .name-loa,
#fund-deposit:checked ~ .fund-distribution-layout .name-deposit,
#fund-css:checked ~ .fund-distribution-layout .name-css,
#fund-others:checked ~ .fund-distribution-layout .name-others { display: block; }
.fund-work-toggle label { min-width: 92px; height: 28px; display: grid; place-items: center; background: var(--control-bg); color: var(--heading); font-size: 11px; font-weight: 800; cursor: pointer; }
#work-maintenance:checked ~ .fund-distribution-layout .fund-work-toggle label[for="work-maintenance"],
#work-construction:checked ~ .fund-distribution-layout .fund-work-toggle label[for="work-construction"] { background: var(--blue); color: var(--on-accent); }
.fund-table-view { display: none; }
#fund-budgetary:checked ~ #work-construction:checked ~ .fund-distribution-layout .fund-budgetary.work-construction,
#fund-budgetary:checked ~ #work-maintenance:checked ~ .fund-distribution-layout .fund-budgetary.work-maintenance,
#fund-loa:checked ~ #work-construction:checked ~ .fund-distribution-layout .fund-loa.work-construction,
#fund-loa:checked ~ #work-maintenance:checked ~ .fund-distribution-layout .fund-loa.work-maintenance,
#fund-deposit:checked ~ #work-construction:checked ~ .fund-distribution-layout .fund-deposit.work-construction,
#fund-deposit:checked ~ #work-maintenance:checked ~ .fund-distribution-layout .fund-deposit.work-maintenance,
#fund-css:checked ~ #work-construction:checked ~ .fund-distribution-layout .fund-css.work-construction,
#fund-css:checked ~ #work-maintenance:checked ~ .fund-distribution-layout .fund-css.work-maintenance,
#fund-others:checked ~ #work-construction:checked ~ .fund-distribution-layout .fund-others.work-construction,
#fund-others:checked ~ #work-maintenance:checked ~ .fund-distribution-layout .fund-others.work-maintenance { display: block; }
.fund-detail-table { font-size: 11px; }
.fund-detail-table th:first-child, .fund-detail-table td:first-child { width: 45%; text-align: left; }
.fund-detail-table th:nth-child(2), .fund-detail-table td:nth-child(2) { width: 30%; text-align: left; }
.fund-detail-table th:last-child, .fund-detail-table td:last-child { width: 25%; text-align: left; }
.fund-detail-table td { padding-block: 7px; }

/* ---- Exceptions table ----------------------------------------------------*/
.exceptions-panel { margin-top: 10px; padding: 13px 16px 9px; }
.exceptions-panel h2 span { text-transform: none; font-weight: 600; }
.exception-table { min-width: 1550px; margin-top: 14px; font-size: 11px; }
.exception-table th { background: var(--navy-2); color: #fff; padding: 10px 8px; white-space: nowrap; }
.exception-table td { border: 1px solid var(--border); padding: 9px 8px; text-align: center; white-space: nowrap; }
.exception-table tbody tr:nth-child(even) { background: var(--row-alt); }
.status { font-weight: 800; }
.status.delayed { color: var(--red); }
.status.risk { color: var(--amber); }

/* ---- Responsive ---------------------------------------------------------*/
@media (max-width: 1500px) {
  .kpi-grid { grid-template-columns: repeat(4,1fr); }
  .analytics-grid { grid-template-columns: repeat(2,1fr); }
  .fund-distribution-panel { grid-column: 1 / -1; }
  .fund-distribution-layout { grid-template-columns: minmax(300px,.8fr) minmax(460px,1.2fr); }
}

@media (max-width: 1200px) {
  .filter-primary-row { grid-template-columns: minmax(160px,1fr) minmax(160px,1fr) auto auto; }
  .show-more-filter { min-width: 132px; padding-inline: 9px; }
  .more-filter-grid { grid-template-columns: repeat(3,minmax(145px,1fr)); }
  .kpi-card { padding: 12px 14px; }
}

@media (max-width: 1180px) {
  .lifecycle-flow.lifecycle-flow-five { grid-template-columns: repeat(5,minmax(150px,1fr)); overflow-x: auto; padding-bottom: 5px; }
  .stage { min-height: 118px; }
}

@media (max-width: 980px) {
  .fund-distribution-panel { grid-column: auto; }
  .fund-distribution-layout { grid-template-columns: 1fr; }
  .fund-chart-area { grid-template-columns: 180px 1fr; justify-content: center; }
}

@media (max-width: 860px) {
  .filter-primary-row { grid-template-columns: repeat(2,minmax(150px,1fr)); }
  .show-more-filter { justify-self: start; }
  .filter-actions { justify-self: end; }
  .more-filter-grid { grid-template-columns: repeat(2,minmax(150px,1fr)); }
  .kpi-grid { grid-template-columns: repeat(2,minmax(165px,1fr)); overflow-x: auto; padding-bottom: 4px; }
  .analytics-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .lifecycle-flow.lifecycle-flow-five { grid-template-columns: 1fr; overflow: visible; }
  .stage { min-height: 82px; grid-template-columns: 40px minmax(0,1fr) auto; grid-template-rows: auto; }
  .stage:not(:last-child)::after { content: "\2193"; top: auto; right: 50%; bottom: -20px; transform: translateX(50%); }
  .stage-icon { grid-column: 1; grid-row: 1; width: 38px; height: 38px; }
  .stage span { grid-column: 2; grid-row: 1; }
  .stage strong { grid-column: 3; grid-row: 1; margin: 0; font-size: 17px; }
}

@media (max-width: 600px) {
  .dashboard-content { padding-inline: 8px; }
  .filter-primary-row, .more-filter-grid { grid-template-columns: 1fr; }
  .show-more-filter, .filter-actions { width: 100%; justify-self: stretch; }
  .filter-actions .button { flex: 1; }
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-card { min-height: 96px; }
  .panel-heading { align-items: stretch; flex-direction: column; }
  .segmented { width: 100%; }
  .segmented button { min-width: 0; flex: 1; }
  .state-panel .panel-heading select { width: 100%; }
  .fund-chart-area { grid-template-columns: 1fr; justify-items: center; }
  .fund-legend { width: 100%; }
  .fund-table-header { align-items: stretch; flex-direction: column; }
  .fund-work-toggle { width: 100%; }
  .fund-work-toggle label { min-width: 0; flex: 1; }
}
