/*
 * Stylesheet intent:
 * Defines dashboard layout, component styling, and responsive behavior for the
 * OASIS browser simulator UI.
 */
/* Theme tokens */
:root {
  --bg-ink: #1f232a;
  --bg-dusk: #2f3a4c;
  --bg-frost: #f2f6f8;
  --line: #89a3b5;
  --panel: #ffffff;
  --text: #10212a;
  --accent: #0d6e83;
  --accent-strong: #084b5a;
  --green: #1f9f4a;
  --yellow: #c79200;
  --red: #bd2f2f;
}

* {
  box-sizing: border-box;
}

/* Base page sizing/reset */
html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Avenir Next", "Futura", "Trebuchet MS", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 18%, rgba(130, 190, 207, 0.35), transparent 36%),
    radial-gradient(circle at 88% 80%, rgba(141, 164, 194, 0.4), transparent 34%),
    linear-gradient(165deg, var(--bg-dusk), var(--bg-ink));
}

/* Top-level app regions */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 1rem;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  background: linear-gradient(100deg, rgba(14, 31, 47, 0.8), rgba(13, 57, 74, 0.75));
  color: #eef7fc;
}

/* Header branding + control strip */
.brand h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0.08em;
}

.brand p {
  margin: 0.2rem 0 0;
  opacity: 0.85;
  font-size: 0.85rem;
}

.run-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: end;
}

.run-controls label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
}

/* Form controls + button states */
button,
input,
select {
  font: inherit;
}

select,
input {
  border: 1px solid #8aa9b8;
  border-radius: 7px;
  padding: 0.33rem 0.45rem;
  background: #f3fbff;
  color: #13313e;
}

button {
  border: 1px solid var(--accent-strong);
  border-radius: 8px;
  padding: 0.4rem 0.62rem;
  background: linear-gradient(180deg, #1591ab, #0c6880);
  color: #f5ffff;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease, background 180ms ease;
}

button:hover {
  filter: brightness(1.06);
}

button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
  filter: saturate(0.45);
}

button:active {
  transform: translateY(1px) scale(0.985);
  filter: brightness(0.92);
}

button:focus-visible {
  outline: 2px solid #7ed2e6;
  outline-offset: 1px;
}

button.ui-press {
  animation: button-pop 180ms ease-out;
}

#startBtn,
#trafficStartBtn {
  border-color: #0c6132;
  background: linear-gradient(180deg, #2bb965, #168345);
}

#startBtn[aria-pressed="true"],
#trafficStartBtn[aria-pressed="true"] {
  border-color: #0c6132;
  box-shadow: 0 0 0 2px rgba(26, 124, 69, 0.25);
}

#pauseBtn,
#trafficPauseBtn {
  border-color: #7a2c2c;
  background: linear-gradient(180deg, #db5a5a, #ab3939);
}

#pauseBtn[aria-pressed="true"],
#trafficPauseBtn[aria-pressed="true"] {
  box-shadow: 0 0 0 2px rgba(171, 57, 57, 0.25);
}

#statusPanel.ui-flash {
  animation: status-pulse 340ms ease-out;
}

/* Micro-animations */
@keyframes button-pop {
  0% { transform: scale(0.96); }
  100% { transform: scale(1); }
}

@keyframes status-pulse {
  0% {
    border-color: #6cbad0;
    box-shadow: 0 0 0 0 rgba(22, 135, 168, 0.34);
  }
  100% {
    border-color: var(--line);
    box-shadow: 0 0 0 10px rgba(22, 135, 168, 0);
  }
}

/* Workspace split layout */
.workspace {
  flex: 1;
  min-height: 0;
  padding: 1rem;
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  grid-template-areas: "controls board";
  gap: 1rem;
}

.board-panel,
.control-panel {
  min-height: 0;
}

/* Board/canvas column */
.board-panel {
  grid-area: board;
  background: rgba(255, 255, 255, 0.93);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.board-header h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.03em;
}

.elapsed {
  font-size: 0.83rem;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  background: #d8ebf4;
  border: 1px solid #8cb0c1;
}

.intersection-card {
  position: relative;
  min-height: 360px;
  border-radius: 14px;
  border: 1px solid #98acbb;
  background:
    linear-gradient(180deg, #d4e5ef 0%, #eaf5fb 100%);
  overflow: hidden;
}

#geometryCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.canvas-help {
  margin: 0;
  font-size: 0.77rem;
  color: #23495a;
}

/* Ring and performance cards */
.rings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-areas:
    "r1 r2"
    ". perf";
  gap: 0.6rem;
}

