:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #6b7785;
  --line: #dce3ea;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --error: #b42318;
  --error-bg: #fdecea;
  --warn: #9a6700;
  --warn-bg: #fff7e0;
  --ok: #1a7f37;
  --radius: 12px;
}

* { box-sizing: border-box; }

/* The HTML `hidden` attribute must always win — otherwise a class with its own `display`
   (e.g. .user-bar { display: flex }) keeps the element visible even when hidden=true is set. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

.site-header {
  text-align: center;
  padding: 2.4rem 1rem 1rem;
}
.site-header h1 { margin: 0; font-size: 1.6rem; }
.subtitle { margin: .3rem 0 0; color: var(--muted); }

/* Signed-in user bar */
.user-bar {
  display: flex; align-items: center; justify-content: center; gap: .75rem;
  margin-top: .6rem; font-size: .9rem; color: var(--muted);
}
.user-bar a { color: var(--accent); text-decoration: none; }
.user-bar a:hover { text-decoration: underline; }

/* Auth cards (login / waiting / blocked) */
.auth-card { max-width: 420px; margin: 1.5rem auto; }
.auth-card h2 { margin-top: 0; }
.auth-field { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: .75rem; }
.auth-field input {
  display: block; width: 100%; margin-top: .25rem; padding: .55rem .7rem;
  border: 1px solid var(--line); border-radius: 8px; font: inherit; font-size: .95rem;
}
.auth-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31,111,235,.15); }
.auth-card .primary { margin-top: .25rem; }
.auth-toggle { text-align: center; margin: .9rem 0 0; font-size: .88rem; }
.auth-toggle a { color: var(--accent); text-decoration: none; }
.auth-error { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: .6rem .8rem; margin-bottom: .9rem; font-size: .9rem; }

/* Admin tables */
.admin-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.admin-table th, .admin-table td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.admin-table th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.admin-btn { padding: .25rem .6rem; font-size: .8rem; margin-right: .35rem; }

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 1rem 1rem 4rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}

