﻿:root {
  color-scheme: light dark;
  /* AGP maritime blue identity (same tokens as the trial panel) */
  --bg: #f5f8fa;
  --card: #ffffff;
  --text: #0e1e2b;
  --muted: #5e7482;
  --accent: #12557a;
  --accent-strong: #0d3b57;
  --accent-soft: rgba(18, 85, 122, .10);
  --tint: #e4f0f6;
  --ok: #12715b;
  --warn: #8a5a00;
  --hold: #7a3e00;
  --danger: #a32b22;
  --line: #d9e4eb;
  --line-soft: #edf2f6;
  --shadow: 0 1px 2px rgba(10, 42, 63, .05), 0 10px 24px -18px rgba(10, 42, 63, .35);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1b26;
    --card: #102636;
    --text: #e8f1f6;
    --muted: #9ab4c3;
    --accent: #5aa9cf;
    --accent-strong: #7cc0e0;
    --accent-soft: rgba(90, 169, 207, .16);
    --tint: rgba(90, 169, 207, .14);
    --ok: #5fd3ab;
    --warn: #e7b25c;
    --hold: #e9a06a;
    --danger: #ff9b93;
    --line: #1e3a4b;
    --line-soft: #18313f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 14px 30px -20px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-variant-numeric: tabular-nums;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.6;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }

.logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #1a6e99, var(--accent-strong));
  color: #f2f9fc;
  font-weight: 800;
  font-size: 12.5px;
  letter-spacing: .4px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .18) inset, 0 8px 18px -12px #082537;
  flex: none;
}

.user { display: flex; align-items: center; gap: 10px; color: var(--muted); }

.wrap { max-width: 1200px; margin: 0 auto; padding: 20px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.login-card { max-width: 420px; margin: 8vh auto; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.muted { color: var(--muted); margin: 0 0 18px; font-size: 14px; }

label { display: block; margin-bottom: 14px; font-size: 14px; color: var(--muted); }

input, select {
  width: 100%;
  margin-top: 6px;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
}

input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0 18px;
}

.inline-form input, .inline-form select { flex: 1 1 180px; margin-top: 0; width: auto; }

.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 15px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: filter .15s ease;
}

.btn:hover { filter: brightness(1.06); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.small { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; }

.tab {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 18px;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
}

.tab.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }

.card-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 18px; }
.hint { color: var(--muted); font-size: 13px; }

.table { width: 100%; border-collapse: collapse; margin-top: 6px; }

.table th, .table td {
  text-align: right;
  padding: 9px 9px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

.table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 1;
}

.table tbody tr:hover { background: var(--tint); }
.table tr:last-child td { border-bottom: 0; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent);
}

.badge.off { background: rgba(163, 43, 34, .1); color: var(--danger); }
.badge.done { background: rgba(18, 113, 91, .12); color: var(--ok); }
.badge.hold { background: rgba(122, 62, 0, .12); color: var(--hold); }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.empty { color: var(--muted); text-align: center; padding: 18px; }

.toast {
  position: fixed;
  inset-inline: 0;
  bottom: 22px;
  margin: 0 auto;
  width: max-content;
  max-width: 90vw;
  padding: 12px 18px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 20;
}

.toast.error { background: var(--danger); color: #fff; }
.error { color: var(--danger); font-size: 14px; }

@media (max-width: 640px) {
  .wrap { padding: 14px; }
  .table th:nth-child(3), .table td:nth-child(3) { display: none; }
}

/* ---------- M2: import & trucks ---------- */

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 6px 0 16px;
}

.chip {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.chip.warn { background: rgba(196, 125, 0, .14); color: #b26a00; }
.chip.bad { background: rgba(179, 38, 30, .12); color: var(--danger); }

.table-scroll { max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }

.badge.warn { background: rgba(138, 90, 0, .14); color: var(--warn); }
.badge.bad { background: rgba(163, 43, 34, .12); color: var(--danger); }

.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

input[type="file"] {
  padding: 9px;
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
}

.issues { color: var(--muted); font-size: 12px; }

button.chip {
  border: 0;
  cursor: pointer;
  font-family: inherit;
}

button.chip.active {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

details.card > summary { list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }

/* ---------- M3.1: stages & chat ---------- */

tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--accent-soft); }

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Fixed height (not max-height): a growing thread must not shift the page under the cursor. */
  height: 380px;
  overflow-y: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 12px 0;
  background: var(--bg);
}

.chat-bubble {
  max-width: 70%;
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
}

.chat-bubble.admin {
  align-self: flex-end;
  background: var(--accent-soft);
  border-color: var(--accent);
}

.chat-meta {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}

.chat-image {
  display: block;
  max-width: 220px;
  max-height: 180px;
  border-radius: 8px;
  margin-top: 6px;
  object-fit: cover;
}

