/* FLAGMAN 1.0 - mobile-first, edge-to-edge, sun-readable */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --orange: #ff8c2d;
  --orange-dark: #e07320;
  --yellow: #ffd400;
  --bg: #f5f5f4;
  --card: #ffffff;
  --ink: #1a1a1a;
  --muted: #555555;
  --line: #d4d4d4;
  --good: #2a8c3a;
  --warn: #c84300;
  --tap: 48px;
}
html, body {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
#app {
  width: 100vw;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.topbar {
  background: var(--orange);
  color: #fff;
  padding: env(safe-area-inset-top) 16px 12px 16px;
  padding-top: max(env(safe-area-inset-top), 12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 2px;
}
.env-tag {
  background: rgba(0,0,0,0.18);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
main#view {
  flex: 1;
  width: 100%;
  padding: 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
.card {
  background: var(--card);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  border-left: 6px solid var(--orange);
}
.card h1 {
  font-size: 20px;
  margin-bottom: 10px;
  color: var(--ink);
}
.card h2 {
  font-size: 17px;
  margin-bottom: 8px;
  color: var(--ink);
}
.card p {
  color: var(--muted);
  line-height: 1.5;
  font-size: 15px;
}
.card.warn {
  border-left-color: var(--yellow);
  background: #fffbe6;
}
.row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border: none;
  border-radius: 10px;
  background: var(--orange);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:active { background: var(--orange-dark); }
.btn.ghost {
  background: transparent;
  color: var(--orange);
  border: 2px solid var(--orange);
}
.crew-hello {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}
.crew-role {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 12px;
}
.tabs {
  display: flex;
  gap: 4px;
  background: #e8e8e6;
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 16px;
}
.tab {
  flex: 1;
  min-height: 44px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 9px;
  cursor: pointer;
}
.tab.active {
  background: var(--card);
  color: var(--orange);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.list-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: none; }
.list-item .when { font-size: 12px; color: var(--muted); }
.list-item .who { font-weight: 600; }
.empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.chat-msg {
  background: #f0f0ee;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.chat-msg .from { font-weight: 700; font-size: 13px; color: var(--orange-dark); }
.chat-msg .body { font-size: 15px; margin-top: 2px; }
.chat-msg .ts { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* Photo upload UI */
.fm-input {
  width: 100%;
  min-height: 72px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  margin-bottom: 14px;
  background: #fafafa;
  resize: vertical;
}
.fm-input:focus { outline: none; border-color: var(--orange); background: #fff; }
.fm-photos { margin-top: 8px; }
.fm-h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
}
.fm-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.fm-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #eee;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid var(--line);
}
.fm-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.fm-x {
  position: absolute;
  top: 4px; right: 4px;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.fm-badge {
  position: absolute;
  bottom: 4px; left: 4px;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
}
.fm-badge.ok { background: var(--good); }
.fm-badge.up { background: var(--orange); }
.fm-badge.err { background: var(--warn); }
.fm-empty {
  grid-column: 1 / -1;
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  background: #fafafa;
  border-radius: 10px;
  border: 2px dashed var(--line);
}
.fm-add-photo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  text-align: center;
  cursor: pointer;
}
.fm-add-photo.disabled { opacity: 0.5; pointer-events: none; }
.fm-status {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
}
.fm-status.info { background: #eef5ff; color: #1a4d8a; border-left: 4px solid #1a4d8a; }
.fm-status.ok   { background: #ecf7ee; color: var(--good); border-left: 4px solid var(--good); }
.fm-status.err  { background: #ffece4; color: var(--warn); border-left: 4px solid var(--warn); }
.fm-submit { width: 100%; }
.fm-submit:disabled { opacity: 0.6; cursor: not-allowed; }
@media (max-width: 400px) {
  .fm-thumbs { grid-template-columns: repeat(3, 1fr); }
}

/* Chat pane (Task 4) */
.fm-chat-pane { display: flex; flex-direction: column; gap: 10px; }
.fm-chat-card { padding-bottom: 8px; }
.fm-chat-feed {
  max-height: 60vh;
  min-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 2px;
}
.fm-chat-msg {
  background: #f0f0ee;
  border-radius: 12px;
  padding: 8px 12px;
  max-width: 85%;
  align-self: flex-start;
  border-left: 3px solid var(--orange);
}
.fm-chat-msg.mine {
  align-self: flex-end;
  background: #fff3e6;
  border-left: none;
  border-right: 3px solid var(--orange);
}
.fm-chat-msg.pending { opacity: 0.6; }
.fm-chat-msg.failed { background: #ffece4; border-color: var(--warn); }
.fm-chat-head {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 11px; margin-bottom: 2px;
}
.fm-chat-from { font-weight: 700; color: var(--orange-dark); }
.fm-chat-ts { color: var(--muted); }
.fm-chat-body { font-size: 15px; line-height: 1.35; word-wrap: break-word; }
.fm-chat-photos {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px;
}
.fm-chat-photo {
  width: 200px; max-width: 100%;
  border-radius: 8px;
  cursor: pointer;
  display: block;
  background: #ddd;
}
.fm-chat-retry {
  margin-top: 6px;
  padding: 4px 10px;
  font-size: 12px;
  background: var(--warn); color: #fff;
  border: none; border-radius: 6px;
  cursor: pointer;
}
.fm-chat-compose {
  background: #fff;
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  border-left: 6px solid var(--yellow);
  position: sticky;
  bottom: 8px;
}
.fm-chat-pend {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.fm-chat-pthumb {
  position: relative;
  width: 56px; height: 56px;
  border-radius: 8px; overflow: hidden;
  border: 2px solid var(--line);
}
.fm-chat-pthumb img { width: 100%; height: 100%; object-fit: cover; }
.fm-chat-row {
  display: flex; gap: 8px; align-items: center;
}
.fm-chat-add {
  min-width: var(--tap); height: var(--tap);
  border-radius: 50%;
  background: var(--orange); color: #fff;
  font-size: 24px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.fm-chat-add.disabled { opacity: 0.5; pointer-events: none; }
.fm-chat-input {
  flex: 1; min-width: 0;
  min-height: var(--tap);
  padding: 0 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  font-size: 16px; font-family: inherit;
  background: #fafafa;
}
.fm-chat-input:focus { outline: none; border-color: var(--orange); background: #fff; }
.fm-chat-send {
  min-height: var(--tap); padding: 0 16px;
  border: none; border-radius: 12px;
  background: var(--orange); color: #fff;
  font-weight: 700; font-size: 15px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.fm-chat-send:disabled { opacity: 0.6; cursor: not-allowed; }
.fm-chat-fs {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.fm-chat-fs img { max-width: 100%; max-height: 100%; border-radius: 8px; }
