/* ============================================================
   ServiceStacking — Base Stylesheet
   Default functional + visual styles. Theme files override :root
   variables and add brand-specific component overrides.
   ============================================================ */

:root {
  --bg: #f8f9fa; --card: #ffffff; --border: #dee2e6;
  --primary: #2563eb; --secondary: #7c3aed; --green: #16a34a;
  --red: #dc2626; --orange: #ea580c; --gray: #6b7280;
  --text: #1f2937; --light-text: #6b7280;
  --logo-stroke: #D51317;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
       background: var(--bg); color: var(--text); line-height: 1.6; }
.container { max-width: 1200px; margin: 0 auto; padding: 20px; }

/* Header */
.header { position: relative; background: var(--card); color: var(--text);
          padding: 28px 36px; border-radius: 10px; margin-bottom: 25px;
          border: 1px solid var(--border); overflow: hidden; }
.header::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0;
                  width: 5px; background: var(--primary); border-radius: 10px 0 0 10px; }
.header-inner { position: relative; z-index: 1; display: flex; align-items: center; gap: 24px; padding-left: 10px; }
.header-logo { flex-shrink: 0; width: 72px; height: 72px; }
.header-text { flex: 1; }
.header h1 { font-size: 1.8rem; margin-bottom: 4px; line-height: 1; }
.header h1 .arc-word { color: var(--primary); }
.header-tagline { font-size: 0.82rem; color: var(--light-text); font-style: italic; margin-bottom: 3px; }
.header .subtitle { color: var(--light-text); font-size: 0.82rem; letter-spacing: 0.05em; }
.subtitle-by { opacity: 0.5; }
.logout-btn { flex-shrink: 0; color: var(--light-text); font-size: 0.78rem; text-decoration: none; padding: 6px 14px; border: 1px solid var(--border); border-radius: 4px; transition: background 0.2s, color 0.2s; }
.logout-btn:hover { background: var(--border); color: var(--text); }

/* Step panels */
.step { background: var(--card); border-radius: 8px; padding: 20px;
        border: 1px solid var(--border); margin-bottom: 20px; }
.step-header { display: flex; align-items: center; gap: 10px; margin-bottom: 15px; }
.step-num { background: var(--primary); color: #fff; width: 28px; height: 28px;
            border-radius: 50%; display: flex; align-items: center; justify-content: center;
            font-size: 0.85rem; font-weight: 700; flex-shrink: 0; }
.step-header h2 { font-size: 1.15rem; border: none; margin: 0; padding: 0; }

/* Upload area */
.upload-area { border: 2px dashed var(--border); border-radius: 8px; padding: 30px;
               text-align: center; cursor: pointer; transition: border-color 0.2s; }
