/* AHL Al-Khaleej Daily Report - navy theme */
:root {
  --navy-950: #041726;
  --navy-900: #061E30;
  --navy-800: #0A2F49;   /* brand navy from logo */
  --navy-700: #123F61;
  --navy-600: #1F5580;
  --navy-500: #2E6A9E;
  --navy-200: #BFD2E4;
  --navy-100: #E3ECF5;
  --navy-50:  #F2F6FA;
  --silver:   #C9D2DB;

  --bg: #EEF2F6;
  --surface: #FFFFFF;
  --text: #14212E;
  --text-2: #3F5062;
  --muted: #6A7A8B;
  --border: #D3DCE6;
  --border-strong: #AEBCCB;

  --ok: #1E7A4C;      --ok-bg: #E4F4EA;
  --warn: #9A6200;    --warn-bg: #FFF3D6;
  --danger: #B42318;  --danger-bg: #FDE8E6;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(6, 30, 48, .06), 0 4px 14px rgba(6, 30, 48, .06);
  --sidebar-w: 248px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 15px; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--navy-600); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--navy-800); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--navy-700); }
.btn-secondary { background: var(--surface); color: var(--navy-800); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--navy-50); border-color: var(--navy-600); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #E9B4AE; }
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); }
.btn-ghost-light { background: transparent; color: #DCE7F2; border-color: rgba(255,255,255,.25); }
.btn-ghost-light:hover { background: rgba(255,255,255,.08); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; color: inherit; }
.icon-btn:hover { background: rgba(10,47,73,.08); }
:focus-visible { outline: 3px solid var(--navy-500); outline-offset: 2px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--text-2); letter-spacing: .01em; }
.field .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
input, select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--border-strong);
  border-radius: 8px; background: #fff;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--navy-600); box-shadow: 0 0 0 3px rgba(46,106,158,.18); }
input[readonly] { background: var(--navy-50); }
.form-error { color: var(--danger); font-size: 13.5px; min-height: 1em; margin: 4px 0 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check input { width: 18px; min-height: 18px; height: 18px; }

/* ---------- Login ---------- */
.login-view {
  min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(1200px 600px at 20% 0%, var(--navy-600), transparent 60%),
              linear-gradient(160deg, var(--navy-800), var(--navy-950));
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px; padding: 32px 28px 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,.35); display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.login-card .field { text-align: left; }
.login-logo { width: 120px; height: 120px; object-fit: contain; margin: 0 auto 2px; }
.login-card h1 { font-size: 20px; color: var(--navy-800); }
.login-sub {margin: -8px 0 6px; color: var(--muted); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; font-size: 12.5px; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100%; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  display: flex; flex-direction: column; background: linear-gradient(180deg, var(--navy-800), var(--navy-900));
  color: #E8EFF6;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand-logo { width: 48px; height: 48px; background: #fff; border-radius: 50%; padding: 2px; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--navy-200); letter-spacing: .06em; text-transform: uppercase; }
.nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px;
  color: #D5E1EC; text-decoration: none; font-weight: 600;
}
.nav a svg { width: 20px; height: 20px; flex: none; opacity: .85; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: #fff; color: var(--navy-800); }
.nav a.active svg { opacity: 1; }
.nav .nav-label { margin: 14px 12px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--navy-200); opacity: .8; }
.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255,255,255,.1); display: flex; flex-direction: column; gap: 10px; }
.side-user { font-size: 13px; }
.side-user strong { display: block; font-size: 14px; color: #fff; }
.side-user span { color: var(--navy-200); }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px;
  height: 60px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.menu-btn, .topbar-logo { display: none; }
.page-title { font-size: 19px; color: var(--navy-800); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-user { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--text-2); }
.role-badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: var(--navy-100); color: var(--navy-800); }
.page { padding: 22px 24px 40px; outline: none; max-width: 1500px; width: 100%; }
.scrim { position: fixed; inset: 0; background: rgba(4,23,38,.5); z-index: 35; }

