/* Crew web app. Shares the brand tokens used by owner-portal/styles.css and
   the marketing site: ink navy, slate cards, signal green. */
* { box-sizing: border-box; }

:root {
  --bg: #010d18;
  --surface: #16222d;
  --surface-raised: #23313e;
  --surface-muted: #1a2733;
  --surface-pressed: #2c3c4b;
  --line: rgba(238, 229, 229, 0.14);
  --line-strong: rgba(238, 229, 229, 0.28);
  --text-soft: rgba(238, 229, 229, 0.68);
  --text-tertiary: rgba(238, 229, 229, 0.5);
  --text-main: #eee5e5;
  --accent: #0df26c;
  --accent-cool: #0bc75b;
  --success: #0df26c;
  --warning: #ffb443;
  --danger: #ff6b5e;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --header-h: 62px;
  --nav-w: 208px;
}

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text-main);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body.sheet-open { overflow: hidden; }

h1, h2, h3, h4, .app-title {
  font-family: "Syne", -apple-system, BlinkMacSystemFont, sans-serif;
}

h2 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
h3 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }
h4 { font-size: 15px; margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-cool); }

.hidden { display: none !important; }
.muted { color: var(--text-soft); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 13.5px; }
.error:empty { display: none; }

/* ---------- boot / blocked ---------- */

.app-boot, .app-blocked {
  min-height: 100vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 32px;
  text-align: center;
}

.blocked-logo { width: 120px; opacity: 0.9; }

