:root {
  --bg: #0d0e10;
  --bg-elevated: #15171a;
  --fg: #e7e9ea;
  --fg-muted: #888e96;
  --accent: #4aa3ff;
  --accent-soft: rgba(74, 163, 255, 0.15);
  --danger: #ff5c5c;
  --success: #4ade80;
  --warning: #facc15;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 10px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

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

button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}
button:hover { opacity: 0.9; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
}
button.danger { background: var(--danger); }
button.success { background: var(--success); color: #000; }

input, select, textarea {
  background: var(--bg-elevated);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--fg-muted);
}

.card {
  max-width: 460px;
  margin: 60px auto;
  padding: 36px 32px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card h1 { margin: 0 0 8px; font-size: 1.8rem; }
.card .subtitle { color: var(--fg-muted); margin: 0 0 24px; }
.card form { display: flex; flex-direction: column; gap: 4px; }
.card form input { margin-bottom: 14px; }
.card form button { margin-top: 8px; }
.card .links { margin-top: 18px; text-align: center; font-size: 0.9rem; }
.card .links a { margin: 0 8px; }

.error {
  color: var(--danger);
  background: rgba(255, 92, 92, 0.1);
  border: 1px solid rgba(255, 92, 92, 0.3);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-top: 14px;
  font-size: 0.9rem;
}
.success {
  color: var(--success);
  background: rgba(74, 222, 128, 0.1);
  border: 1px solid rgba(74, 222, 128, 0.3);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-top: 14px;
  font-size: 0.9rem;
}

.topnav {
  display: flex;
  align-items: center;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topnav .brand {
  font-weight: 600;
  font-size: 1.05rem;
  padding-right: 12px;
  border-right: 1px solid var(--border);
}
.topnav a {
  color: var(--fg);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.93rem;
}
.topnav a:hover { background: rgba(255, 255, 255, 0.06); }
.topnav a.active { color: var(--accent); background: var(--accent-soft); }
.nav-tabs { display: flex; gap: 4px; }
.nav-user { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.nav-user .user-info { margin-right: 6px; }
@media (max-width: 640px) {
  .topnav { flex-wrap: wrap; padding: 8px 14px; gap: 6px; }
  .topnav .brand { border-right: 0; padding-right: 0; }
  .nav-user { margin-left: 0; }
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}
.container h1 { margin-top: 0; }

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 24px;
}
.panel h2 { margin-top: 0; font-size: 1.2rem; display: flex; align-items: center; gap: 10px; }
.panel form { display: flex; flex-direction: column; }
.panel form input,
.panel form select,
.panel form textarea { margin-bottom: 16px; }
.panel form button[type="submit"] { margin-top: 12px; align-self: flex-start; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.badge.admin { background: rgba(250, 204, 21, 0.15); color: var(--warning); }

.users-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 0.93rem;
}
.users-table th, .users-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.users-table th { color: var(--fg-muted); font-weight: 500; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; }
.users-table tr:hover { background: rgba(255, 255, 255, 0.02); }
.users-table .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.users-table .actions button { padding: 6px 12px; font-size: 0.85rem; }

.user-info { color: var(--fg-muted); font-size: 0.9rem; margin-right: 8px; }
.updated { font-size: 0.78rem; font-weight: 400; color: var(--fg-muted); margin-left: auto; }

.tides-panel h2 { display: flex; align-items: center; }
.tide-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}
.tide-current, .tide-next, .tide-following {
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius);
}
.tide-label { color: var(--fg-muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.tide-value { font-size: 1.8rem; font-weight: 600; }
.tide-trend { margin-top: 4px; font-size: 0.95rem; color: var(--fg-muted); }
.tide-trend.rising { color: var(--success); }
.tide-trend.falling { color: var(--accent); }
.tide-following ul { list-style: none; padding: 0; margin: 0; font-size: 0.9rem; }
.tide-following li { padding: 3px 0; }
.tide-following li.muted { color: var(--fg-muted); }

.chart-wrap {
  position: relative;
  height: 280px;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.tab {
  background: transparent;
  color: var(--fg-muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .badge { font-size: 0.72rem; padding: 1px 8px; }

.ships-toolbar { margin-bottom: 12px; }
.ships-toolbar input { max-width: 360px; }

.berth-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.berth-filter .filter-label { color: var(--fg-muted); font-size: 0.85rem; font-weight: 500; }
.berth-chips { display: flex; flex-wrap: wrap; gap: 5px; flex: 1; }
.chip {
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  font-family: ui-monospace, monospace;
}
.chip:hover { color: var(--fg); border-color: var(--accent); }
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.chip.missing { opacity: 0.5; font-style: italic; }
.chip.missing.active { opacity: 0.85; }
button.small { padding: 4px 10px; font-size: 0.8rem; }

.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.ships-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-width: 700px;
}
.ships-table th, .ships-table td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.ships-table th { color: var(--fg-muted); font-weight: 500; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; background: var(--bg); position: sticky; top: 0; }
.ships-table tr:hover { background: rgba(255, 255, 255, 0.02); }
.ships-table .muted { color: var(--fg-muted); font-size: 0.82rem; }
.ships-table .center { text-align: center; padding: 24px; }
.ships-table .bordee { color: var(--warning); }

.status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
}
.status-ACC, .status-APP { background: rgba(74,222,128,0.12); color: var(--success); }
.status-DIG { background: rgba(74,163,255,0.15); color: var(--accent); }
.status-PVA, .status-PVD { background: rgba(250,204,21,0.12); color: var(--warning); }

.ship-row { cursor: pointer; }
.ship-row.no-imo { cursor: default; opacity: 0.65; }
.ship-row:not(.no-imo):hover { background: var(--accent-soft) !important; }

.back-link { display: inline-block; margin-bottom: 14px; color: var(--fg-muted); font-size: 0.9rem; }
.back-link:hover { color: var(--accent); }

.ship-header {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  margin-bottom: 24px;
  align-items: start;
}
@media (max-width: 700px) { .ship-header { grid-template-columns: 1fr; } }
.ship-header-photo {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  aspect-ratio: 4/3;
  display: flex; align-items: center; justify-content: center;
}
.ship-header-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-placeholder { color: var(--fg-muted); }
.ship-header-info h1 { margin: 0 0 4px; font-size: 1.9rem; }
.specs { list-style: none; padding: 0; margin: 16px 0 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.specs li { padding: 8px 12px; background: var(--bg-elevated); border-radius: 6px; font-size: 0.9rem; }

.movement-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 10px;
}
.movement-card ul { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 6px 18px; font-size: 0.9rem; }

.lashing-display { background: var(--bg); padding: 16px; border-radius: var(--radius); border-left: 3px solid var(--accent); }
.lashing-technique { font-size: 1.1rem; margin-bottom: 8px; }
.lashing-notes { white-space: pre-wrap; font-family: inherit; margin: 10px 0; padding: 10px; background: var(--bg-elevated); border-radius: 6px; font-size: 0.92rem; }
.small { font-size: 0.82rem; }

.form-actions { display: flex; gap: 8px; margin-top: 10px; }

.photos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-top: 12px; }
.photo { margin: 0; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.photo img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.photo figcaption { padding: 10px; display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; }
.photo img { cursor: zoom-in; }

/* === Lightbox === */
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, 0.92);
  flex-direction: column;
  align-items: center; justify-content: center;
}
/* IMPORTANT : on n'applique display:flex que si NON masqué — sinon l'attribut HTML
   [hidden] est ignoré par le CSS et le lightbox reste visible en permanence (bug critique). */
.lightbox:not([hidden]) { display: flex; }

.lightbox.lb-loading::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 48px; height: 48px;
  margin: -24px 0 0 -24px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: #4aa3ff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  z-index: 3;
}
.lightbox.lb-loading #lb-img { opacity: 0.3; }
.lb-stage {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
#lb-img {
  max-width: 92vw; max-height: 88vh;
  user-select: none;
  transition: transform 0.05s linear;
  will-change: transform;
}
.lb-btn {
  position: absolute; z-index: 2;
  background: rgba(15, 17, 20, 0.7);
  color: #fff; border: 1px solid var(--border);
  width: 44px; height: 44px;
  border-radius: 999px;
  font-size: 1.2rem; line-height: 1;
  cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.lb-btn:hover { background: rgba(74, 163, 255, 0.4); }
.lb-close { top: 16px; right: 16px; }
.lb-prev { left: 16px; top: 50%; transform: translateY(-50%); font-size: 1.8rem; }
.lb-next { right: 16px; top: 50%; transform: translateY(-50%); font-size: 1.8rem; }
.lb-caption {
  position: absolute; left: 50%; bottom: 16px;
  transform: translateX(-50%);
  background: rgba(15, 17, 20, 0.85);
  color: var(--fg);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.88rem;
  max-width: 90vw;
  text-align: center;
  z-index: 2;
}
.lb-caption a { color: var(--accent); }
.lb-counter {
  position: absolute; top: 18px; left: 50%;
  transform: translateX(-50%);
  color: var(--fg-muted);
  font-size: 0.85rem;
  background: rgba(15, 17, 20, 0.6);
  padding: 4px 12px;
  border-radius: 999px;
  z-index: 2;
}

/* === Tickets === */
.tickets-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.ticket-row { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); transition: border-color 0.12s; }
.ticket-row:hover { border-color: var(--accent); }
.ticket-link { display: block; padding: 12px 16px; text-decoration: none; color: var(--fg); }
.ticket-link:hover { text-decoration: none; }
.ticket-row-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.ticket-subject { font-weight: 600; font-size: 1rem; }
.status-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.status-open { background: rgba(74,222,128,0.15); color: var(--success); }
.status-closed { background: rgba(136,142,150,0.15); color: var(--fg-muted); }