.ring-card {
  border: 1px solid #97b1c2;
  border-radius: 10px;
  padding: 0.55rem;
  background: #eef6fa;
}

.ring-card h3 {
  margin: 0;
  font-size: 0.9rem;
}

.ring-card p {
  margin: 0.26rem 0 0;
  font-size: 0.8rem;
}

.ring-card-r1 {
  grid-area: r1;
}

.ring-card-r2 {
  grid-area: r2;
}

.perf-card {
  grid-area: perf;
  display: grid;
  gap: 0.2rem;
}

#perfCanvas {
  margin-top: 0.15rem;
  width: 100%;
  height: 116px;
  border: 1px solid #a2b8c6;
  border-radius: 8px;
  background: linear-gradient(180deg, #f7fcff, #e6f0f6);
}

/* Control/editor column */
.control-panel {
  grid-area: controls;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

/* Shared panel chrome */
.panel-block {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem;
}

.panel-block h2 {
  margin: 0 0 0.55rem;
  font-size: 0.9rem;
  letter-spacing: 0.03em;
}

.status-text,
.presence-text {
  margin: 0.25rem 0;
  font-size: 0.82rem;
}

/* Phase timing table */
.phase-table {
  display: grid;
  gap: 0.2rem;
  max-width: 100%;
  overflow-x: auto;
}

.phase-row {
  display: grid;
  grid-template-columns: 1.45rem repeat(5, 3.2rem) 1.9rem 2.1rem 3.6rem;
  gap: 0.14rem;
  align-items: center;
  min-width: 26.2rem;
}

.phase-row input[type="number"] {
  width: 100%;
  min-width: 2.8rem;
  max-width: 3.2rem;
  padding: 0.16rem 0.2rem;
  font-size: 0.74rem;
}

.phase-row label,
.phase-row span {
  font-size: 0.72rem;
}

.phase-row input[type="checkbox"] {
  justify-self: center;
}

.phase-pulse-btn {
  padding: 0.18rem 0.32rem;
  font-size: 0.72rem;
}

/* Traffic controls and table */
.traffic-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  margin: 0;
}

.inline-field {
  display: flex;
  align-items: center;
  gap: 0.32rem;
  font-size: 0.78rem;
  margin: 0;
}

.inline-field select,
.inline-field input {
  width: 6.2rem;
  padding: 0.2rem 0.3rem;
}

.traffic-stats {
  margin: 0.45rem 0 0.35rem;
  font-size: 0.78rem;
  color: #21495a;
}

.traffic-table {
  display: grid;
  gap: 0.25rem;
}

.traffic-row {
  display: grid;
  grid-template-columns: 1.4rem repeat(5, minmax(0, 1fr));
  gap: 0.25rem;
  align-items: center;
}

.traffic-row span {
  font-size: 0.75rem;
}

.traffic-row input[type="number"] {
  width: 100%;
  min-width: 0;
}

/* Sequence editor */
.seq-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 0.24rem;
  font-size: 0.74rem;
}

.seq-grid input[type="number"] {
  width: 100%;
  min-width: 0;
}

.seq-grid input[type="checkbox"] {
  width: auto;
  justify-self: center;
}

/* LCD editor */
.lcd-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 0.35rem;
  align-items: end;
}

.lcd-controls label {
  margin: 0;
}

.lcd-controls button {
  white-space: nowrap;
}

.lcd-keypad {
  margin-top: 0.45rem;
  border: 1px solid #9fb8c7;
  border-radius: 8px;
  padding: 0.45rem;
  background: #eef6fb;
  display: grid;
  gap: 0.35rem;
}

.lcd-nav {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.25rem;
}

.lcd-digits {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.25rem;
}

.lcd-digits button:last-child {
  grid-column: 1 / -1;
}

.lcd-entry-status {
  margin: 0;
  font-size: 0.74rem;
  color: #1f4557;
}

.lcd-text {
  margin-top: 0.45rem;
  width: 100%;
  min-height: 19rem;
  border: 1px solid #8ca9b7;
  border-radius: 8px;
  padding: 0.45rem;
  background: #f8fcff;
  font-family: "Courier New", "Menlo", monospace;
  font-size: 0.75rem;
  line-height: 1.18;
  resize: vertical;
}

/* Small-screen adaptations */
@media (max-width: 1040px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "board"
      "controls";
  }

  .rings {
    grid-template-columns: 1fr;
    grid-template-areas:
      "r1"
      "r2"
      "perf";
  }

  .intersection-card {
    height: min(45vh, 360px);
  }
}
