:root {
  --bg: #0a0f18; --panel: #12192b; --panel2: #1a2847; --line: #2a3a56; --text: #e6edf3; --muted: #8aa0b6;
  --accent: #64c8ff; --ok: #4caf50; --warn: #ffb020; --bad: #ff4d4f; --crit: #ff6b9a;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: linear-gradient(135deg, #0a0f18 0%, #12192b 100%); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; transition: color 0.2s ease; }
a:hover { color: #7dd9ff; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; }
.mt { margin-top: 22px; }
[hidden] { display: none !important; }

/* header */
.top { display: flex; align-items: center; gap: 14px; padding: 14px 20px; background: linear-gradient(135deg, rgba(18, 25, 43, 0.8) 0%, rgba(26, 40, 71, 0.5) 100%); border-bottom: 1px solid rgba(255, 255, 255, 0.08);
       position: sticky; top: 0; z-index: 5; flex-wrap: wrap; backdrop-filter: blur(10px); }
.brand { font-weight: 700; color: var(--text); letter-spacing: .3px; font-size: 16px; }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top nav a { color: var(--muted); padding: 8px 12px; border-radius: 8px; transition: all 0.2s ease; }
.top nav a.active, .top nav a:hover { color: var(--text); background: rgba(100, 200, 255, 0.15); }
.spacer { flex: 1; }
.top select { width: auto; min-width: 160px; padding: 6px 8px; background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 6px; color: var(--text); }
.who { color: var(--muted); font-size: 13px; white-space: nowrap; }
.badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, 0.12); color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.badge.admin { color: #64c8ff; border-color: rgba(100, 200, 255, 0.3); background: rgba(100, 200, 255, 0.08); }

/* tabs */
.tabs { display: flex; gap: 2px; padding: 0 20px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); overflow-x: auto; }
.tabs a { color: var(--muted); padding: 12px 16px; border-bottom: 2px solid transparent; white-space: nowrap; transition: all 0.2s ease; }
.tabs a.active { color: var(--text); border-bottom-color: #64c8ff; }
.tabs a:hover { color: var(--text); }

main { padding: 20px; max-width: 1280px; margin: 0 auto; }
.card { background: linear-gradient(135deg, rgba(18, 25, 43, 0.6) 0%, rgba(26, 40, 71, 0.4) 100%); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 14px; padding: 20px; margin-bottom: 16px; min-width: 0; transition: all 0.3s ease; }
.card:hover { border-color: rgba(100, 200, 255, 0.2); background: linear-gradient(135deg, rgba(18, 25, 43, 0.8) 0%, rgba(26, 40, 71, 0.5) 100%); }
.card.flush { padding: 0; overflow-x: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

/* forms */
input, select, textarea, button, .button {
  font: inherit; color: var(--text); background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 8px; padding: 10px 12px; width: 100%; transition: all 0.2s ease;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #64c8ff; background: rgba(100, 200, 255, 0.1); }
textarea { min-height: 100px; resize: vertical; }
button, .button { background: linear-gradient(135deg, #64c8ff 0%, #4db8f5 100%); border-color: transparent; cursor: pointer; width: auto; font-weight: 600; display: inline-block; text-align: center; transition: all 0.2s ease; }
button:hover, .button:hover { transform: translateY(-2px); box-shadow: 0 8px 16px rgba(100, 200, 255, 0.3); }
button:active { transform: translateY(0); }
button.ghost, .button.ghost { background: rgba(255, 255, 255, 0.08); color: var(--text); border-color: rgba(255, 255, 255, 0.12); font-weight: 500; }
button.ghost:hover { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.2); }
button.danger { background: rgba(255, 77, 79, 0.1); color: #ff4d4f; border-color: rgba(255, 77, 79, 0.2); font-weight: 500; }
button.danger:hover { background: rgba(255, 77, 79, 0.2); border-color: rgba(255, 77, 79, 0.4); }
button.small, .button.small { padding: 6px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
.form label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.form label input, .form label select, .form label textarea { margin-top: 4px; }
.f3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.f2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.f4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 620px) { .f4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .f3 { grid-template-columns: 1fr 1fr; } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1; min-width: 80px; }
.filebtn input { display: none; }
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 200px; }
.toolbar select { width: auto; }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; background: rgba(26, 40, 71, 0.5); position: sticky; top: 0; }
tbody tr { transition: background-color 0.2s ease; }
tbody tr:hover { background: rgba(100, 200, 255, 0.05); }
tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
.empty { padding: 32px 24px; text-align: center; color: var(--muted); }

/* status chips */
.chip { display: inline-block; font-size: 12px; padding: 3px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.12); white-space: nowrap; font-weight: 500; transition: all 0.2s ease; }
.chip.ok { color: #4caf50; border-color: rgba(76, 175, 80, 0.3); background: rgba(76, 175, 80, 0.1); }
.chip.warn { color: #ffb020; border-color: rgba(255, 176, 32, 0.3); background: rgba(255, 176, 32, 0.1); }
.chip.bad { color: #ff4d4f; border-color: rgba(255, 77, 79, 0.3); background: rgba(255, 77, 79, 0.1); }
.chip.crit { color: #ff6b9a; border-color: rgba(255, 107, 154, 0.3); background: rgba(255, 107, 154, 0.1); }
.chip.info { color: #64c8ff; border-color: rgba(100, 200, 255, 0.3); background: rgba(100, 200, 255, 0.08); }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 16px; }
.tile { background: linear-gradient(135deg, rgba(18, 25, 43, 0.6) 0%, rgba(26, 40, 71, 0.4) 100%); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 12px; padding: 16px; transition: all 0.3s ease; }
.tile:hover { border-color: rgba(100, 200, 255, 0.2); transform: translateY(-2px); }
.tile b { display: block; font-size: 28px; font-variant-numeric: tabular-nums; color: #64c8ff; }
.tile span { color: var(--muted); font-size: 13px; }

.list-item { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.list-item:last-child { border-bottom: 0; }
.flash { padding: 12px 14px; border-radius: 8px; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.12); }
.flash.bad { border-color: rgba(255, 77, 79, 0.4); background: rgba(255, 77, 79, 0.1); color: #ff4d4f; }
.flash.ok { border-color: rgba(76, 175, 80, 0.4); background: rgba(76, 175, 80, 0.1); color: #4caf50; }
.bar { height: 6px; background: rgba(255, 255, 255, 0.08); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #64c8ff 0%, #4db8f5 100%); transition: width .2s; }

dialog { background: linear-gradient(135deg, rgba(18, 25, 43, 0.8) 0%, rgba(26, 40, 71, 0.6) 100%); color: var(--text); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 14px; padding: 24px; width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .65); }

.check { display: flex !important; gap: 8px; align-items: center; color: var(--text) !important; font-size: 14px !important; margin: 6px 0 !important; }
.check input { width: auto; margin: 0 !important; }
.check small { color: var(--muted); }
td select.inline { width: auto; padding: 3px 6px; font-size: 13px; }
.spacer { flex: 1; }

/* history */
dialog.wide { width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
.tiles.small { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 12px 0 16px; }
.tiles.small .tile { padding: 10px; }
.tiles.small .tile b { font-size: 18px; }
.timeline { list-style: none; margin: 8px 0 0; padding: 0 0 0 16px; border-left: 2px solid rgba(255, 255, 255, 0.12); }
.timeline li { position: relative; display: flex; justify-content: space-between; gap: 12px; padding: 10px 0 10px 10px; font-size: 14px; transition: color 0.2s ease; }
.timeline li::before { content: ""; position: absolute; left: -23px; top: 14px; width: 12px; height: 12px; border-radius: 50%; background: rgba(255, 255, 255, 0.12); border: 2px solid rgba(255, 255, 255, 0.2); }
.timeline li > .muted { white-space: nowrap; flex-shrink: 0; }
.timeline li.ev-completed::before { background: #4caf50; border-color: #4caf50; }
.timeline li.ev-created::before, .timeline li.ev-pinned::before { background: #64c8ff; border-color: #64c8ff; }
.timeline li.ev-archived::before { background: #ff4d4f; border-color: #ff4d4f; }
tr.archived td { opacity: .6; }
@media (max-width: 640px) { .timeline li { flex-direction: column; gap: 2px; } .timeline li > .muted { white-space: normal; } }

/* repair estimates */
ol.steps { margin: 0; padding-left: 20px; font-size: 14px; }
ol.steps li { margin: 6px 0; }
ul.notes { padding-left: 18px; margin: 14px 0 0; }
.estimate-box { border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; background: rgba(26, 40, 71, 0.4); }

/* AI corrosion findings */
.finding-view { position: relative; margin: 14px 0; line-height: 0; border-radius: 10px; overflow: hidden; }
.finding-view img { width: 100%; border-radius: 10px; display: block; }
.finding-box { position: absolute; border: 2px solid #ffb020; border-radius: 4px; line-height: 1.2; }
.finding-box.g4, .finding-box.g5 { border-color: #ff4d4f; }
.finding-box span { position: absolute; top: -22px; left: -2px; font-size: 11px; padding: 2px 6px; background: rgba(0, 0, 0, 0.8); color: #fff; border-radius: 4px; white-space: nowrap; font-weight: 500; }

.coat-list { margin: 8px 0 0; padding-left: 0; list-style: none; }
.coat-list li { margin: 4px 0; }
.roller-warning { margin: 10px 0; padding: 8px 12px; border-left: 3px solid #ffb020; background: rgba(255, 176, 32, 0.12); border-radius: 4px; font-weight: 600; }

/* dropdown lists: dark background, light text, so every option (all vessels) is readable */
select { color-scheme: dark; }
select option, select optgroup { background-color: #0f1b2d; color: #e6edf3; }
select option:checked { background-color: #1f4f7a; color: #ffffff; }

/* navbar user profile cluster (rendered by common.js) */
:root { --accent2: #8b7bff; --ease: cubic-bezier(.2, .8, .2, 1); --shadow: 0 10px 30px -12px rgba(0, 0, 0, .65);
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; --line-strong: rgba(125, 200, 255, .30); --danger: #ff5d6c; }
.top select { width: auto; min-width: 160px; padding: 6px 30px 6px 10px; }
.user-cluster {
  position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px;
  border-radius: 12px; border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(16, 33, 60, .78), rgba(8, 18, 36, .78));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 8px 22px -14px rgba(0, 0, 0, .85);
}
.who {
  display: inline-flex; align-items: center; gap: 9px; padding: 4px 10px 4px 6px;
  border: 1px solid transparent; border-radius: 9px; background: transparent;
  color: var(--text); font-size: 13px; font-weight: 500; white-space: nowrap;
  box-shadow: none; width: auto; text-align: left; letter-spacing: 0; filter: none;
}
.who:hover:not(:disabled), .who[aria-expanded="true"] {
  background: rgba(125, 200, 255, .08); border-color: rgba(125, 200, 255, .22);
  color: #fff; transform: none; box-shadow: none; filter: none;
}
.user-avatar {
  position: relative; width: 26px; height: 26px; border-radius: 8px; flex-shrink: 0;
  display: grid; place-items: center; font: 700 10.5px/1 var(--font-mono); letter-spacing: .04em; color: #eaf8ff;
  background: linear-gradient(135deg, rgba(61, 224, 255, .32), rgba(124, 92, 255, .38));
  border: 1px solid rgba(61, 224, 255, .45);
  box-shadow: 0 0 14px -4px rgba(61, 224, 255, .55), inset 0 1px 0 rgba(255, 255, 255, .18);
}
.user-avatar::after {
  content: ""; position: absolute; right: -2px; bottom: -2px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok); border: 1.5px solid #071222; box-shadow: 0 0 8px var(--ok);
}
.user-avatar.lg { width: 36px; height: 36px; border-radius: 10px; font-size: 13px; }
.user-meta { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; min-width: 0; }
.user-name { font-size: 12.5px; font-weight: 600; color: #eaf4ff; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 10.5px; color: var(--muted); max-width: 155px; overflow: hidden; text-overflow: ellipsis; }
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 9.5px; padding: 2px 8px;
  border-radius: 999px; border: 1px solid var(--line-strong); color: var(--muted);
  background: rgba(125, 200, 255, .05);
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.admin {
  color: var(--accent); border-color: rgba(61, 224, 255, .48);
  background: rgba(61, 224, 255, .1); box-shadow: 0 0 12px -6px rgba(61, 224, 255, .8);
}
.signout-btn {
  position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px;
  border-radius: 9px; border: 1px solid rgba(125, 200, 255, .16);
  background: rgba(255, 255, 255, .03); color: #cde2fa;
  font-size: 12.5px; font-weight: 600; letter-spacing: .01em; white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04); width: auto;
}
.signout-btn::before {
  content: ""; position: absolute; left: -3px; top: 20%; bottom: 20%; width: 1px; background: var(--line); pointer-events: none;
}
.signout-btn svg { opacity: .85; transition: transform .2s var(--ease), opacity .2s; flex-shrink: 0; }
.signout-btn:hover:not(:disabled) {
  color: #ffe3e6; border-color: rgba(255, 93, 108, .55);
  background: linear-gradient(135deg, rgba(255, 93, 108, .18), rgba(255, 93, 108, .08));
  box-shadow: 0 0 0 1px rgba(255, 93, 108, .22), 0 8px 20px -8px rgba(255, 93, 108, .65);
  transform: translateY(-1px); filter: none;
}
.signout-btn:hover:not(:disabled) svg { opacity: 1; transform: translateX(2px); }
.user-card {
  position: absolute; top: calc(100% + 10px); right: 0; width: min(300px, calc(100vw - 24px)); z-index: 80;
  padding: 14px; border-radius: 14px; border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, #0d1d38, #071224);
  box-shadow: 0 24px 54px -12px rgba(0, 0, 0, .96), 0 0 0 1px rgba(61, 224, 255, .14);
  animation: ocms-pop .2s var(--ease) both;
}
.user-card-head { display: flex; align-items: center; gap: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.user-card-id { flex: 1; min-width: 0; }
.user-card-name { font-size: 13.5px; font-weight: 600; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-card-email { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-card-meta { display: grid; gap: 7px; padding-top: 10px; font-size: 12px; }
.user-card-meta > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.user-card-meta span { color: var(--muted); font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; }
.user-card-meta b { color: var(--text); font-weight: 500; text-align: right; overflow-wrap: anywhere; }
@keyframes ocms-pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

#utDialog { background: #172238; }
#utNotice:empty { display: none; }
.ut-form { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.ut-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: 10px 14px; }
.ut-warning { color: #ffcf75; }
.ut-error { color: #ff9b9c; white-space: pre-wrap; }
.ut-status-note { display: block; margin-top: 4px; font-size: 12px; }

/* Plan upload, reading and model approval */
#plansInfo, .plan-upload { margin-top: 12px; overflow-wrap: anywhere; }

#toolsImportStatus { overflow-wrap: anywhere; }
#toolsImportDialog { background: var(--panel, #182633); }
.tools-import-row { margin-bottom: 8px; }
.form .tools-import-choice { display: flex; align-items: baseline; gap: 8px; color: var(--text); }
.tools-import-choice input { flex: none; }
.tools-import-row dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 185px), 1fr)); gap: 8px 16px; margin: 8px 0; }
.tools-import-row dt { color: var(--muted); font-size: 13px; }
.tools-import-row dd { margin: 0; white-space: pre-wrap; }
.form .tools-import-reason:has(input:enabled:invalid) { color: var(--warn); }
.tools-import-reason input:enabled:invalid { border-color: var(--warn); }
.tools-import-actions { justify-content: flex-end; }
#toolsImportError { position: static; flex: 0 0 100%; max-height: 22vh; overflow: auto; margin: 0; box-sizing: border-box; }

.plan-upload progress { display: block; width: 100%; margin-top: 4px; accent-color: var(--accent); }
.plan-steps, .plan-files, .plan-particulars { list-style: none; padding: 0; margin: 0; }
.plan-steps > li { display: grid; grid-template-columns: 1.1rem minmax(0, 1fr); gap: 8px; padding: 9px 0; }
.plan-steps > li + li { border-top: 1px solid var(--line); }
.plan-steps strong { color: var(--text); }
.plan-steps small { display: block; font-size: inherit; }
.plan-steps button { display: block; margin-top: 6px; }
.plan-files { margin: 5px 0; }
.plan-files li, .plan-particulars li { display: flex; align-items: baseline; gap: 6px; }
.plan-files li + li { margin-top: 4px; }
.plan-particulars { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; }
.plan-mark { display: inline-grid; place-items: center; width: 1em; height: 1em; flex: none; }
.plan-mark.done { color: var(--ok); }
.plan-mark.failed { color: var(--bad); }
.plan-mark.working {
  color: var(--accent); border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: plan-spin .8s linear infinite; vertical-align: -.1em;
}
.plan-steps > li > .plan-mark { margin-top: .23em; }
#pmDims small, #pmErr { overflow-wrap: anywhere; }
.plan-preview-status { display: flex; align-items: center; justify-content: center; gap: 8px; height: 100%; padding: 12px; }
@keyframes plan-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .plan-mark.working { animation: none; } }