.ticket-header { margin-bottom: 24px; }
.ticket-header h1 { margin: 0 0 6px; }
.ticket-actions { margin-top: 12px; display: flex; gap: 8px; }

.messages { list-style: none; padding: 0; margin: 0 0 24px; display: flex; flex-direction: column; gap: 12px; }
.message { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.message header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.message .msg-text { white-space: pre-wrap; font-size: 0.94rem; }
.message.msg-admin { border-left: 3px solid var(--warning); }
.message.msg-creator { border-left: 3px solid var(--accent); }

.reply-panel textarea { resize: vertical; }

/* === Logs admin === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-card.stat-wide { grid-column: span 2; text-align: left; }
.stat-card.stat-warn { border-color: var(--danger); background: rgba(255,92,92,0.08); }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--accent); }
.stat-warn .stat-value { color: var(--danger); }
.stat-label { color: var(--fg-muted); font-size: 0.85rem; margin-top: 4px; }
.stat-card.stat-wide ul { list-style: none; padding: 0; margin: 8px 0 0; font-size: 0.9rem; }
.stat-card.stat-wide li { padding: 3px 0; }
.stat-card.stat-wide code { background: var(--bg-elevated); padding: 1px 6px; border-radius: 4px; font-size: 0.85rem; }

.status.status-200 { background: rgba(74,222,128,0.12); color: var(--success); }
.status.status-300 { background: rgba(250,204,21,0.12); color: var(--warning); }
.status.status-400 { background: rgba(255,92,92,0.12); color: var(--danger); }
.status.status-500 { background: rgba(255,92,92,0.2); color: var(--danger); font-weight: 700; }

.comment-form textarea { resize: vertical; }
.comments { list-style: none; padding: 0; margin: 18px 0 0; display: flex; flex-direction: column; gap: 12px; }
.comment { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.comment header { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; }
.comment-text { white-space: pre-wrap; font-size: 0.93rem; }
.comment-actions { margin-top: 8px; display: flex; gap: 6px; }

.source-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  margin-right: 4px;
  background: var(--bg-elevated);
}
.source-vesselfinder { background: rgba(74,163,255,0.15); color: var(--accent); }
.source-shipspotting { background: rgba(74,222,128,0.15); color: var(--success); }

.checkbox-row.inline { margin: 0; }

.ships-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 16px; }
.ships-toolbar input[type="search"] { max-width: 320px; flex: 1; }
.ships-toolbar select { max-width: 200px; }

.ships-catalog {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.ship-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: var(--fg);
  transition: transform 0.12s, border-color 0.12s;
}
.ship-card:hover { transform: translateY(-2px); border-color: var(--accent); text-decoration: none; }
.ship-card-photo { aspect-ratio: 4/3; background: var(--bg); display: flex; align-items: center; justify-content: center; position: relative; }
.ship-card-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ship-card-photo .photo-placeholder { font-size: 1.8rem; color: var(--fg-muted); }
.ship-card-photo .live-pill {
  position: absolute; top: 8px; right: 8px;
  background: var(--success); color: #000;
  font-size: 0.7rem; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
}
.ship-card-photo .live-pill.live-pending { background: var(--warning); color: #000; }
.ship-card-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 5px; flex: 1; }
.ship-card-name { font-weight: 600; font-size: 1.02rem; }
.ship-card-badges { display: flex; gap: 5px; flex-wrap: wrap; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 14px;
  color: var(--fg);
  font-size: 0.9rem;
  cursor: pointer;
}
.checkbox-row input[type="checkbox"] { width: auto; margin: 0; cursor: pointer; }

.ext-link { font-size: 0.78rem; font-weight: 400; margin-left: auto; }
.map-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg);
}
.map-wrap iframe { display: block; width: 100%; }

.icon-btn {
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 0.95rem;
  cursor: pointer;
  margin-left: 6px;
  transition: transform 0.2s, color 0.15s;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn.spin { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.placeholder {
  max-width: 600px;
  margin: 80px auto;
  padding: 40px 30px;
  text-align: center;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.placeholder h1 {
  font-size: 2.4rem;
  margin: 0 0 8px;
}
.placeholder .subtitle {
  color: var(--fg-muted);
  margin: 0 0 30px;
  font-size: 1.05rem;
}
.placeholder .status {
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-block;
  padding: 8px 16px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  font-weight: 500;
}
.placeholder .features {
  text-align: left;
  list-style: none;
  padding: 0;
  margin: 20px auto;
  max-width: 400px;
}
.placeholder .features li {
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.placeholder .hint {
  color: var(--fg-muted);
  font-size: 0.9rem;
  margin-top: 24px;
}
