/* ==========================================================================
   Skyward Leadership App

   The original single-file build carried ~800 lines of generic design-system
   CSS, most of it unused. This is only what the app actually renders:
   tokens, form controls, buttons, menus, the canvas stage, the map, dialogs,
   and the sign-in page.
   ========================================================================== */

/* --- Tokens --------------------------------------------------------------- */
:root {
  --font-sans: -apple-system, system-ui, "Segoe UI", sans-serif;
  --font-size: 14px;
  --font-size-small: 12px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --navy: #15354d;
  --navy-deep: #101922;
  --paper: #f6fbff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--navy-deep);
  color: #fff;
  font-family: var(--font-sans);
  font-size: var(--font-size);
  line-height: 1.5;
}

h1,
h2,
h3,
p {
  margin-block: 0;
}

/* --- Theme ---------------------------------------------------------------- */
#skyward-app {
  position: relative;
  width: 100%;
  min-height: 100vh;
  padding: 16px;
}

#skyward-app[data-theme="light"] {
  --graph-ink: #15354d;
  --graph-muted: #445d70;
  --graph-border: #a9bdca;
  --surface: #fff;
  --surface-ink: #15354d;
  --control-bg: #fff;
  --control-border: #c3d4e0;
  background: var(--paper);
  color: var(--navy);
}

#skyward-app[data-theme="dark"] {
  --graph-ink: #fff;
  --graph-muted: #d7e7f3;
  --graph-border: #7893a8;
  --surface: #182631;
  --surface-ink: #fff;
  --control-bg: #1e2f3d;
  --control-border: #3c5468;
  background: var(--navy-deep);
  color: #fff;
}

/* --- Utilities ------------------------------------------------------------ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.text-small {
  font-size: var(--font-size-small);
}

.text-muted {
  color: var(--graph-muted);
}

.card {
  border: 1px solid var(--graph-border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--surface-ink);
}

/* --- Form controls -------------------------------------------------------- */
.form-control,
.form-select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
  background: var(--control-bg);
  color: inherit;
  font: inherit;
}

.form-control:focus-visible,
.form-select:focus-visible,
.btn:focus-visible,
summary:focus-visible {
  outline: 2px solid #4da3ff;
  outline-offset: 2px;
}

textarea.form-control {
  resize: vertical;
}

.form-label {
  display: grid;
  gap: 6px;
  font-size: var(--font-size-small);
  color: var(--graph-muted);
}

.form-label > .form-control,
.form-label > .form-select {
  color: var(--surface-ink);
  font-size: var(--font-size);
}

.form-check {
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  cursor: pointer;
}

.form-check-input {
  width: 34px;
  height: 19px;
  margin: 0;
  accent-color: #4da3ff;
  cursor: pointer;
}

/* --- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
  background: var(--control-bg);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.btn:hover {
  border-color: #4da3ff;
}

.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  border-color: #2f7fd0;
  background: #2f7fd0;
  color: #fff;
  font-weight: 600;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
}

.btn-avatar {
  width: 34px;
  padding: 0;
  overflow: hidden;
  border-radius: var(--radius-pill);
}

.btn-avatar img {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-pill);
  object-fit: cover;
}

#skyward-app[data-theme="light"] .toolbar-group > .btn,
#skyward-app[data-theme="light"] .toolbar-group > .menu > summary {
  border-color: var(--navy);
  background: var(--navy);
  color: #fff;
}

/* --- Toolbar -------------------------------------------------------------- */
.viz-controls {
  position: relative;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 4px;
}

.brand-logo {
  display: block;
  width: 190px;
  height: auto;
  margin-right: auto;
}

#skyward-app[data-theme="dark"] .brand-logo-light,
#skyward-app[data-theme="light"] .brand-logo-dark,
#skyward-app[data-theme="dark"] .theme-dark-action,
#skyward-app[data-theme="light"] .theme-light-action {
  display: none;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.person-search {
  width: 200px;
  flex: 0 1 auto;
}

/* --- Menus ---------------------------------------------------------------- */
.menu {
  position: relative;
}

.menu > summary {
  list-style: none;
}

.menu > summary::-webkit-details-marker {
  display: none;
}

.menu-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 1100;
  display: grid;
  gap: 2px;
  width: max-content;
  min-width: 200px;
  padding: 6px;
  box-shadow: 0 18px 40px rgb(0 0 0 / 38%);
}

.menu-end > .menu-list {
  right: 0;
  left: auto;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.menu-item:hover {
  background: rgb(125 170 210 / 22%);
}

.menu-item[aria-checked="true"]::before {
  content: "✓";
  margin-right: -2px;
}

.menu-heading {
  padding: 6px 9px;
  color: var(--graph-muted);
  font-size: var(--font-size-small);
  overflow-wrap: anywhere;
}

/* --- Stage ---------------------------------------------------------------- */
.visual-workspace {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 14px;
  min-width: 0;
}

.visual-stage {
  flex: 1 1 auto;
  min-width: 0;
}

.graph-detail {
  min-height: 30px;
  color: var(--graph-muted);
  text-align: center;
}

#skyward-app canvas {
  display: block;
  width: 100%;
  height: calc(100vh - 150px);
  cursor: grab;
}