/* Dropzones */
.dropzones {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
@media (max-width: 560px) { .dropzones { grid-template-columns: 1fr; } }

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  outline: none;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); background: #f7faff; }
.dropzone.dragover { border-color: var(--accent); background: #eef4ff; }
.dropzone.filled { border-style: solid; border-color: var(--ok); background: #f3fbf5; }

.dz-icon { font-size: 1.5rem; color: var(--muted); }
.dz-label { font-weight: 600; margin-top: .35rem; }
.dz-hint { color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.req { color: var(--error); font-weight: 500; }
.opt { color: var(--muted); font-weight: 500; }
.dz-file { margin-top: .6rem; font-size: .88rem; color: var(--ok); font-weight: 600; word-break: break-all; }

/* Buttons */
button { font: inherit; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary {
  width: 100%;
  padding: .8rem 1rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  border: none;
}
.primary:not(:disabled):hover { background: #1a5fd0; }
.secondary {
  padding: .5rem .9rem;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 600;
}
.secondary:hover { border-color: var(--accent); color: var(--accent); }

/* Spinner */
.spinner { margin-top: 1rem; text-align: center; color: var(--muted); }
.dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); margin-right: .4rem;
  animation: pulse 1s infinite ease-in-out;
}
@keyframes pulse { 0%,100% { opacity: .3; } 50% { opacity: 1; } }

/* Error banner */
.error-banner { border-color: var(--error); background: var(--error-bg); color: var(--error); }
.error-banner #error-message { margin-top: .4rem; color: var(--ink); }

/* Results */
.results-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.results-header h2 { margin: 0; font-size: 1.2rem; }
.summary { margin: .75rem 0 1rem; color: var(--muted); font-weight: 600; }
.summary .ok { color: var(--ok); }
.summary .has-error { color: var(--error); }
.summary .has-warn { color: var(--warn); }

details { border-top: 1px solid var(--line); padding: .75rem 0; }
details > summary { cursor: pointer; font-weight: 600; }
.empty-note { color: var(--muted); margin: .5rem 0 0; }

.issue-list, .flag-list { list-style: none; margin: .6rem 0 0; padding: 0; }
.issue-list li, .flag-list li {
  padding: .5rem .7rem; border-radius: 8px; margin-bottom: .4rem; font-size: .92rem;
}
.issue-list li.error { background: var(--error-bg); }
.issue-list li.warning { background: var(--warn-bg); }
.flag-list li { background: #f1f4f8; }
.issue-list .tag { font-weight: 700; margin-right: .4rem; }
.issue-list li.error .tag { color: var(--error); }
.issue-list li.warning .tag { color: var(--warn); }
.field { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 600; }

.payload {
  background: #0d1117; color: #e6edf3; border-radius: 8px;
  padding: 1rem; overflow-x: auto; font-size: .85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.results-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Selected-charter header: title + remove-from-batch action */
.detail-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.link-danger {
  background: none; border: none; color: var(--muted);
  font-size: .82rem; padding: .15rem .35rem; white-space: nowrap;
}
.link-danger:hover { color: var(--error); text-decoration: underline; }

/* Charter rows (one per charter in the upload card) */
.charter {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.charter .dropzones { margin-bottom: 0; }
.charter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .75rem;
}
.charter-title { font-weight: 600; }
.remove-charter {
  background: none;
  border: none;
  color: var(--muted);
  font-size: .85rem;
  padding: .15rem .35rem;
}
.remove-charter:hover { color: var(--error); }

.add-charter { display: block; margin: 0 0 1.25rem; }

/* Per-charter selector tabs */
.charter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin: .25rem 0 1.1rem;
}
.charter-tab {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .35rem .7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-size: .88rem;
}
.charter-tab:hover { border-color: var(--accent); }
.charter-tab.active { border-color: var(--accent); background: #eef4ff; font-weight: 600; }
.charter-tab .tab-icon { font-weight: 700; }
.charter-tab.ready  .tab-icon { color: var(--ok); }
.charter-tab.review .tab-icon { color: var(--warn); }
.charter-tab.failed .tab-icon { color: var(--error); }

.batch-summary { font-weight: 600; color: var(--muted); margin: .25rem 0 1rem; }
.detail-title { margin: 0 0 .5rem; font-size: 1.05rem; }
.detail-error {
  background: var(--error-bg);
  color: var(--error);
  border-radius: 8px;
  padding: .6rem .8rem;
  font-size: .92rem;
}
.manual-entry { margin-top: .6rem; }

/* Clickable problem rows (jump to the field in the editor) */
.issue-list li.clickable, .flag-list li.clickable { cursor: pointer; }
.issue-list li.clickable:hover, .flag-list li.clickable:hover { outline: 1px solid var(--accent); }
.flag-help { font-size: .8rem; margin: .4rem 0 0; }

/* Editor */
.editor-status { font-size: .82rem; color: var(--muted); margin: .35rem 0 .5rem; min-height: 1.2em; }
.suggest-note-text { color: var(--ok); font-weight: 600; }
.editor-group {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin: .75rem 0;
}
.editor-group > h4 { margin: 0 0 .75rem; font-size: .95rem; }
.fields-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem 1rem; }
@media (max-width: 640px) { .fields-grid { grid-template-columns: 1fr; } }

.field-wrap.wide { grid-column: 1 / -1; }
.field-wrap > label {
  display: block; font-size: .78rem; font-weight: 600;
  color: var(--muted); margin-bottom: .2rem;
}
.field-wrap .req-star { color: var(--error); }
.field-wrap input, .field-wrap select, .field-wrap textarea {
  width: 100%; padding: .45rem .6rem;
  border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: .92rem; background: #fff; color: var(--ink);
}
.field-wrap textarea { min-height: 70px; resize: vertical; }
.field-wrap input:focus, .field-wrap select:focus, .field-wrap textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31,111,235,.15);
}
.field-hint { font-size: .74rem; color: var(--muted); margin-top: .15rem; }

/* Searchable picker (ports / authorities / nationality) */
.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: 100%;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  max-height: 240px; overflow: auto;
  margin: .15rem 0 0; padding: .25rem; list-style: none;
  box-shadow: 0 8px 24px rgba(16,24,40,.12);
}
.combo-list li { padding: .35rem .5rem; border-radius: 6px; cursor: pointer; font-size: .88rem; }
.combo-list li:hover, .combo-list li.active { background: #eef4ff; }

/* Parties / crew / passenger entry cards */
.entry-card { border: 1px solid var(--line); border-radius: 10px; padding: .85rem; margin-bottom: .75rem; }
.entry-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: .6rem; font-weight: 600; font-size: .9rem;
}
.remove-entry { background: none; border: none; color: var(--muted); font-size: .82rem; padding: .15rem .35rem; }
.remove-entry:hover { color: var(--error); }
.add-entry { margin-top: .25rem; }
.no-entries { color: var(--muted); font-size: .88rem; margin: 0 0 .5rem; }

/* Authority suggestion (from the deterministic resolver) */
.auth-suggest {
  grid-column: 1 / -1; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap;
  font-size: .85rem; min-height: 1.2em;
}
.suggest-note, .verify-note { color: var(--warn); }
.ok-note { color: var(--ok); }
.chip-btn {
  padding: .2rem .65rem; border: 1px solid var(--accent); color: var(--accent);
  background: #fff; border-radius: 999px; font-size: .8rem;
}
.chip-btn:hover { background: #eef4ff; }

/* Jump-to-field highlight */
.flash { animation: flashbg 1.6s ease-out; }
@keyframes flashbg {
  0%   { box-shadow: 0 0 0 3px rgba(31,111,235,.55); }
  100% { box-shadow: 0 0 0 0 rgba(31,111,235,0); }
}
