/* CrewMan - giao diện */
:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e3e7eb;
  --text: #13202b;
  --text-2: #4f5d69;
  --muted: #84909a;
  --primary: #0e3a5b;
  --primary-2: #175a8a;
  --accent: #2a78d6;
  --side-bg: #0c2a42;
  --side-text: #c9d6e2;
  --side-active: #ffffff;
  --row-hover: #f1f6fb;
  --series-1: #2a78d6;   /* trên tàu */
  --series-2: #eb6834;   /* dự trữ */
  --grid: #e1e0d9;
  --good: #0ca30c; --good-bg: #e6f6e6; --good-ink: #0b6b0b;
  --warn: #fab219; --warn-bg: #fff4d9; --warn-ink: #7a5300;
  --serious: #ec835a; --serious-bg: #fde9df; --serious-ink: #94401b;
  --critical: #d03b3b; --critical-bg: #fbe3e3; --critical-ink: #9b2222;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 2px 8px rgba(16, 32, 48, .05);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1418; --surface: #182027; --surface-2: #1d262e; --border: #2a353f;
    --text: #eef2f5; --text-2: #b8c3cc; --muted: #8b97a1;
    --primary: #4b9be6; --primary-2: #6aaef0; --accent: #3987e5;
    --side-bg: #0a1117; --row-hover: #1f2b35;
    --series-1: #3987e5; --series-2: #d95926; --grid: #2c2c2a;
    --good-bg: #12301a; --good-ink: #7fdc7f; --warn-bg: #3a2e0c; --warn-ink: #ffd36b;
    --serious-bg: #3d2117; --serious-ink: #f5a98a; --critical-bg: #3d1717; --critical-ink: #f29b9b;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.nowrap { white-space: nowrap; }
.error { color: var(--critical-ink); min-height: 18px; font-size: 13px; }

/* ---------- đăng nhập */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 20% 0%, #1b5d8f 0%, #0c2a42 55%, #08192a 100%); }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border-radius: 14px; padding: 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35); display: grid; gap: 12px; }
.brand-lg { font-size: 24px; font-weight: 700; color: var(--primary); }
.login-card p { margin: -8px 0 6px; }

/* ---------- bố cục */
.layout { display: flex; min-height: 100%; }
.sidebar { width: 232px; flex: none; background: var(--side-bg); color: var(--side-text); display: flex;
  flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { font-size: 19px; font-weight: 700; color: #fff; padding: 18px 20px; letter-spacing: .2px; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: #1f6aa5; color: #fff; font-size: 17px; margin-right: 6px; }
#nav { display: flex; flex-direction: column; padding: 4px 10px; gap: 2px; flex: 1; overflow-y: auto; }
#nav a { color: var(--side-text); padding: 9px 12px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
#nav a i { font-style: normal; width: 20px; text-align: center; opacity: .85; }
#nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
#nav a.active { background: rgba(255,255,255,.13); color: var(--side-active); font-weight: 600; }
.sidebar-foot { padding: 14px 20px; font-size: 12px; color: #8ea4b8; border-top: 1px solid rgba(255,255,255,.08); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.search-wrap { position: relative; flex: 1; max-width: 520px; }
.search-wrap input { width: 100%; }
.search-results { position: absolute; top: 40px; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); max-height: 380px; overflow-y: auto; z-index: 30; }
.search-results a { display: flex; justify-content: space-between; gap: 8px; padding: 8px 12px; color: var(--text); }
.search-results a:hover, .search-results a.sel { background: var(--row-hover); text-decoration: none; }
.user-box { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.menu-btn { display: none; }
.view { padding: 22px 24px 40px; max-width: 1500px; width: 100%; }

/* ---------- thành phần */
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .spacer { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head .spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; display: block; color: var(--text); }
a.kpi:hover { text-decoration: none; border-color: var(--accent); }
.kpi .label { color: var(--text-2); font-size: 12.5px; }
.kpi .value { font-size: 28px; font-weight: 650; margin-top: 2px; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.alert .value { color: var(--critical-ink); }
.kpi.warn .value { color: var(--warn-ink); }

.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 14px;
  font: inherit; font-weight: 550; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--primary-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--critical-ink); }
.btn.danger:hover { border-color: var(--critical); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; padding: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: transparent; font-size: 18px; cursor: pointer; color: var(--text-2); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--row-hover); }

input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { width: 100%; padding-right: 40px; }
.pw-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; border: 0;
  background: transparent; color: var(--muted); border-radius: 6px; cursor: pointer; display: grid; place-items: center; padding: 0; }
