:root {
  color-scheme: dark;
  --bg: #071724;
  --surface: #0f2838;
  --surface-2: #173b50;
  --line: #31566b;
  --text: #f2f7fa;
  --muted: #a9bec9;
  --accent: #55b8c8;
  --accent-ink: #041b24;
  --ok: #65c7c1;
  --danger: #ef796f;
  --shadow: 0 18px 50px rgb(0 0 0 / 24%);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: clip;
}

.layout,
.content,
.view,
.card,
.grid,
.field,
.input-now,
.section-title,
.section-title > div,
.list-row,
.list-main,
.actions,
.brand,
.header-actions,
.dialog-body,
.metric > span {
  min-width: 0;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 85% 0%, #184a66 0, transparent 32rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  max-width: 100%;
  cursor: pointer;
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: space-between;
  padding: 12px clamp(14px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
  background: rgb(7 23 36 / 92%);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: block;
  width: 42px;
  height: 42px;
  padding: 2px;
  border-radius: 50%;
  background: #17485f;
  object-fit: contain;
}

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

h1 {
  margin-bottom: 2px;
  font-size: clamp(17px, 3vw, 22px);
}

.subtitle,
.translation {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.status {
  display: flex;
  gap: 8px;
  align-items: center;
  white-space: nowrap;
  font-size: 0.82rem;
}

.header-actions {
  display: flex;
  gap: 18px;
  align-items: center;
}

#logout-button {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
}

#logout-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Hide journal pages while the PIN dialog is the only allowed surface. */
body.pin-locked .layout {
  visibility: hidden;
}

.header-logo {
  display: block;
  width: clamp(110px, 12vw, 150px);
  height: auto;
}

.app-version {
  position: absolute;
  top: calc(2px + env(safe-area-inset-top, 0px));
  right: calc(6px + env(safe-area-inset-right, 0px));
  color: var(--muted);
  font-size: 0.62rem;
  line-height: 1;
  pointer-events: none;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
}

.dot.online {
  background: var(--ok);
  box-shadow: 0 0 14px var(--ok);
}

.layout {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  min-height: calc(100vh - 68px);
}

.sidebar {
  position: sticky;
  top: 68px;
  align-self: start;
  display: grid;
  gap: 7px;
  height: calc(100vh - 68px);
  padding: 22px 14px;
  border-right: 1px solid var(--line);
}

.nav-button {
  display: grid;
  gap: 2px;
  padding: 11px 13px;
  border: 0;
  border-radius: 11px;
  color: var(--text);
  background: transparent;
  text-align: left;
  text-decoration: none;
}

.nav-button:hover,
.nav-button.active {
  background: var(--surface-2);
}

.nav-button.active {
  box-shadow: inset 3px 0 var(--accent);
}

.nav-footer {
  align-self: end;
  display: grid;
  gap: 8px;
}

.content {
  width: min(1200px, 100%);
  padding: clamp(18px, 4vw, 42px);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card {
  padding: clamp(16px, 3vw, 24px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(145deg, rgb(23 59 80 / 92%), rgb(15 40 56 / 96%));
  box-shadow: var(--shadow);
}

.card h2,
.card h3 {
  margin-bottom: 4px;
}

.card-header,
.actions,
.list-row,
.metric {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}

.metric {
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.metric:last-child {
  border-bottom: 0;
}

.metric strong {
  color: var(--accent);
  font-size: 1.15rem;
}

.motor-strip {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  padding: 10px 16px;
}

.motor-strip h3 {
  margin: 0;
}

.timer {
  margin: 0 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.danger-value {
  color: var(--danger);
}

.primary,
.secondary,
.danger,
.now {
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 750;
}

.primary,
.now {
  color: var(--accent-ink);
  background: var(--accent);
}

.secondary {
  color: var(--text);
  border-color: var(--line);
  background: var(--surface-2);
}

.danger {
  color: white;
  background: #a4332b;
}

.wide {
  width: 100%;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.field[hidden] {
  display: none;
}

label {
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  color: var(--text);
  background: #081d2b;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(85 184 200 / 18%);
}

.input-now {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
}

.section-title {
  display: flex;
  align-items: end;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 18px;
}

.history-controls select {
  width: auto;
}

.list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.list-row {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgb(7 23 36 / 55%);
}

.list-main {
  min-width: 0;
}

.list-main strong,
.list-main span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-data {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.history-field {
  display: grid;
  grid-template-columns: minmax(140px, 0.8fr) minmax(0, 1.2fr);
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.history-label {
  font-weight: 700;
}

.history-label .translation {
  margin-top: 2px;
  white-space: normal;
}

.history-value {
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.history-empty {
  margin: 12px 0 0;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 4px 9px;
  border-radius: 999px;
  color: var(--muted);
  background: #081d2b;
  font-size: 0.78rem;
}

.badge.pending {
  color: var(--accent);
}

.harbor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(235px, 1fr));
  gap: 12px;
}

.harbor-button {
  min-height: 110px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: var(--surface);
  text-align: left;
}

.harbor-button.complete {
  border-color: var(--ok);
}

.harbor-button strong,
.harbor-button span {
  display: block;
}

.harbor-button span {
  margin-top: 5px;
  color: var(--muted);
}

.dialog {
  width: min(680px, calc(100% - 24px));
  max-height: calc(100vh - 30px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 30px 80px rgb(0 0 0 / 55%);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 68%);
  backdrop-filter: blur(5px);
}

.dialog-body {
  max-height: calc(100vh - 30px);
  padding: 22px;
  overflow-y: auto;
}

.dialog-header {
  display: flex;
  gap: 12px;
  align-items: start;
  justify-content: space-between;
  margin-bottom: 18px;
}

.icon-button {
  width: 38px;
  min-width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  background: transparent;
}

.notice {
  padding: 12px;
  border-left: 3px solid var(--accent);
  border-radius: 7px;
  color: var(--muted);
  background: #081d2b;
  font-size: 0.87rem;
}

.toast-stack {
  position: fixed;
  z-index: 50;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100% - 32px));
}

.toast {
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #12394e;
  box-shadow: var(--shadow);
}

.form-status {
  min-height: 1.4em;
  margin: 10px 0 0;
  color: #8dd9cf;
  font-weight: 700;
}

.form-status.error {
  color: var(--danger);
}

.permanent-delete {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--danger);
}

.map-canvas {
  width: 100%;
  aspect-ratio: 1.42;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    linear-gradient(90deg, transparent 49.5%, rgb(255 255 255 / 8%) 50%, transparent 50.5%),
    linear-gradient(transparent 49.5%, rgb(255 255 255 / 8%) 50%, transparent 50.5%),
    #e7e2d2;
  touch-action: none;
}

.small {
  font-size: 0.8rem;
}

.hidden {
  display: none !important;
}

@media (max-width: 800px) {
  .layout {
    display: block;
  }

  .sidebar {
    position: fixed;
    z-index: 30;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    width: auto;
    max-width: 100%;
    height: auto;
    padding:
      7px
      calc(7px + env(safe-area-inset-right, 0px))
      calc(7px + env(safe-area-inset-bottom, 0px))
      calc(7px + env(safe-area-inset-left, 0px));
    overflow-x: auto;
    border-top: 1px solid var(--line);
    border-right: 0;
    background: rgb(7 23 36 / 96%);
  }

  .nav-button,
  .nav-footer {
    flex: 0 0 auto;
  }

  .nav-button {
    min-width: 92px;
    padding: 8px;
    text-align: center;
  }

  .nav-footer {
    display: flex;
  }

  .content {
    padding-right: calc(clamp(18px, 4vw, 42px) + env(safe-area-inset-right, 0px));
    padding-bottom: calc(180px + env(safe-area-inset-bottom, 0px));
    padding-left: calc(clamp(18px, 4vw, 42px) + env(safe-area-inset-left, 0px));
  }

  .grid.two,
  .grid.three {
    grid-template-columns: 1fr;
  }

  .motor-strip {
    flex-wrap: wrap;
  }

  .app-header,
  .header-actions,
  .section-title,
  .list-row,
  .actions,
  .metric {
    flex-wrap: wrap;
    max-width: 100%;
  }

  .app-header {
    align-items: center;
    padding:
      calc(10px + env(safe-area-inset-top, 0px))
      calc(12px + env(safe-area-inset-right, 0px))
      10px
      calc(12px + env(safe-area-inset-left, 0px));
  }

  .brand,
  .section-title > div,
  .list-main {
    flex: 1 1 12rem;
  }

  .header-actions {
    flex: 1 1 12rem;
    gap: 10px;
    justify-content: flex-end;
  }

  .section-title > button,
  .list-row > .actions,
  .actions > button {
    flex: 1 1 9rem;
    min-width: 0;
    max-width: 100%;
    white-space: normal;
  }

  .history-controls select {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }

  .header-logo {
    width: 90px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .status span:last-child {
    display: none;
  }

  .history-field {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

/* The overview is shorter than the menu, so the sidebar has to scroll itself. */
@media (min-width: 801px) {
  body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }

  .layout {
    flex: 1;
    min-height: 0;
    grid-template-rows: minmax(0, 1fr);
  }

  .sidebar {
    position: static;
    align-self: stretch;
    height: auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .content {
    min-height: 0;
    overflow-y: auto;
  }
}