.spinner, .spinner-sm {
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner { width: 26px; height: 26px; }
.spinner-sm { width: 14px; height: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 4px;
  color: var(--text-soft);
}

/* ---------- frame ---------- */

.app-frame { min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: rgba(1, 13, 24, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.app-logo { height: 30px; width: auto; }
.app-header-copy { min-width: 0; flex: 1; }
.app-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.app-header-copy .small {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-header-actions { display: flex; gap: 8px; }

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 34px;
  height: 34px;
  padding: 0 6px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}
.nav-toggle span { display: block; height: 2px; background: var(--text-main); border-radius: 2px; }

.app-body { flex: 1; display: flex; min-height: 0; }

.app-nav {
  width: var(--nav-w);
  flex: 0 0 var(--nav-w);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 10px 20px;
  border-right: 1px solid var(--line);
  position: sticky;
  top: var(--header-h);
  align-self: flex-start;
  max-height: calc(100vh - var(--header-h));
  overflow-y: auto;
}

.nav-spacer { flex: 1; min-height: 14px; }

.nav-item {
  font-family: "Syne", -apple-system, BlinkMacSystemFont, sans-serif;
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-soft);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.nav-item:hover { background: var(--surface-muted); color: var(--text-main); }

/* Unread count for whatever that section is about. */
.nav-badge {
  flex: 0 0 auto;
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: #04231a;
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.nav-item.active .nav-badge { background: var(--accent); color: #04231a; }

/* Something is waiting behind the closed nav. */
.nav-toggle { position: relative; }
.nav-toggle.has-unread::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  border: 1px solid var(--bg);
}
.nav-item.active { background: var(--surface-raised); color: var(--accent); }
.nav-signout { color: var(--danger); }
.nav-link { color: var(--text-soft); }

.nav-scrim { display: none; }

.app-main {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 18px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  /* A single panel stretched edge to edge puts a row's label and its value an
     inch apart on a wide monitor, so cap and centre it. Views with several
     panels tile instead and get the full width. */
  max-width: 1120px;
  margin-inline: auto;
}

/* Set by the shell when a view renders more than one panel. auto-fit collapses
   the empty tracks, so two panels become two wide columns rather than three
   narrow ones. */
.app-main.tiled {
  max-width: 1680px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr));
  align-items: start;
}

/* The lead panel carries the summary/filters for the view, so it spans. */
.app-main.tiled > .panel:first-child,
.app-main.tiled > :not(.panel) {
  grid-column: 1 / -1;
}

/* ---------- panels & rows ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.heading-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.empty {
  padding: 18px 2px;
  color: var(--text-tertiary);
  font-size: 14px;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 2px;
  border-top: 1px solid var(--line);
}
.list-row:first-of-type { border-top: 0; }
.list-row.clickable { cursor: pointer; }
.list-row.clickable:hover { background: var(--surface-muted); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-weight: 600; }
.row-sub { font-size: 13px; color: var(--text-soft); }
.row-value {
  font-weight: 600;
  white-space: nowrap;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.row-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.state-overdue { color: var(--danger); font-weight: 700; }
.state-due { color: var(--warning); font-weight: 700; }
.state-ok { color: var(--success); }
.state-unknown { color: var(--text-tertiary); }

.group-head {
  font-family: "Syne", -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 700;
  font-size: 13px;
  color: var(--text-soft);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 18px 2px 6px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.stat-card {
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  margin: 3px 0;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  font-family: "Syne", -apple-system, BlinkMacSystemFont, sans-serif;
  border: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--text-soft);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.chip.active { background: var(--accent); color: #04231a; border-color: var(--accent); }

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-pressed);
  color: var(--text-soft);
}
.badge.accent { background: rgba(13, 242, 108, 0.16); color: var(--accent); }
.badge.warn { background: rgba(255, 180, 67, 0.18); color: var(--warning); }
.badge.danger { background: rgba(255, 107, 94, 0.18); color: var(--danger); }

/* ---------- controls ---------- */

.pill {
  font-family: "Syne", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 15px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface-raised);
  color: var(--text-main);
  cursor: pointer;
  white-space: nowrap;
}
.pill:hover { background: var(--surface-pressed); }
.pill:disabled { opacity: 0.5; cursor: default; }
.pill.primary { background: var(--accent); border-color: var(--accent); color: #04231a; }
.pill.primary:hover { background: var(--accent-cool); }
.pill.ghost { background: transparent; }
.pill.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.pill.small { font-size: 12px; padding: 5px 11px; }
.pill.full { width: 100%; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field-label { font-size: 13px; color: var(--text-soft); font-weight: 600; }

input, textarea, select {
  font: inherit;
  font-size: 15px;
  color: var(--text-main);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
textarea { resize: vertical; }
select option { background: var(--surface); color: var(--text-main); }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

/* ---------- sheet ---------- */

.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(1, 13, 24, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.sheet-card {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.sheet-actions { margin-top: 14px; display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  z-index: 80;
  background: var(--surface-raised);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  max-width: calc(100vw - 32px);
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ---------- chat ---------- */

.chat-layout { display: grid; grid-template-columns: 220px 1fr; gap: 14px; min-height: 0; }
.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 62vh;
  overflow-y: auto;
  padding-right: 4px;
}
.chat-bubble {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 14px;
  background: var(--surface-raised);
  align-self: flex-start;
  word-break: break-word;
}
.chat-bubble.mine { align-self: flex-end; background: rgba(13, 242, 108, 0.16); }
.chat-meta { font-size: 12px; color: var(--text-tertiary); margin-bottom: 3px; }
.chat-composer { display: flex; gap: 8px; margin-top: 12px; }
.chat-composer input { flex: 1; }

/* ---------- responsive ---------- */

/* On a phone the action buttons crushed the row's title to one word per line.
   Give the text the full width and let the value/badge/actions wrap beneath. */
@media (max-width: 640px) {
  .list-row { flex-wrap: wrap; row-gap: 8px; }
  .row-main { flex: 1 1 100%; }
  .row-value { text-align: left; }
  .row-actions { margin-left: auto; }
  .section-heading { flex-wrap: wrap; }
  .heading-actions { width: 100%; }
}

@media (max-width: 820px) {
  .nav-toggle { display: flex; }
  .app-nav {
    position: fixed;
    top: var(--header-h);
    bottom: 0;
    left: 0;
    z-index: 40;
    background: var(--surface);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    max-height: none;
  }
  .app-frame.nav-open .app-nav { transform: translateX(0); }
  .app-frame.nav-open .nav-scrim {
    display: block;
    position: fixed;
    inset: var(--header-h) 0 0 0;
    z-index: 35;
    background: rgba(1, 13, 24, 0.6);
  }
  .app-main { padding: 14px 12px 40px; }
  .chat-layout { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .app-logo { display: none; }
  .app-header { gap: 10px; padding: 0 12px; }
  #appOrgSwitcher { max-width: 116px; }
}

/* Owner-only organization picker in the header. */
#appOrgSwitcher {
  width: auto;
  max-width: 180px;
  padding: 7px 10px;
  font-size: 12.5px;
  border-radius: 999px;
  background: var(--surface-raised);
}

/* ---------- photos ---------- */

.photo-thumb {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid var(--line);
  cursor: pointer;
  background: var(--surface-muted);
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.photo-preview img {
  max-width: 100%;
  max-height: 200px;
  border-radius: 10px;
  margin-top: 8px;
  display: block;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(1, 13, 24, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; }

input[type="file"] {
  padding: 8px;
  font-size: 12.5px;
}

/* ---------- tracking ---------- */

.track-wrap { padding: 8px 2px 12px; }
.track-chart {
  width: 100%;
  max-width: 420px;
  height: auto;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.unread-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 7px;
  vertical-align: middle;
}

.vessel-hero {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  margin-right: 12px;
}

/* A badge inside the text column is a label, not a bar: hug its own width. */
.row-main .badge {
  align-self: flex-start;
  margin-top: 4px;
}
