/* ============================================================
    PMS Manual Extraction Platform - frontend styles
   ============================================================ */
:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #e3e8ef;
  --text: #1c2430;
  --muted: #6b7685;
  --accent: #0b5cad;
  --accent-2: #0e7490;
  --accent-soft: #e8f1fb;
  --sidebar: #0f1b2d;
  --sidebar-2: #16263d;
  --sidebar-text: #c6d0dd;
  --sidebar-active: #1d3a5f;
  --green: #17803d;
  --green-bg: #e7f6ec;
  --amber: #b45309;
  --amber-bg: #fef3e2;
  --red: #b42318;
  --red-bg: #fdecea;
  --blue: #0b5cad;
  --blue-bg: #e8f1fb;
  --gray-bg: #eef1f5;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
  --shadow-lg: 0 8px 30px rgba(16,24,40,.12);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}
button { font-family: inherit; }

#app { display: flex; height: 100vh; overflow: hidden; }

/* ---------------- Sidebar ---------------- */
#sidebar {
  width: 240px;
  min-width: 240px;
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 12px 14px;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 9px;
  background: linear-gradient(135deg, #1d7ed8, #0e7490);
  color: #fff; font-weight: 800; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: .5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { color: #fff; font-size: 13.5px; }
.brand-text span { font-size: 11px; color: #8fa1b8; }

.nav-section { margin-top: 10px; }
.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px;
  color: #7d8ca1; padding: 8px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px; margin: 2px 0;
  background: transparent; border: 0; border-radius: 8px;
  color: var(--sidebar-text); font-size: 13.5px; cursor: pointer;
  text-align: left; transition: background .15s;
}
.nav-item svg { width: 17px; height: 17px; fill: currentColor; opacity: .85; }
.nav-item:hover:not(:disabled) { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item:disabled { opacity: .35; cursor: not-allowed; }
.nav-spacer { flex: 1; }
.nav-footer { border-top: 1px solid rgba(255,255,255,.08); padding-top: 10px; }

.whoami-badge {
  display: flex; gap: 9px; align-items: center;
  padding: 8px 10px; margin-bottom: 8px;
  background: rgba(255,255,255,.05); border-radius: 8px;
}
.whoami-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; flex-shrink: 0; }
.whoami-label { font-size: 12.5px; color: #fff; font-weight: 600; }
.whoami-role { font-size: 11px; color: #8fa1b8; text-transform: capitalize; }
.hidden { display: none !important; }

.conn-status { display: flex; align-items: center; gap: 7px; padding: 6px 10px 2px; font-size: 11.5px; color: #8fa1b8; }
.conn-dot { width: 7px; height: 7px; border-radius: 50%; background: #64748b; }
.conn-dot.ok { background: #22c55e; box-shadow: 0 0 6px #22c55e88; }
.conn-dot.err { background: #ef4444; }

/* ---------------- Main ---------------- */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px 14px; background: var(--panel);
  border-bottom: 1px solid var(--border); gap: 16px;
}
.topbar-left h1 { margin: 0; font-size: 19px; font-weight: 700; }
.view-sub { font-size: 12.5px; color: var(--muted); margin-left: 10px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.vessel-select-wrap { display: flex; align-items: center; gap: 8px; }
.vessel-select-wrap label { font-size: 12.5px; color: var(--muted); }
.vessel-select-wrap select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 7px;
  background: #fff; font-size: 13px; min-width: 200px; color: var(--text);
}

#content { flex: 1; overflow-y: auto; padding: 24px; }
#view-root { max-width: 1280px; margin: 0 auto; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s;
  background: var(--accent); color: #fff;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { fill: currentColor; }
.btn-ghost { background: #fff; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--gray-bg); filter: none; }
.btn-outline { background: #fff; color: var(--accent); border-color: var(--accent); }
.btn-outline:hover { background: var(--accent-soft); filter: none; }
.btn-danger { background: var(--red); }
.btn-success { background: var(--green); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-lg { padding: 10px 18px; font-size: 14px; }

/* ---------------- Cards / panels ---------------- */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 20px;
}
.card-title {
  font-size: 15px; font-weight: 700; margin: 0 0 4px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.card-sub { font-size: 12.5px; color: var(--muted); margin: 0 0 16px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

/* Stat tiles */
.stat {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.stat::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--accent);
}
.stat.s-green::before { background: var(--green); }
.stat.s-amber::before { background: var(--amber); }
.stat.s-red::before { background: var(--red); }
.stat.s-cyan::before { background: var(--accent-2); }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 28px; font-weight: 800; margin-top: 6px; line-height: 1; }
.stat-sub { font-size: 12.5px; color: var(--muted); margin-top: 7px; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 11px 14px; background: #f8fafc;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid #f0f2f5; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fafc; }
.td-strong { font-weight: 600; }
.td-muted { color: var(--muted); }
.td-mono { font-family: var(--mono); font-size: 12px; }
.empty-state {
  text-align: center; padding: 48px 20px; color: var(--muted);
}
.empty-state strong { display: block; font-size: 15px; color: var(--text); margin-bottom: 6px; }

/* ---------------- Badges ---------------- */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge-gray { background: var(--gray-bg); color: var(--muted); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }

/* ---------------- Progress ---------------- */
.progress {
  height: 8px; background: var(--gray-bg); border-radius: 99px; overflow: hidden;
  min-width: 90px;
}
.progress-bar { height: 100%; background: linear-gradient(90deg, #1d7ed8, #0e7490); border-radius: 99px; transition: width .4s; }
.progress-bar.done { background: var(--green); }
.progress-bar.err { background: var(--red); }

/* ---------------- Forms ---------------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.field input, .field select, .field textarea {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13.5px; font-family: inherit; background: #fff; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input[readonly] { background: var(--gray-bg); }
.field .hint { font-size: 11.5px; color: var(--muted); }
.field .err-msg { font-size: 12px; color: var(--red); }

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

/* Upload dropzone */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 32px; text-align: center; background: #fafbfd;
  cursor: pointer; transition: all .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone-icon { font-size: 34px; margin-bottom: 8px; opacity: .5; }
.dropzone strong { display: block; font-size: 14.5px; margin-bottom: 4px; }
.dropzone span { font-size: 12.5px; color: var(--muted); }

/* ---------------- Tabs ---------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab {
  padding: 10px 16px; background: none; border: 0; border-bottom: 2px solid transparent;
  font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .count {
  display: inline-block; margin-left: 6px; padding: 1px 7px;
  background: var(--gray-bg); border-radius: 99px; font-size: 11px; font-weight: 700;
}
.tab.active .count { background: var(--accent-soft); color: var(--accent); }

/* ---------------- Modal ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,27,45,.5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 20px; animation: fadeIn .15s;
}
.modal {
  background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  animation: slideUp .2s;
}
.modal-lg { max-width: 760px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 16px; }
.modal-close {
  background: none; border: 0; font-size: 22px; cursor: pointer;
  color: var(--muted); line-height: 1; padding: 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 22px; }
.modal-footer {
  padding: 16px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------- Toast ---------------- */
#toast-root {
  position: fixed; right: 20px; bottom: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px; max-width: 380px;
}
.toast {
  background: #1c2430; color: #fff; padding: 12px 16px; border-radius: 10px;
  font-size: 13px; box-shadow: var(--shadow-lg); display: flex; gap: 10px;
  align-items: flex-start; animation: slideUp .2s;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.info { background: var(--accent); }
.toast .toast-close { background: none; border: 0; color: #ffffffaa; cursor: pointer; font-size: 15px; margin-left: auto; padding: 0 0 0 8px; }

/* ---------------- Coverage rings / bars ---------------- */
.cov-item { margin-bottom: 14px; }
.cov-item:last-child { margin-bottom: 0; }
.cov-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.cov-head strong { font-weight: 600; }
.cov-head span { color: var(--muted); }
.cov-track { height: 10px; background: var(--gray-bg); border-radius: 99px; overflow: hidden; }
.cov-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, #1d7ed8, #0e7490); transition: width .5s; }
.cov-fill.green { background: linear-gradient(90deg, #17803d, #22c55e); }
.cov-fill.amber { background: linear-gradient(90deg, #b45309, #f59e0b); }

/* Document row actions */
.doc-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Fleet row kebab menu (Edit / Delete vessel) */
.kebab { position: relative; display: inline-flex; }
.kebab-btn {
  border: 1px solid var(--border); background: #fff; color: inherit;
  font-size: 17px; line-height: 1; padding: 3px 7px; cursor: pointer;
  border-radius: 8px;
}
.kebab-btn:hover { background: var(--gray-bg); }
.kebab-menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 40;
  min-width: 140px; padding: 4px; display: flex; flex-direction: column;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 10px 26px rgba(15, 23, 42, .14);
}
.kebab-item {
  border: none; background: transparent; text-align: left;
  padding: 8px 10px; font-size: 13px; cursor: pointer; border-radius: 6px;
  color: inherit;
}
.kebab-item:hover { background: var(--gray-bg); }
.kebab-item.danger { color: var(--red); }
.kebab-item.danger:hover { background: var(--red-bg); }

/* Filter bar */
.filter-bar {
  display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap;
}
.filter-bar input[type="search"], .filter-bar select {
  padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; min-width: 220px; background: #fff;
}
.filter-bar input:focus, .filter-bar select:focus { outline: none; border-color: var(--accent); }
.filter-bar .spacer { flex: 1; }

/* Pager */
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 14px; font-size: 13px; color: var(--muted); }

/* Page header helper */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 17px; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

/* Inline callout */
.callout {
  padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 16px;
  background: var(--blue-bg); color: var(--blue); border: 1px solid #c9def5;
}
.callout.warn { background: var(--amber-bg); color: var(--amber); border-color: #fde1b8; }
.callout.err { background: var(--red-bg); color: var(--red); border-color: #f5c6c2; }

/* Key reveal */
.key-reveal {
  font-family: var(--mono); font-size: 14px; background: var(--gray-bg);
  padding: 12px 14px; border-radius: 8px; word-break: break-all;
  border: 1px dashed var(--border); margin: 10px 0;
}

/* Spinner */
.spinner {
  width: 16px; height: 16px; border: 2px solid #ffffff66; border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
.spinner.dark { border-color: var(--border); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Settings layout */
.settings-wrap { max-width: 640px; }

/* Role pill in whoami */
.role-admin { color: #f59e0b; }
.role-reviewer { color: #38bdf8; }
.role-viewer { color: #94a3b8; }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* Responsive sidebar collapse handled via JS class */
@media (max-width: 860px) {
  #sidebar { width: 64px; min-width: 64px; padding: 14px 8px; }
  .brand-text, .nav-label, .nav-item span, .whoami-badge, .conn-status span:last-child { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .nav-item svg { width: 20px; height: 20px; }
  .brand { justify-content: center; padding: 4px 0 14px; }
}

/* Source-PDF info button (Master / Jobs / Spares rows) */
.info-btn {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--panel);
  color: var(--muted);
  font-family: var(--mono, monospace);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: color .12s, border-color .12s;
}
.info-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* Login / signup */
.auth-wrap { display: flex; justify-content: center; padding-top: 48px; }

/* Password strength meter (login, create-user, reset-password) */
.pw-meter { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.pw-strength { flex: 1; height: 6px; background: var(--gray-bg); border-radius: 4px; overflow: hidden; }
.pw-fill { height: 100%; width: 0; background: var(--gray-bg); border-radius: 4px; transition: width .15s ease, background .15s ease; }
.pw-l1 { background: var(--red); }
.pw-l2 { background: var(--amber); }
.pw-l3 { background: var(--blue); }
.pw-l4 { background: var(--green); }
.pw-label { font-size: 12px; min-width: 48px; text-align: right; }

/* Text-style link button (Forgot password?, Copy key, etc.) */
.link-btn {
  background: none;
  border: none;
  padding: 4px 0 0;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
}
.link-btn:hover { color: var(--text); }

/* Bulk upload progress (zip upload) */
.upload-prog { margin-top: 14px; }
.upload-bar { height: 8px; background: var(--gray-bg); border-radius: 4px; overflow: hidden; }
.upload-fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .2s ease; }
.upload-pct { font-size: 12px; display: inline-block; margin-top: 4px; }

/* Users table: action buttons + role select */
.actions-cell button { margin-right: 6px; }
.actions-cell select { max-width: 110px; }