#skyward-app canvas:active {
  cursor: grabbing;
}

#skyward-app canvas[hidden] {
  display: none;
}

/* --- Person sidebar ------------------------------------------------------- */
.person-sidebar {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 15;
  display: grid;
  gap: 12px;
  width: 300px;
  padding: 16px;
}

.person-sidebar[hidden] {
  display: none;
}

.sidebar-actions {
  display: grid;
  gap: 8px;
}

/* --- Footer --------------------------------------------------------------- */
.feedback-footer {
  position: absolute;
  right: 18px;
  bottom: 10px;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--graph-muted);
  font-size: var(--font-size-small);
}

.feedback-footer a {
  color: var(--graph-muted);
}

.save-status[data-state="saving"] {
  color: #d99a2b;
}

.save-status[data-state="error"] {
  color: #e2603c;
  font-weight: 600;
}

/* --- State map ------------------------------------------------------------ */
.state-map {
  min-height: calc(100vh - 112px);
  padding-top: 4px;
}

.state-map[hidden] {
  display: none;
}

.world-map-frame {
  position: relative;
  width: 100%;
}

.leaflet-map {
  width: 100%;
  height: calc(100vh - 180px);
  min-height: 420px;
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.leaflet-tile-pane {
  transition: filter 0.2s ease;
}

#skyward-app .leaflet-control-container {
  color: var(--navy);
}

#skyward-app .leaflet-popup-content-wrapper,
#skyward-app .leaflet-popup-tip {
  background: var(--surface);
  color: var(--surface-ink);
}

.employee-map-marker-wrap {
  border: 0;
  background: transparent;
}

.employee-map-marker {
  display: grid;
  place-content: center;
  border: 2px solid rgb(255 255 255 / 90%);
  border-radius: 50%;
  background: radial-gradient(circle at 32% 25%, #ff9b81 0, #e5654f 48%, #a9382e 100%);
  color: #fff;
  text-align: center;
  box-shadow: 0 8px 22px rgb(16 34 49 / 34%), inset 0 1px 2px rgb(255 255 255 / 48%);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.employee-map-marker:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 12px 28px rgb(16 34 49 / 44%), 0 0 0 5px rgb(229 101 79 / 20%);
}

.employee-marker-code {
  font-weight: 500;
  letter-spacing: 0.04em;
}

.employee-marker-count {
  opacity: 0.88;
}

.map-key {
  position: absolute;
  bottom: 16px;
  left: 18px;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--graph-border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--surface-ink);
  font-size: var(--font-size-small);
}

.map-key-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #e5654f;
}

.state-detail {
  margin-top: 8px;
  color: var(--graph-muted);
  text-align: center;
}

/* --- Dialogs -------------------------------------------------------------- */
#skyward-app dialog {
  width: min(720px, calc(100% - 32px));
  border: 1px solid var(--graph-border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--surface-ink);
  box-shadow: 0 24px 80px rgb(0 0 0 / 58%);
}

#skyward-app dialog::backdrop {
  background: rgb(0 0 0 / 62%);
}

.editor-form {
  display: grid;
  gap: 16px;
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.editor-head h2 {
  font-size: 18px;
}

.editor-grid,
.scenario-grid,
.comparison-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.scenario-save {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
}

.comparison-group {
  padding-top: 10px;
  border-top: 1px solid var(--graph-border);
}

.comparison-group h3 {
  margin-bottom: 6px;
  font-size: 14px;
}

.comparison-group p {
  color: var(--graph-muted);
}

.share-status-error {
  color: #e2603c;
}

.share-status-ok {
  color: #4faa72;
}

/* --- Tooltip -------------------------------------------------------------- */
.tooltip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2000;
  width: max-content;
  max-width: 20rem;
  padding: 5px 9px;
  border-radius: var(--radius);
  background: #0d1b26;
  color: #fff;
  font-size: var(--font-size-small);
  pointer-events: none;
}

/* --- Sign-in page --------------------------------------------------------- */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: radial-gradient(circle at 50% 0%, #1d3550 0, #101922 60%);
}

.login-shell {
  width: min(420px, calc(100% - 32px));
  padding: 24px 0;
}

.login-card {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 36px 28px;
  text-align: center;
}

.login-logo {
  width: 240px;
  height: auto;
}

.login-card h1 {
  font-size: 22px;
  font-weight: 600;
}

.login-lead {
  color: #a8c0d2;
}

.login-button {
  min-height: 44px;
  margin-top: 6px;
}

.login-error {
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgb(226 96 60 / 16%);
  color: #ffb4a0;
  font-size: var(--font-size-small);
}

.login-error[hidden] {
  display: none;
}

.login-note {
  color: #7e97ab;
  font-size: var(--font-size-small);
}

/* --- Narrow screens ------------------------------------------------------- */
@media (max-width: 760px) {
  .visual-workspace {
    display: block;
  }

  .person-sidebar {
    position: static;
    width: 100%;
    margin-top: 12px;
  }

  .editor-grid,
  .scenario-grid,
  .comparison-grid,
  .scenario-save {
    grid-template-columns: 1fr;
  }

  .viz-controls {
    justify-content: flex-start;
  }

  .feedback-footer {
    position: static;
    margin-top: 12px;
  }
}