/* ---------- Cards / layout ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h3 { font-size: 15.5px; color: var(--navy-800); }
.card-head .sub { font-size: 13px; color: var(--muted); }
.card-body { padding: 16px 18px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.toolbar .field { width: 180px; }
.toolbar .grow { flex: 1; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.muted { color: var(--muted); }
.empty { padding: 34px 16px; text-align: center; color: var(--muted); }

/* ---------- Stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-top: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); border-top: 3px solid var(--navy-800); }
.tile-label { font-size: 12.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tile-value { font-size: 28px; font-weight: 700; color: var(--text); margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile-value small { font-size: 15px; color: var(--muted); font-weight: 600; margin-left: 3px; }
.tile-note { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ---------- Bar chart (single series) ---------- */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 190px; padding: 6px 4px 0; border-bottom: 1px solid var(--border-strong); }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; position: relative; cursor: default; }
.bar { width: min(36px, 70%); background: var(--navy-700); border-radius: 4px 4px 0 0; min-height: 2px; transition: background .15s; }
.bar-col:hover .bar, .bar-col:focus .bar { background: var(--navy-500); }
.bar-val { font-size: 12px; color: var(--text-2); margin-bottom: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-labels { display: flex; gap: 10px; padding: 6px 4px 0; }
.bar-labels span { flex: 1; text-align: center; font-size: 12px; color: var(--muted); min-width: 0; }
.bar-tip { position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); background: var(--navy-950); color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 6px; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .12s; z-index: 2; }
.bar-col:hover .bar-tip, .bar-col:focus .bar-tip { opacity: 1; }
/* keep the first/last tooltips inside the chart (no sideways scrolling on phones) */
.bar-col:first-child .bar-tip { left: auto; transform: none; inset-inline-start: 0; }
.bar-col:last-child .bar-tip { left: auto; transform: none; inset-inline-end: 0; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { background: var(--navy-50); color: var(--navy-800); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; white-space: nowrap; }
.table tbody tr:hover td { background: #FAFCFE; }
.table td.r, .table th.r { text-align: right; }
.table td.c, .table th.c { text-align: center; }
.table .row-actions { white-space: nowrap; text-align: right; }
.table .row-actions .btn + .btn { margin-left: 6px; }

/* Report table modelled on the daily report sheet */
.report-table { border: 2px solid var(--navy-800); font-size: 14px; }
.report-table th, .report-table td { border: 1px solid #9FB3C8; padding: 7px 9px; text-align: center; }
.report-table thead th { background: var(--navy-800); color: #fff; font-size: 12px; letter-spacing: .03em; text-transform: uppercase; }
.report-table tr.group td { background: var(--navy-100); color: var(--navy-800); font-weight: 800; letter-spacing: .04em; text-transform: uppercase; font-size: 14.5px; border-top: 2px solid var(--navy-800); }
.report-table tr.subtotal td { background: var(--navy-50); font-weight: 700; }
.report-table tr.grand td { background: var(--navy-800); color: #fff; font-weight: 800; }
.report-table td.op, .report-table td.eq { font-weight: 600; }
.report-table td.rem { text-align: left; max-width: 260px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted { background: #EDF1F5; color: var(--muted); }

/* ---------- Daily entry form ---------- */
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.cell-hint { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.3; }
.cell-hint.warn { color: var(--warn); font-weight: 600; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* Searchable drop-down (Equipment No) */
.combo { position: relative; }
.combo-input { padding-right: 36px; }
.combo-caret { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; color: var(--muted); cursor: pointer; border-radius: 6px; }
.combo-caret:hover { background: var(--navy-50); color: var(--navy-800); }
.combo-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 25; margin: 0; padding: 4px; list-style: none;
  max-height: 264px; overflow-y: auto; background: #fff; border: 1px solid var(--border-strong); border-radius: 8px;
  box-shadow: 0 10px 28px rgba(6,30,48,.16);
}
.combo-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 10px; border-radius: 6px; cursor: pointer; }
.combo-list li small { color: var(--muted); font-size: 12px; white-space: nowrap; }
.combo-list li.active { background: var(--navy-100); }
.combo-list li.selected span { font-weight: 700; color: var(--navy-800); }
.combo-list li.combo-empty { color: var(--muted); cursor: default; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(4,23,38,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { width: 100%; max-width: 620px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 14px; box-shadow: 0 24px 60px rgba(0,0,0,.35); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-head h3 { font-size: 17px; color: var(--navy-800); }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--navy-50); position: sticky; bottom: 0; }

/* ---------- Toast ---------- */
.toast-root { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 36px); }
.toast { background: var(--navy-900); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 600; border-left: 4px solid #7FB3E0; animation: toast-in .2s ease-out; }
.toast.error { border-left-color: #F08A80; }
.toast.ok { border-left-color: #6FCF97; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Tablet / mobile ---------- */
@media (max-width: 1100px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  body { font-size: 15.5px; }
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; box-shadow: none; }
  .sidebar.open { transform: none; box-shadow: 8px 0 30px rgba(0,0,0,.3); }
  .main { margin-left: 0; }
  .topbar { height: 56px; padding: 0 8px 0 4px; gap: 8px; background: var(--navy-800); color: #fff; border-bottom: 0; padding-top: env(safe-area-inset-top); height: calc(56px + env(safe-area-inset-top)); }
  .topbar .icon-btn:hover { background: rgba(255,255,255,.1); }
  .menu-btn { display: inline-flex; }
  .topbar-logo { display: block; width: 34px; height: 34px; background: #fff; border-radius: 50%; padding: 1px; }
  .page-title { color: #fff; font-size: 17px; }
  .top-user .who { display: none; }
  .top-user .role-badge { background: rgba(255,255,255,.15); color: #fff; }
  .page { padding: 14px 12px calc(28px + env(safe-area-inset-bottom)); }
  .card-head, .card-body { padding: 12px 14px; }
  .toolbar .field { width: calc(50% - 6px); }
  .toolbar .actions { width: 100%; }
  .toolbar .actions .btn { flex: 1; }
  .tile-value { font-size: 24px; }

  .form-actions .btn { flex: 1; }

  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-radius: 16px 16px 0 0; max-height: 92vh; }
  .toast-root { left: 12px; right: 12px; bottom: calc(14px + env(safe-area-inset-bottom)); }
}

@media (max-width: 480px) {
  .toolbar .field { width: 100%; }
  .tiles { gap: 10px; }
  .tile { padding: 12px 14px; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- Print (reports) ---------- */
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; font-size: 11px; }
  .sidebar, .topbar, .no-print, .toast-root, .scrim { display: none !important; }
  .main { margin: 0; }
  .page { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; }
  .print-head { display: flex !important; }
  .report-table { font-size: 10.5px; }
  .report-table thead th, .report-table tr.grand td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .report-table tr.group td, .report-table tr.subtotal td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .table-wrap { overflow: visible; }
}
.print-head { display: none; align-items: center; gap: 14px; margin-bottom: 10px; }
.print-head img { width: 60px; height: 60px; }
.print-head h2 { font-size: 18px; color: var(--navy-800); }

/* ---------- Language switch ---------- */
.report-table td.tend { text-align: right; }
.lang-btn {
  min-height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--navy-800); font-weight: 700; cursor: pointer; white-space: nowrap;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}
.lang-btn:hover { background: var(--navy-50); border-color: var(--navy-600); }
.lang-btn-login { align-self: center; border: 0; background: transparent; color: var(--navy-600); text-decoration: underline; }
.lang-btn-login:hover { background: transparent; color: var(--navy-800); }

/* ---------- Arabic: right-to-left layout ---------- */
[dir="rtl"] body { font-family: "Segoe UI", Tahoma, Arial, sans-serif; }
[dir="rtl"] * { letter-spacing: 0 !important; }   /* letter-spacing breaks Arabic joining */
[dir="rtl"] .sidebar { inset: 0 0 0 auto; }
[dir="rtl"] .main { margin-left: 0; margin-right: var(--sidebar-w); }
[dir="rtl"] .login-card .field { text-align: right; }
[dir="rtl"] .table th, [dir="rtl"] .table td { text-align: right; }
[dir="rtl"] .table td.r, [dir="rtl"] .table th.r, [dir="rtl"] .table .row-actions { text-align: left; }
[dir="rtl"] .table .row-actions .btn + .btn { margin-left: 0; margin-right: 6px; }
[dir="rtl"] .report-table td.rem { text-align: right; }
[dir="rtl"] .report-table td.tend { text-align: left; }
[dir="rtl"] .tile-value small { margin-left: 0; margin-right: 3px; }
[dir="rtl"] .combo-input { padding-right: 10px; padding-left: 36px; }
[dir="rtl"] .combo-caret { right: auto; left: 4px; }
[dir="rtl"] .toast-root { right: auto; left: 18px; }
[dir="rtl"] .toast { border-left: 0; border-right: 4px solid #7FB3E0; }
[dir="rtl"] .toast.error { border-right-color: #F08A80; }
[dir="rtl"] .toast.ok { border-right-color: #6FCF97; }
@media (max-width: 900px) {
  [dir="rtl"] .main { margin-right: 0; }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  [dir="rtl"] .sidebar.open { transform: none; box-shadow: -8px 0 30px rgba(0,0,0,.3); }
  [dir="rtl"] .toast-root { left: 12px; right: 12px; }
  .topbar .lang-btn { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.3); padding: 0 10px; }
}

/* ---------- Install-app dialog ---------- */
.install-box { display: flex; align-items: center; gap: 14px; }
.install-icon { width: 64px; height: 64px; border-radius: 14px; border: 1px solid var(--border); flex: none; }
.install-steps { margin: 14px 0 0; padding-inline-start: 22px; line-height: 1.8; color: var(--text-2); }