.pw-eye:hover { color: var(--text); background: var(--row-hover); }
.pw-eye .eye-off { display: none; }
.pw-eye.on .eye-open { display: none; }
.pw-eye.on .eye-off { display: block; }
label { display: grid; gap: 4px; font-size: 12.5px; color: var(--text-2); font-weight: 550; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters input[type=search] { width: 260px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.form-section { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 650; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--text); font-size: 14px; }

/* bảng */
.table-wrap { overflow: auto; max-height: calc(100vh - 230px); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .3px;
  color: var(--text-2); font-weight: 650; z-index: 1; white-space: nowrap; }
th.sortable, .sortable { cursor: pointer; user-select: none; }
th.sortable:hover, .sortable:hover { color: var(--text); }
/* lọc theo cột kiểu Excel */
.th-in { display: inline-flex; align-items: center; gap: 4px; }
th.num .th-in { flex-direction: row; }
.col-btn { border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px;
  line-height: 1; padding: 3px 4px; border-radius: 4px; }
.col-btn:hover { border-color: var(--border); background: var(--surface); color: var(--text); }
.col-btn.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.col-menu { position: fixed; z-index: 60; width: 270px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 28px rgba(16, 32, 48, .18); padding: 8px; display: grid; gap: 4px;
  text-transform: none; letter-spacing: 0; font-size: 13.5px; font-weight: 400; color: var(--text); }
.col-menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; width: 100%; }
.cm-sort { border: 0; background: none; text-align: left; padding: 6px 8px; border-radius: 6px; cursor: pointer; font: inherit; color: var(--text); }
.cm-sort:hover { background: var(--row-hover); }
.cm-q { width: 100%; }
.cm-list { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 6px; padding: 2px 0; }
.cm-row { display: flex; align-items: center; gap: 8px; padding: 4px 8px; font-size: 13px; font-weight: 400; color: var(--text); cursor: pointer; }
.cm-row:hover { background: var(--row-hover); }
.cm-row span:first-of-type { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm-all { padding-left: 9px; }
.cm-actions { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
tbody tr.click { cursor: pointer; }
tbody tr:hover { background: var(--row-hover); }
td.code { font-family: ui-monospace, Consolas, monospace; font-size: 13px; color: var(--text-2); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* nhãn trạng thái: luôn có biểu tượng + chữ, không dùng màu đơn thuần */
.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 9px; font-size: 12px;
  font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.b-ok { background: var(--good-bg); color: var(--good-ink); }
.b-yellow { background: var(--warn-bg); color: var(--warn-ink); border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.b-red { background: var(--serious-bg); color: var(--serious-ink); border-color: color-mix(in srgb, var(--serious) 50%, transparent); }
.b-expired { background: var(--critical-bg); color: var(--critical-ink); border-color: color-mix(in srgb, var(--critical) 50%, transparent); }
.b-none { background: var(--surface-2); color: var(--muted); border-color: var(--border); }
.b-onboard { background: color-mix(in srgb, var(--series-1) 14%, transparent); color: var(--text); border-color: color-mix(in srgb, var(--series-1) 40%, transparent); }
.b-standby { background: color-mix(in srgb, var(--series-2) 14%, transparent); color: var(--text); border-color: color-mix(in srgb, var(--series-2) 40%, transparent); }
.b-inactive { background: var(--surface-2); color: var(--muted); border-color: var(--border); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.onboard { background: var(--series-1); }
.dot.standby { background: var(--series-2); }

/* hồ sơ */
.profile-head { display: flex; gap: 18px; align-items: center; padding: 18px; flex-wrap: wrap; }
.avatar { width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center; font-size: 24px; font-weight: 700;
  color: #fff; background: linear-gradient(135deg, #175a8a, #0e3a5b); flex: none; }
.profile-head .info { flex: 1; min-width: 220px; }
.profile-head .meta { display: flex; gap: 14px; flex-wrap: wrap; color: var(--text-2); margin-top: 6px; }
.profile-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 12px; overflow-x: auto; }
.tabs button { border: 0; background: none; font: inherit; padding: 11px 12px; color: var(--text-2); cursor: pointer;
  border-bottom: 2px solid transparent; font-weight: 550; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 2px 24px; padding: 14px 18px; }
.kv div { padding: 7px 0; border-bottom: 1px dashed var(--border); display: flex; gap: 10px; justify-content: space-between; }
.kv span:first-child { color: var(--muted); flex: none; }
.kv span:last-child { text-align: right; overflow-wrap: anywhere; }
.group-row td { background: var(--surface-2); font-weight: 650; color: var(--text-2); font-size: 12.5px; }

/* biểu đồ cột ngang: trên tàu / dự trữ theo chức danh */
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-2); align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.bars { display: grid; grid-template-columns: 74px 1fr 64px; gap: 3px 10px; align-items: center; padding: 12px 18px 16px; }
.bars .lbl { font-size: 12.5px; color: var(--text-2); text-align: right; }
.bars .track { display: flex; flex-direction: column; gap: 2px; padding: 3px 0; border-left: 1px solid var(--grid); }
.bars .bar { height: 9px; border-radius: 0 4px 4px 0; min-width: 2px; }
.bars .bar.s1 { background: var(--series-1); }
.bars .bar.s2 { background: var(--series-2); }
.bars .val { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.bars .row-hit { display: contents; }
.split { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; margin: 8px 0 6px; }
.split div { height: 100%; }
.tip { position: fixed; z-index: 100; background: var(--text); color: var(--surface); padding: 6px 10px; border-radius: 6px;
  font-size: 12.5px; pointer-events: none; box-shadow: var(--shadow); max-width: 280px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 9px 18px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center; }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }

/* thẻ tàu */
.vessel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.vessel-card { padding: 14px 16px; color: var(--text); display: block; }
.vessel-card:hover { text-decoration: none; border-color: var(--accent); }
.vessel-card .code { font-weight: 700; font-size: 16px; color: var(--primary); }
.vessel-card .n { font-size: 26px; font-weight: 650; }

/* ma trận */
.matrix td, .matrix th { text-align: center; padding: 6px 6px; font-variant-numeric: tabular-nums; }
.matrix td:first-child, .matrix th:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 2; white-space: nowrap; }
.matrix th:first-child { background: var(--surface-2); z-index: 3; }
.matrix td.zero { color: var(--muted); }
.matrix td.miss { background: var(--critical-bg); color: var(--critical-ink); font-weight: 700; }
.matrix tr.total td { font-weight: 700; background: var(--surface-2); }

/* kế hoạch */
.plan-item { display: grid; grid-template-columns: minmax(220px, 1.1fr) 2fr; gap: 14px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.cands { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.cand { border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; color: var(--text); font-size: 13px; background: var(--surface-2); }
.cand:hover { border-color: var(--accent); text-decoration: none; }

/* modal & thông báo */
.modal { position: fixed; inset: 0; background: rgba(8, 20, 32, .5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--surface); border-radius: 14px; width: 100%; max-width: 720px; max-height: calc(100vh - 32px); overflow: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); }
#modal-body { padding: 16px 18px 18px; }
.toast { position: fixed; bottom: 22px; right: 22px; background: var(--text); color: var(--surface); padding: 11px 16px; border-radius: 10px;
  z-index: 60; box-shadow: var(--shadow); max-width: 420px; }
.toast.err { background: var(--critical); color: #fff; }
.note { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; color: var(--text-2); }
.note.warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 50%, transparent); color: var(--warn-ink); }
.steps { margin: 6px 0 0; padding-left: 20px; }
.steps li { margin: 4px 0; }

/* ---------- bản in */
.print-page { background: #fff; color: #000; padding: 24px 28px; font-family: "Times New Roman", serif; font-size: 13px; overflow-x: auto; }
.print-page h2 { text-align: center; font-size: 17px; margin: 6px 0; }
.print-page table { border-collapse: collapse; width: 100%; }
.print-page th, .print-page td { border: 1px solid #333; padding: 4px 6px; color: #000; background: #fff; position: static; font-size: 12px; text-transform: none; letter-spacing: 0; }
.print-page th { font-weight: 700; text-align: center; }
.print-page .hdr-center { text-align: center; line-height: 1.5; }
.print-page .fields { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px 16px; margin: 12px 0; }
.print-page [contenteditable] { border-bottom: 1px dotted #999; min-width: 80px; display: inline-block; outline: none; }
.print-page .sec { font-weight: 700; margin: 14px 0 6px; font-size: 14px; }
.print-toolbar { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }

@media print {
  .sidebar, .topbar, .print-toolbar, .toast, .no-print { display: none !important; }
  .view { padding: 0; max-width: none; }
  body { background: #fff; }
  .print-page { padding: 0; }
  @page { size: A4 landscape; margin: 12mm; }
  @page portrait { size: A4 portrait; margin: 12mm; }
  .print-page.portrait { page: portrait; }
}

/* ---------- màn hình nhỏ */
@media (max-width: 900px) {
  .g2, .g3 { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -240px; z-index: 40; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .menu-btn { display: inline-block; }
  .user-box .btn { display: none; }
  .user-box #user-name { display: none; }
  .topbar { padding: 10px 16px; }
  .view { padding: 16px; }
  .plan-item { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px; }
  .kpi .value { font-size: 24px; }
  .page-head h1 { font-size: 19px; }
  .filters input[type=search] { width: 100%; }
  .table-wrap { max-height: none; }
}