.upload-area:hover { border-color: var(--primary); }
.upload-area.active { border-color: var(--green); background: #f0fdf4; }
.upload-area input[type="file"] { display: none; }
.upload-status { margin-top: 12px; font-size: 0.9rem; color: var(--light-text); }
.upload-status.success { color: var(--green); }
.upload-status.error { color: var(--red); }

/* Field status chips */
.field-chip { display:inline-flex; align-items:center; gap:4px; padding:4px 10px;
              border-radius:12px; font-size:0.8rem; font-weight:600; border:1px solid; }
.field-chip.required.unmapped { background:#fef2f2; color:#dc2626; border-color:#fca5a5; }
.field-chip.required.mapped { background:#f0fdf4; color:#16a34a; border-color:#86efac; }
.field-chip.optional.unmapped { background:#f9fafb; color:#9ca3af; border-color:#e5e7eb; }
.field-chip.optional.mapped { background:#f0fdf4; color:#16a34a; border-color:#86efac; }
.field-chip.optional.disabled-field { background:#f3f4f6; color:#d1d5db; border-color:#e5e7eb;
  text-decoration:line-through; cursor:pointer; opacity:0.6; }
.field-chip.optional { cursor:pointer; }
.field-chip.optional:hover { opacity:0.8; }

/* Pending upload cards */
.pending-upload-card { background:#f8fafc; border:1px solid var(--border); border-radius:6px;
                       padding:12px; margin-bottom:8px; font-size:0.85rem; }
.pending-upload-card .pu-header { display:flex; justify-content:space-between; align-items:center;
                                   margin-bottom:8px; }
.pending-upload-card .pu-title { font-weight:600; }
.pending-upload-card .pu-meta { font-size:0.78rem; color:var(--light-text); }
.pending-upload-card .pu-delete { background:none; border:none; color:#ef4444; cursor:pointer;
                                   font-size:1.1rem; padding:0 4px; }
.pending-upload-card .mapping-row { display:flex; align-items:center; gap:8px; margin-bottom:4px; }
.pending-upload-card .mapping-row label { min-width:100px; font-size:0.82rem; }
.pending-upload-card .mapping-row select { padding:3px 6px; border:1px solid var(--border);
                                            border-radius:3px; font-size:0.82rem; flex:1; max-width:200px; }

/* Dataset list */
.dataset-list { margin-top: 12px; }
.dataset-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px;
                border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px;
                font-size: 0.85rem; cursor: pointer; transition: background 0.15s; }
.dataset-item:hover { background: #f8fafc; }
.dataset-item.active { border-color: var(--primary); background: #eff6ff; }
.dataset-item .ds-info { flex: 1; }
.dataset-item .ds-name { font-weight: 600; }
.dataset-item .ds-meta { color: var(--light-text); font-size: 0.8rem; }
.dataset-item .ds-badge { font-size: 0.72rem; padding: 2px 8px; border-radius: 10px;
                          background: var(--primary); color: #fff; }

/* Config layout */
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 768px) { .config-grid { grid-template-columns: 1fr; } }
.config-section { background: #f8fafc; border-radius: 6px; padding: 15px;
                  border: 1px solid #e2e8f0; }
.config-section h3 { font-size: 0.95rem; margin-bottom: 10px; color: var(--primary); }
.form-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.form-row label { font-size: 0.85rem; min-width: 130px; color: var(--text); }
.form-row input[type="number"], .form-row input[type="date"], .form-row input[type="text"] {
  width: 120px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 4px;
  font-size: 0.85rem; }
.form-row .unit { font-size: 0.8rem; color: var(--light-text); }
.service-item { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.service-item label { font-size: 0.85rem; cursor: pointer; }
.service-item .planned { font-size: 0.75rem; color: var(--orange);
                         font-style: italic; margin-left: 4px; }

/* DR event cards */
.dr-event-card { background:#fff; border:1px solid var(--border); border-radius:6px;
                 padding:10px 12px; margin-bottom:8px; font-size:0.84rem; position:relative; }
.dr-event-card .dr-row { display:flex; align-items:center; gap:6px; margin-bottom:4px; flex-wrap:wrap; }
.dr-event-card input[type="time"], .dr-event-card input[type="number"] {
  padding:3px 6px; border:1px solid var(--border); border-radius:3px; font-size:0.82rem; }
.dr-event-card input[type="time"] { width:100px; }
.dr-event-card input[type="number"] { width:80px; }
.dr-event-card .dr-label { font-size:0.78rem; color:var(--light-text); min-width:60px; }
.dr-event-card .dr-delete { background:none; border:none; color:#ef4444; cursor:pointer;
                             font-size:1.1rem; padding:0 4px; position:absolute; top:6px; right:6px; }
.dr-event-card select { padding:3px 6px; border:1px solid var(--border); border-radius:3px;
                         font-size:0.82rem; }
.dr-event-card input[type="date"] { padding:3px 6px; border:1px solid var(--border); border-radius:3px;
                                     font-size:0.82rem; width:140px; }
.dr-schedule-options { margin-top:2px; margin-bottom:2px; }
.dr-schedule-options label { font-size:0.78rem; margin-right:6px; cursor:pointer; }
.dr-schedule-options input[type="checkbox"] { margin-right:2px; }

/* Multi-stage timeline */
.ms-timeline { position: relative; padding-left: 28px; margin-top: 10px; }
.ms-timeline::before { content: ''; position: absolute; left: 11px; top: 18px; bottom: 18px;
                        width: 2px; background: #cbd5e1; }
.ms-stage { position: relative; margin-bottom: 14px; }
.ms-stage:last-child { margin-bottom: 0; }
.ms-stage-dot { position: absolute; left: -28px; top: 10px; width: 12px; height: 12px;
                border-radius: 50%; border: 2px solid var(--primary); background: #fff; z-index: 1; }
.ms-stage.active .ms-stage-dot { background: var(--primary); }
.ms-stage.dimmed { opacity: 0.4; pointer-events: none; }
.ms-stage-card { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px;
                 padding: 10px 12px; font-size: 0.82rem; }
.ms-stage.active .ms-stage-card { border-color: var(--primary); background: #eff6ff; }
.ms-stage-header { font-weight: 700; color: var(--primary); margin-bottom: 4px; font-size: 0.85rem; }
.ms-stage-gate { font-size: 0.75rem; color: var(--light-text); margin-bottom: 6px; }
.ms-stage-services { font-size: 0.76rem; color: var(--text); margin-bottom: 6px; }
.ms-stage-services span { background: #dbeafe; color: #1e40af; padding: 1px 6px; border-radius: 3px;
                           font-size: 0.72rem; margin-right: 4px; display: inline-block; margin-bottom: 2px; }
.ms-stage-param { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; flex-wrap: wrap; }
.ms-stage-param label { font-size: 0.76rem; color: var(--text); min-width: 90px; }
.ms-stage-param input { width: 52px; text-align: center; padding: 2px 4px; border: 1px solid var(--border);
                         border-radius: 3px; font-size: 0.78rem; }
.ms-stage-param .param-group { display: flex; align-items: center; gap: 3px; }
.ms-stage-param .param-label { font-size: 0.68rem; color: var(--light-text); }
.ms-lock-arrow { text-align: center; color: #94a3b8; font-size: 0.72rem; margin: 2px 0 2px -28px;
                 padding-left: 28px; }

/* Scenario panel */
.scenario-panel { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;
                  padding: 15px; margin-top: 20px; }
.scenario-panel h3 { font-size: 0.95rem; color: var(--primary); margin-bottom: 10px; }
.scenario-list { margin-bottom: 12px; }
.scenario-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px;
                border: 1px solid var(--border); border-radius: 6px; margin-bottom: 5px;
                font-size: 0.84rem; background: #fff; transition: all 0.15s; }
.scenario-row.active-scenario { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.scenario-row .sc-vis { cursor: pointer; width: 18px; height: 18px; accent-color: var(--primary); }
.scenario-row .sc-color { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.scenario-row .sc-name { font-weight: 600; cursor: pointer; flex-shrink: 0; }
.scenario-row .sc-name:hover { text-decoration: underline; }
.scenario-row .sc-params { color: var(--light-text); font-size: 0.78rem; flex: 1;
                            overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scenario-row .sc-result { font-weight: 700; white-space: nowrap; }
.scenario-row .sc-result.positive { color: var(--green); }
.scenario-row .sc-result.negative { color: var(--red); }
.scenario-row .sc-export-bat { background: none; border: 1px solid var(--primary); color: var(--primary);
                                cursor: pointer; font-size: 0.72rem; padding: 2px 6px; border-radius: 4px;
                                opacity: 0.6; white-space: nowrap; line-height: 1.4; }
.scenario-row .sc-export-bat:hover { opacity: 1; background: #eff6ff; }
.scenario-row .sc-delete { background: none; border: none; color: var(--red); cursor: pointer;
                            font-size: 1.1rem; padding: 0 4px; opacity: 0.5; }
.scenario-row .sc-delete:hover { opacity: 1; }

.run-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.run-btn { background: var(--primary); color: #fff; border: none; padding: 10px 28px;
           border-radius: 6px; font-size: 0.95rem; font-weight: 600; cursor: pointer;
           transition: background 0.2s; white-space: nowrap; }
.run-btn:hover { background: #1d4ed8; }
.run-btn:disabled { background: var(--gray); cursor: not-allowed; }
.scenario-name-input { padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px;
                        font-size: 0.85rem; width: 180px; }
.progress-bar { display: none; margin-top: 12px; }
.progress-bar.visible { display: block; }
.progress-inner { height: 4px; background: var(--primary); border-radius: 2px;
                  transition: width 0.3s ease; width: 0%; }
.progress-inner.indeterminate {
  animation: progress-anim 2s ease-in-out infinite;
}
@keyframes progress-anim {
  0% { width: 0%; } 50% { width: 70%; } 100% { width: 100%; }
}
.progress-text { font-size: 0.85rem; color: var(--light-text); }

/* Results */
#results-section { display: none; }
#results-section.visible { display: block; }
h2.section-title { font-size: 1.3rem; margin: 30px 0 15px; border-bottom: 2px solid var(--primary);
     padding-bottom: 5px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
         gap: 15px; margin-bottom: 20px; }
.card { background: var(--card); border-radius: 8px; padding: 18px;
        border: 1px solid var(--border); }
.card .label { font-size: 0.78rem; color: var(--light-text); text-transform: uppercase;
               letter-spacing: 0.05em; }
.card .value { font-size: 1.5rem; font-weight: 700; margin: 5px 0; }
.card .detail { font-size: 0.82rem; color: var(--light-text); }
.card.green .value { color: var(--green); }
.card.red .value { color: var(--red); }
.card.blue .value { color: var(--primary); }
.card.purple .value { color: var(--secondary); }
.card.orange .value { color: var(--orange); }
.chart-box { background: var(--card); border-radius: 8px; padding: 15px;
             border: 1px solid var(--border); margin-bottom: 20px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 768px) { .two-col { grid-template-columns: 1fr; } }

/* Comparison table */
.comparison-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-bottom: 20px; }
.comparison-table th, .comparison-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.comparison-table th { background: #f1f5f9; text-align: right; font-weight: 600; }
.comparison-table th:first-child { text-align: left; }
.comparison-table td { text-align: right; }
.comparison-table td:first-child { text-align: left; font-weight: 500; }
.comparison-table .col-header { text-align: center; font-weight: 700; border-bottom: 3px solid; }

/* Data table */
.table-wrap { max-height: 600px; overflow-y: auto; border: 1px solid var(--border);
              border-radius: 8px; margin-bottom: 20px; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th { background: #f1f5f9; padding: 8px 10px; text-align: right; cursor: pointer;
     border-bottom: 2px solid var(--border); position: sticky; top: 0; z-index: 1; }
th:first-child, th:nth-child(2) { text-align: left; }
td { padding: 6px 10px; text-align: right; border-bottom: 1px solid #f1f5f9; }
td:first-child, td:nth-child(2) { text-align: left; }
tr:hover { background: #f8fafc; }
.positive { color: var(--green); font-weight: 600; }
.negative { color: var(--red); font-weight: 600; }

/* Allocation per-timestep table */
#alloc-table input[type="number"] {
  width: 58px; padding: 2px 4px; border: 1px solid var(--border);
  border-radius: 3px; font-size: 0.78rem; text-align: right;
}
#alloc-table td { padding: 3px 6px; font-size: 0.78rem; }
#alloc-table th { font-size: 0.76rem; padding: 4px 6px; }
#alloc-table tr.peak-row { background: #fffbeb; }

/* Export button */
.export-btn { background: var(--primary); border: 1px solid var(--primary); color: #fff; padding: 6px 16px;
              border-radius: 4px; font-size: 0.85rem; cursor: pointer; margin-bottom: 10px; }
.export-btn:hover { background: #1d4ed8; }

/* Baseline button */
.baseline-btn { background: #fff !important; color: var(--primary) !important;
                border: 2px solid var(--primary) !important; }
.baseline-btn:hover:not(:disabled) { background: #eff6ff !important; }
.baseline-btn:disabled { color: var(--gray) !important; border-color: var(--border) !important;
                         background: #f1f5f9 !important; }

/* EMS Baselines */
.ems-section { background: #fffbeb; border: 1px solid #fbbf24; border-radius: 8px;
               padding: 15px; margin-bottom: 15px; }
.ems-section h3 { font-size: 0.95rem; color: #92400e; margin-bottom: 10px; }
.ems-strategy-desc { font-size: 0.82rem; color: var(--light-text); margin: 6px 0 10px; min-height: 2.4em; }
.tod-grid-container { margin: 10px 0; }
.tod-labels { display: grid; grid-template-columns: repeat(24, 1fr); gap: 1px; margin-bottom: 2px; }
.tod-labels span { font-size: 0.65rem; text-align: center; color: var(--light-text); }
.tod-grid { display: grid; grid-template-columns: repeat(24, 1fr); gap: 1px; }
.tod-cell { height: 32px; border-radius: 3px; cursor: pointer; border: 1px solid #e2e8f0;
            display: flex; align-items: center; justify-content: center;
            font-size: 0.6rem; font-weight: 600; user-select: none; transition: background 0.15s; }
.tod-cell.idle { background: #f1f5f9; color: #94a3b8; }
.tod-cell.charge { background: #3b82f6; color: #fff; }
.tod-cell.discharge { background: #f97316; color: #fff; }
.tod-cell:hover { opacity: 0.85; }
.tod-legend { display: flex; gap: 12px; margin-top: 6px; font-size: 0.75rem; color: var(--light-text); }
.tod-legend span { display: flex; align-items: center; gap: 4px; }
.tod-legend .swatch { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.tod-power-row { display: grid; grid-template-columns: repeat(24, 1fr); gap: 1px; margin-top: 1px; }
.tod-power-input { width: 100%; height: 22px; text-align: center; font-size: 0.6rem;
                   border: 1px solid #e2e8f0; border-radius: 2px; padding: 0;
                   box-sizing: border-box; }
.tod-power-input:disabled { background: #f8fafc; color: #cbd5e1; }
.tod-presets { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.tod-preset-btn { background: #fff; border: 1px solid #d1d5db; border-radius: 4px;
                  padding: 3px 10px; font-size: 0.75rem; cursor: pointer; color: var(--text); }
.tod-preset-btn:hover { background: #f8fafc; border-color: #9ca3af; }
.tod-preset-btn.active { background: #eff6ff; border-color: #3b82f6; color: #1d4ed8; font-weight: 600; }
.ems-run-btn { background: #f97316; color: #fff; border: none; padding: 8px 22px;
               border-radius: 6px; font-weight: 600; cursor: pointer; font-size: 0.9rem; }
.ems-run-btn:hover { background: #ea580c; }
.ems-run-btn:disabled { background: var(--gray); cursor: not-allowed; }

/* Warning modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000;
                 display: flex; align-items: center; justify-content: center; }
.modal-card { background: #fff; border-radius: 10px; padding: 25px; max-width: 520px;
              width: 90%; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal-card h3 { font-size: 1.1rem; margin-bottom: 12px; color: var(--orange); }
.modal-card p { font-size: 0.9rem; color: var(--text); margin-bottom: 10px; }
.modal-card ul { font-size: 0.85rem; color: var(--text); margin: 0 0 18px 18px; }
.modal-card ul li { margin-bottom: 6px; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 10px; }
.modal-buttons button { padding: 8px 20px; border-radius: 6px; font-size: 0.9rem;
                        font-weight: 600; cursor: pointer; }
.modal-btn-cancel { background: #f1f5f9; border: 1px solid var(--border); color: var(--text); }
.modal-btn-cancel:hover { background: #e2e8f0; }
.modal-btn-confirm { background: var(--primary); border: 1px solid var(--primary); color: #fff; }
.modal-btn-confirm:hover { background: #1d4ed8; }

/* Baseline scenario row styling */
.sc-color-square { width: 14px; height: 14px; border-radius: 2px; flex-shrink: 0; }

/* Dispatch drill-down */
.dispatch-hint { font-size: 0.85rem; color: var(--light-text); margin-bottom: 10px;
                 font-style: italic; }
