/* Mobile-friendly, large font and large buttons. All times UTC. */

:root {
  --font-size-base: 1.25rem;
  --font-size-title: 1.75rem;
  --font-size-header: 1.5rem;
  --touch-min: 48px;
  --spacing: 1rem;
  --header-height: 10rem;
  --bg: #f5f5f5;
  --panel-bg: #fff;
  --button-bg: #2563eb;
  --button-bg-schedule: #64748b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: var(--font-size-base);
  line-height: 1.5;
  background: var(--bg);
  color: #111;
}

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--spacing) var(--spacing) var(--spacing);
}

.header {
  position: sticky;
  top: 0;
  z-index: 200;
  margin: 0;
  padding-top: var(--spacing);
  padding-bottom: var(--spacing);
  background: var(--bg);
}

.title {
  font-size: var(--font-size-title);
  font-weight: 700;
  margin: 0 0 0.5rem 0;
}

.active-envs {
  font-size: var(--font-size-base);
  margin: 0;
  word-break: break-word;
}

.refresh-note {
  font-size: 0.875rem;
  color: #64748b;
  margin: 0.25rem 0 0 0;
}

.sections {
  display: flex;
  flex-direction: column;
  gap: var(--spacing);
}

.panel {
  background: var(--panel-bg);
  border-radius: 8px;
  padding: 0 var(--spacing) var(--spacing) var(--spacing);
}

/* Table name: no top padding on panel so h2 reaches panel top (no white strip on load).
   Sticky, matches panel width and top radius, flush with table below. */
.panel h2 {
  font-size: var(--font-size-header);
  margin: 0;
  margin-left: -0.5rem;
  margin-right: -0.5rem;
  padding: var(--spacing) 0.5rem 0.5rem 0.5rem;
  min-height: calc(var(--touch-min) + 1rem);
  display: flex;
  align-items: center;
  position: sticky;
  top: var(--header-height);
  z-index: 100;
  background: var(--panel-bg);
  border-bottom: 1px solid #e2e8f0;
  border-radius: 8px 8px 0 0;
}

/* Covers the table row scrolling underneath; header (z-index: 200) stays on top */
.panel h2::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 24px;
  background: var(--panel-bg);
  border-radius: 8px 8px 0 0;
}

.section-wrap {
  overflow-x: auto;
  margin: 0 -0.5rem 0 -0.5rem;
  padding: 0 0.5rem;
}

.section-head.row,
.section-body .row {
  display: grid;
  gap: 0.5rem 1rem;
  padding: 0.5rem 0;
  align-items: center;
}

.section-head.row {
  font-weight: 600;
  background: #e2e8f0;
  padding: 0.5rem 0;
}

.section-head .cell,
.section-body .row .cell {
  min-width: 0;
}

/* Truncate text cells only; never truncate cells that contain buttons (Schedule / Immediate Action) */
.section-head .cell:not(.cell-actions),
.section-body .row .cell:not(.cell-actions) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-body .row:hover {
  background: #f8fafc;
}

/* 7 columns: Env, Name, Col3 (ASG/RCU), Active Since Discovery, Auto Action In, Schedule, Immediate. Flexible widths. */
.section-wrap.cols-7 .section-head.row,
.section-wrap.cols-7 .section-body .row {
  grid-template-columns: minmax(3rem, 0.6fr) minmax(4rem, 2fr) minmax(4rem, 1fr) minmax(4rem, 1fr) minmax(4rem, 1fr) minmax(8rem, 1.2fr) minmax(6rem, 1fr);
}

/* Long Running EC2: first column (Instance ID) wider to show full id (e.g. i-0123456789abcdef0). */
#wrap-longRunningEc2.section-wrap.cols-7 .section-head.row,
#wrap-longRunningEc2.section-wrap.cols-7 .section-body .row {
  grid-template-columns: minmax(12rem, 1.2fr) minmax(4rem, 2fr) minmax(4rem, 1fr) minmax(4rem, 1fr) minmax(4rem, 1fr) minmax(6rem, 1fr) minmax(6rem, 1fr);
}

/* 6 columns. Flexible widths. */
.section-wrap.cols-6 .section-head.row,
.section-wrap.cols-6 .section-body .row {
  grid-template-columns: minmax(3rem, 0.6fr) minmax(4rem, 2fr) minmax(4rem, 1fr) minmax(4rem, 1fr) minmax(8rem, 1.2fr) minmax(6rem, 1fr);
}

/* 2 columns: Stack Name, Status. */
.section-wrap.cols-2 .section-head.row,
.section-wrap.cols-2 .section-body .row {
  grid-template-columns: minmax(8rem, 2fr) minmax(6rem, 1fr);
}

.btn {
  display: inline-block;
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  padding: 0.5rem 0.75rem;
  font-size: var(--font-size-base);
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-scale-in {
  background: var(--button-bg);
  color: #fff;
}

.btn-schedule {
  background: var(--button-bg-schedule);
  color: #fff;
}

.btn-stop {
  background: var(--button-bg);
  color: #fff;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.select-schedule {
  height: var(--touch-min);
  min-height: var(--touch-min);
  min-width: 5rem;
  font-size: var(--font-size-base);
  padding: 0.25rem 0.5rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: var(--panel-bg);
  cursor: pointer;
}

/* Mobile: main header wraps and is tall; section title must stick fully below it */
@media (max-width: 767px) {
  :root {
    --header-height: 16rem;
  }
  .panel h2::before {
    height: 48px;
  }
}

/* Narrow desktop: taller cover so table row doesn't peek above section title */
@media (min-width: 768px) and (max-width: 1023px) {
  .panel h2::before {
    height: 48px;
  }
}

@media (min-width: 768px) {
  :root {
    --font-size-base: 1rem;
    --font-size-title: 1.5rem;
    --font-size-header: 1.25rem;
    --header-height: 8rem;
  }
  /* Compact section title height so text stays vertically centered, not near bottom */
  .panel h2 {
    min-height: 2.5rem;
  }
}

/* Login view: centered box, same origin so token can be stored */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: var(--spacing);
}

.login-box {
  max-width: 360px;
  width: 100%;
  background: var(--panel-bg);
  border-radius: 8px;
  padding: var(--spacing);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.login-box .title {
  margin-bottom: 0.5rem;
}

.login-message {
  margin: 0 0 1rem 0;
  color: #64748b;
  font-size: 0.9375rem;
}

.login-form label {
  display: block;
  margin: 0.75rem 0 0.25rem 0;
  font-weight: 500;
}

.login-form input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  min-height: var(--touch-min);
}

.login-form button {
  margin-top: 1.25rem;
  width: 100%;
  min-height: var(--touch-min);
}

.login-error {
  margin: 0.75rem 0 0 0;
  color: #dc2626;
  font-size: 0.875rem;
}