/* ---------- notifications bell ---------- */
.bell { position: relative; font-size: 18px; }
.bell-count {
  position: absolute;
  top: -4px;
  inset-inline-end: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.bell-backdrop {
  position: fixed;
  inset: 0;
  background: transparent;
  z-index: 25;
}
.bell-panel {
  position: fixed;
  top: 72px;
  inset-inline-end: 16px;
  z-index: 26;
  width: min(380px, 90vw);
  max-height: 420px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 8px;
  z-index: 30;
}
.bell-item { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.bell-item:last-child { border-bottom: 0; }
.bell-item small { color: var(--muted); }


/* ---------- realtime indicator ---------- */
.live-dot {
  font-size: 14px;
  color: var(--muted);
  transition: color .2s ease;
}
.live-dot.online { color: #1a7f4b; }
.live-dot.offline { color: var(--danger); }
.live-dot.reconnecting { color: #b26a00; }

/* ---------- dashboard ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-card strong { font-size: 28px; font-weight: 800; }

.dashboard-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.feed { display: flex; flex-direction: column; }
.feed-item { padding: 10px 4px; border-bottom: 1px solid var(--line); }
.feed-item:last-child { border-bottom: 0; }
.feed-item small { color: var(--muted); }

/* ---------- direct messages ---------- */
.direct-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  align-items: start;
}

.thread-list { display: flex; flex-direction: column; max-height: 560px; overflow-y: auto; }

.thread-row {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.thread-row:hover { background: var(--accent-soft); }
.thread-row.active { background: var(--accent-soft); }
.thread-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 800;
}
.thread-name { font-weight: 700; font-size: 14px; }

.thread-avatar-wrap { position: relative; }
.online-dot {
  position: absolute;
  inset-inline-start: -1px;
  bottom: 0;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--card);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
}
.thread-main { flex: 1; min-width: 0; }

.thread-menu-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  width: 26px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  flex: none;
}
.thread-menu-btn:hover { background: rgba(0, 0, 0, 0.06); color: var(--fg); }

.thread-menu-pop {
  position: fixed;
  z-index: 60;
  min-width: 170px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  padding: 6px;
  display: flex;
  flex-direction: column;
}
.thread-menu-pop button {
  border: none;
  background: transparent;
  text-align: start;
  padding: 9px 10px;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.thread-menu-pop button:hover { background: var(--accent-soft); }
.thread-menu-pop button.danger { color: var(--danger, #b42318); }

.thread-row.archived { opacity: 0.65; }
.thread-row.archived .thread-name::after {
  content: ' · مؤرشفة';
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
}
.thread-presence {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--muted);
  margin: 1px 0 2px;
}
.thread-presence.online { color: #16a34a; font-weight: 700; }
.presence-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
  opacity: .85;
}
.thread-row.active .online-dot { border-color: var(--accent-soft); }
.thread-last { color: var(--muted); font-size: 12px; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-badge {
  margin-inline-start: auto;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--danger); color: #fff;
  font-size: 11px; display: grid; place-items: center;
}

.direct-chat-card .chat-list { min-height: 320px; max-height: 480px; }

.undo-toast {
  position: fixed;
  left: 50%;
  right: auto;
  bottom: 26px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  background: #1f2937;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
  z-index: 90;
  font-size: 13.5px;
}
.undo-toast button {
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: transparent;
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.undo-toast button:hover { background: rgba(255, 255, 255, 0.12); }

@media (max-width: 900px) {
  .direct-layout { grid-template-columns: 1fr; }
}

.bell-head { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.bell-item.read { opacity: .6; }
.bell-item { cursor: pointer; }
.bell-item:hover { background: var(--accent-soft); }
tr.flash { animation: flash-row 2.5s ease; }
@keyframes flash-row {
  0% { background: var(--accent-soft); }
  100% { background: transparent; }
}

/* ---------- shell: sidebar + content ---------- */
.topbar { justify-content: flex-start; gap: 10px; }

/* The UA rule for [hidden] loses against author display rules (e.g. #appView{display:grid}),
   which used to show the whole dashboard shell behind the login card. */
[hidden] { display: none !important; }

.login-card { max-width: 440px; margin: 7vh auto 0; }
.brand { margin-inline-end: auto; }

#appView {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.tabs {
  flex-direction: column;
  gap: 3px;
  margin: 0;
  padding: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
}

.tab {
  width: 100%;
  text-align: start;
  border: 0;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  color: var(--muted);
  transition: background .15s ease, color .15s ease;
}

.tab:hover { background: var(--tint); color: var(--text); }

.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.content { min-width: 0; }

/* dashboard stage boxes */
.stage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 6px;
  margin: 4px 0 14px;
}

.stage-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  transition: border-color .15s ease, background .15s ease;
}

.stage-box:hover { border-color: var(--accent); background: var(--tint); }

.stage-box .stage-count {
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  color: var(--accent-strong);
  min-width: 16px;
}
.stage-box .stage-name {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stage-box.pending .stage-count { color: var(--warn); }

/* Numbers lead and stay LTR inside an RTL layout. */
.vessel-metrics strong, .stat-value { direction: ltr; unicode-bidi: isolate; }
.stage-box.measure .stage-count { color: var(--accent); }
.stage-box.done .stage-count { color: var(--ok); }
.stage-box.rejected .stage-count { color: var(--danger); }

#directTabBadge { margin-inline-start: 6px; }

/* ---------- truck details modal ---------- */
.truck-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.truck-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.truck-modal-card {
  position: relative;
  width: min(920px, 100%);
  max-height: 88vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.truck-modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.truck-modal-head h2 { margin: 0; font-size: 18px; }
.truck-modal-head .btn { margin-inline-start: auto; }

.truck-modal-body {
  padding: 16px 18px 22px;
  overflow: auto;
}

.detail-section { margin-bottom: 18px; }
.detail-section h3 { margin: 0 0 8px; font-size: 15px; }

.truck-modal-body .table { table-layout: fixed; }
.truck-modal-body .table th,
.truck-modal-body .table td { white-space: normal; word-break: break-word; }
.truck-modal-body .issues { white-space: normal; word-break: break-word; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.detail-row { display: flex; gap: 8px; font-size: 13px; }
.detail-row span:first-child { color: var(--muted); min-width: 92px; }
.detail-row span:last-child { font-weight: 700; }

.note-card {
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 13px;
}

/* Empty stage blocks read as a quiet placeholder, not a big hole. */
.truck-modal-body .detail-section .empty {
  padding: 9px 12px;
  text-align: start;
  background: var(--card-2, var(--bg));
  border: 1px dashed var(--line);
  border-radius: 8px;
  font-size: 13px;
}

.note-card strong { display: block; margin-bottom: 2px; }

.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.attachments img { width: 120px; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }

tr[data-details] { cursor: pointer; }

/* Audit log: every row opens the full record */
#auditRows tr { cursor: pointer; }
#auditRows tr:hover { background: var(--accent-soft, rgba(120, 160, 255, 0.08)); }
.audit-value { direction: ltr; unicode-bidi: plaintext; text-align: start; font-size: 12.5px; word-break: break-word; }

/* ---------- stages table: compact rows, no more broken words ---------- */
#panel-stages .card { overflow-x: auto; }
#panel-stages .table { min-width: 900px; }
#panel-stages .table th,
#panel-stages .table td { padding: 9px 8px; }
#panel-stages .table .badge { font-size: 11px; padding: 3px 8px; }
#panel-stages .row-actions .btn.small { padding: 6px 10px; font-size: 12px; }

.cell-tight { white-space: nowrap; }
.cell-dip { white-space: nowrap; line-height: 1.7; }
.cell-wrap {
  white-space: normal;
  line-height: 1.5;
  max-width: 160px;
  word-break: break-word;
}
.cell-by { max-width: 120px; }
#panel-stages .table th { white-space: nowrap; }
#panel-stages .row-actions { flex-wrap: nowrap; align-items: center; }

/* Keep the action buttons reachable while the wide table scrolls sideways. */
#panel-stages .table td:last-child,
#panel-stages .table th:last-child {
  position: sticky;
  left: 0;
  background: var(--card);
  z-index: 2;
  box-shadow: 6px 0 8px -8px rgba(0, 0, 0, 0.35);
}
#panel-stages .row-actions .btn { white-space: nowrap; }
#panel-stages .table td small { color: var(--muted); font-size: 11px; }

/* On narrow screens the historical "last action" column gives its space to the buttons. */
@media (max-width: 1200px) {
  #panel-stages .table th:nth-child(9),
  #panel-stages .table td:nth-child(9) { display: none; }
}
tr[data-details]:hover { background: var(--accent-soft); }
tr.flash { animation: flash 1.6s ease; }
.wrap { max-width: 1320px; }

@media (max-width: 980px) {
  #appView { grid-template-columns: 1fr; }
  .tabs {
    flex-direction: row;
    flex-wrap: wrap;
    position: static;
    max-height: none;
  }
  .tab { width: auto; }
}


/* A panel inside a card is a section, not another card: no nested boxes. */
.section {
  margin: 20px 0;
  padding: 18px 0 0;
  border-top: 1px solid var(--line);
}
.section h2 { margin: 0; font-size: 17px; }
.section h3 { margin: 18px 0 8px; font-size: 15px; }
.icon { display: block; }
.bell { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
