/* Laluan Pelayaran — gaya. Sasaran: kontras tinggi, butang besar, mudah dibaca di bawah cahaya matahari. */
:root {
  --bg: #ffffff; --bg2: #eef2f6; --ink: #07121d; --ink2: #33475a; --garis: #9aa9b8;
  --utama: #0b2a4a; --utamaInk: #ffffff; --aksen: #c2007a;
  --amaran: #ffd400; --amaranInk: #111111; --bahaya: #b3001b; --bahayaInk: #ffffff; --baik: #0a6b2d;
  --jejari: 10px;
  font-size: 17px;
}
html.malam {
  --bg: #0b0b0c; --bg2: #18181b; --ink: #ffb9a6; --ink2: #c98572; --garis: #5a3a33;
  --utama: #3a1410; --utamaInk: #ffb9a6; --aksen: #ff6d5a;
  --amaran: #5a4a00; --amaranInk: #ffe680; --bahaya: #6b0010; --bahayaInk: #ffc9c9; --baik: #7fd69a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overscroll-behavior: none; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; line-height: 1.35; -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }
.nombor { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

#app { display: grid; grid-template-rows: minmax(0, 1fr) auto; height: 100vh; height: 100dvh; }
#petaWrap { position: relative; min-height: 0; background: #aad3df; overflow: hidden; }
#peta { position: absolute; inset: 0; }
html.malam #peta .maplibregl-canvas { filter: brightness(.5) contrast(1.15) saturate(.7); }
#petaGagal { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; background: var(--bg2); font-weight: 700; }

/* panel */
#panel { display: flex; flex-direction: column; min-height: 0; max-height: 54vh; max-height: 54dvh; background: var(--bg); border-top: 3px solid var(--utama); padding-bottom: env(safe-area-inset-bottom); }
#panel.lipat #isi, #panel.lipat #peringatan { display: none; }
#peringatan { margin: 0; padding: 5px 12px; font-size: .78rem; background: var(--bg2); color: var(--ink); border-bottom: 1px solid var(--garis); }
#tab { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--utama); flex: none; }
#tab button { min-height: 50px; border: 0; background: transparent; color: var(--utamaInk); font-weight: 700; font-size: 1rem; border-bottom: 5px solid transparent; opacity: .8; }
#tab button[aria-selected="true"] { opacity: 1; border-bottom-color: var(--amaran); background: rgba(255,255,255,.12); }
#isi { overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0; flex: 1; }
.pane { padding: 12px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }

@media (min-width: 900px) {
  #app { grid-template-rows: none; grid-template-columns: 430px minmax(0, 1fr); }
  #panel { grid-column: 1; grid-row: 1; max-height: none; border-top: 0; border-right: 3px solid var(--utama); }
  #petaWrap { grid-column: 2; grid-row: 1; }
  #panel.lipat #isi, #panel.lipat #peringatan { display: block; }
}
@media (max-width: 899px) and (orientation: landscape) {
  #app { grid-template-rows: none; grid-template-columns: minmax(300px, 44vw) minmax(0, 1fr); }
  #panel { grid-column: 1; grid-row: 1; max-height: none; border-top: 0; border-right: 3px solid var(--utama); padding-left: env(safe-area-inset-left); }
  #petaWrap { grid-column: 2; grid-row: 1; }
  #panel.lipat #isi, #panel.lipat #peringatan { display: block; }
}

/* cip status atas peta */
#chips { position: absolute; top: max(8px, env(safe-area-inset-top)); left: 8px; right: 68px; display: flex; flex-direction: column; align-items: flex-start; gap: 5px; pointer-events: none; z-index: 5; }
.chip { pointer-events: auto; max-width: 100%; padding: 5px 10px; border-radius: 8px; font-size: .8rem; font-weight: 700; background: rgba(255,255,255,.94); color: #07121d; border: 2px solid #07121d; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.chip.amaran { background: var(--amaran); color: var(--amaranInk); border-color: #111; }
.chip.bahaya { background: var(--bahaya); color: var(--bahayaInk); border-color: #fff; }
.chip.baik { background: #e6f6ea; color: #063d1a; border-color: #0a6b2d; }
.chip.tiga { background: #111; color: #fff; border-color: #fff; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.chip.tiga button { min-height: 40px; padding: 4px 12px; border-radius: 8px; border: 2px solid #111; background: var(--amaran); color: #111; font-weight: 800; }
html.malam .chip { background: rgba(20,20,22,.94); color: #ffb9a6; border-color: #7a4a40; }
html.malam .chip.amaran { background: #4a3d00; color: #ffe680; }
html.malam .chip.bahaya { background: #6b0010; color: #ffc9c9; }
html.malam .chip.baik { background: #0f2a17; color: #9be0b0; border-color: #2f7a48; }

/* butang peta */
#kawal { position: absolute; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); display: flex; flex-direction: column; gap: 8px; z-index: 6; }
#kawal button { width: 52px; height: 52px; border-radius: 12px; border: 2px solid #07121d; background: #fff; color: #07121d; font-size: 1.35rem; font-weight: 800; box-shadow: 0 1px 5px rgba(0,0,0,.4); padding: 0; }
#kawal button[aria-pressed="true"] { background: #0b2a4a; color: #fff; border-color: #fff; }
#btnMod { font-size: 1.05rem !important; }
html.malam #kawal button { background: #1a1a1d; color: #ffb9a6; border-color: #7a4a40; }
html.malam #kawal button[aria-pressed="true"] { background: #5a1d15; color: #ffd9cf; }

#silang { position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; margin: -13px 0 0 -13px; pointer-events: none; z-index: 3;
  background: linear-gradient(#000, #000) center/2px 100% no-repeat, linear-gradient(#000, #000) center/100% 2px no-repeat; opacity: .75; }
#tengah { position: absolute; left: 8px; bottom: 34px; z-index: 4; padding: 3px 8px; border-radius: 6px; background: rgba(255,255,255,.92); color: #07121d; border: 1px solid #07121d; font-size: .78rem; font-weight: 700; font-variant-numeric: tabular-nums; pointer-events: none; }
html.malam #tengah { background: rgba(20,20,22,.92); color: #ffb9a6; border-color: #7a4a40; }

#gratLabel { position: absolute; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
#gratLabel span { position: absolute; font-size: .68rem; font-weight: 700; color: #07121d; background: rgba(255,255,255,.8); padding: 0 3px; border-radius: 3px; white-space: nowrap; font-variant-numeric: tabular-nums; }
#gratLabel span.la { right: 2px; transform: translateY(-50%); }
#gratLabel span.lo { bottom: 60px; transform: translateX(-50%); }

/* penanda waypoint */
.wpm { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; color: #fff; font-weight: 800; font-size: .85rem; display: grid; place-items: center; box-shadow: 0 0 0 2px #07121d, 0 2px 5px rgba(0,0,0,.5); cursor: pointer; position: relative; font-variant-numeric: tabular-nums; }
.wpm.pudar { width: 20px; height: 20px; font-size: 0; border-width: 2px; opacity: .85; }
.wpm.semak { border-color: var(--amaran); box-shadow: 0 0 0 2px #07121d, 0 0 0 5px #ffd400; }
.wpm.sasaran { box-shadow: 0 0 0 2px #07121d, 0 0 0 6px #fff, 0 0 0 9px #07121d; }
.wpm.dipilih { outline: 4px solid #00e0ff; outline-offset: 3px; }
.wpm .lab { position: absolute; left: 34px; top: 50%; transform: translateY(-50%); white-space: nowrap; font-size: .76rem; font-weight: 700; color: #07121d; background: rgba(255,255,255,.9); border: 1px solid #07121d; border-radius: 4px; padding: 0 5px; pointer-events: none; }
.zkecil .wpm .lab, .wpm.pudar .lab { display: none; }
.wpm.titik { border-radius: 4px; transform: rotate(45deg); width: 22px; height: 22px; background: #fff !important; border: 3px solid #07121d; box-shadow: 0 2px 5px rgba(0,0,0,.5); }
.wpm.titik .lab { transform: rotate(-45deg) translate(6px, -14px); transform-origin: left center; left: 26px; }
.botm { width: 34px; height: 34px; pointer-events: none; }
.botm svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 1px 3px rgba(0,0,0,.6)); }
.botm.lapuk { opacity: .45; }

/* kad waypoint dipilih */
#kadPilih { position: absolute; left: 8px; right: 8px; bottom: 62px; z-index: 7; max-width: 560px; margin: 0 auto; background: var(--bg); color: var(--ink); border: 3px solid var(--ink); border-radius: var(--jejari); padding: 10px 12px; box-shadow: 0 4px 16px rgba(0,0,0,.45); max-height: 70%; overflow: auto; }
#kadPilih h3 { margin: 0 40px 4px 0; font-size: 1.05rem; }
#kadPilih .tutup { position: absolute; top: 4px; right: 4px; width: 44px; height: 44px; border: 0; background: transparent; font-size: 1.5rem; font-weight: 800; }
#kadPilih .koord { font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
#kadPilih .kecil, .kecil { font-size: .82rem; color: var(--ink2); }
.baris { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* butang am */
.btn { min-height: 48px; padding: 8px 14px; border-radius: var(--jejari); border: 2px solid var(--ink); background: var(--bg); color: var(--ink); font-weight: 700; }
.btn.utama { background: var(--utama); color: var(--utamaInk); border-color: var(--utama); }
.btn.bahaya { background: var(--bahaya); color: var(--bahayaInk); border-color: var(--bahaya); }
.btn.penuh { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, #tab button:focus-visible, #kawal button:focus-visible, .wpbaris:focus-visible { outline: 4px solid #00a3c4; outline-offset: 2px; }

/* jubin navigasi */
h2.seksyen { font-size: .82rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ink2); margin: 14px 0 6px; }
h2.seksyen:first-child { margin-top: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.jubin { border: 2px solid var(--ink); border-radius: var(--jejari); padding: 6px 10px; background: var(--bg); min-width: 0; }
.jubin.lebar { grid-column: 1 / -1; }
.jubin .l { font-size: .74rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink2); }
.jubin .v { font-size: 1.75rem; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.jubin .v.sederhana { font-size: 1.3rem; }
.jubin .v small { font-size: .55em; font-weight: 700; }
.jubin .s { font-size: .78rem; color: var(--ink2); }
.jubin.tiada .v { color: var(--ink2); }
.status { border-radius: var(--jejari); padding: 8px 10px; font-weight: 700; border: 2px solid var(--ink); margin-bottom: 8px; }
.status.bahaya { background: var(--bahaya); color: var(--bahayaInk); border-color: var(--bahaya); }
.status.baik { background: var(--bg); color: var(--baik); border-color: var(--baik); }
.status.amaran { background: var(--amaran); color: var(--amaranInk); border-color: var(--amaranInk); }
.sasar { display: grid; grid-template-columns: 56px 1fr 56px; gap: 8px; align-items: stretch; }
.sasar button { min-height: 56px; font-size: 1.4rem; border-radius: var(--jejari); border: 2px solid var(--ink); background: var(--utama); color: var(--utamaInk); font-weight: 800; }
.sasar .nama { border: 2px solid var(--ink); border-radius: var(--jejari); padding: 4px 10px; display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.sasar .nama b { font-size: 1.1rem; overflow-wrap: anywhere; }

/* senarai laluan & waypoint */
.kad { border: 2px solid var(--ink); border-radius: var(--jejari); padding: 8px 10px; margin-bottom: 8px; background: var(--bg); }
.kad.aktif { border-width: 4px; }
.kad .tajuk { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.kad .warna { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--ink); flex: none; }
.kad .tajuk span:not(.warna) { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.nota { margin: 6px 0; padding: 6px 10px; background: var(--bg2); border-left: 5px solid var(--garis); border-radius: 4px; font-size: .86rem; white-space: pre-wrap; }
.wpbaris { display: grid; grid-template-columns: 34px 1fr; gap: 8px; width: 100%; text-align: left; padding: 8px 6px; border: 0; border-top: 1px solid var(--garis); background: transparent; }
.wpbaris .no { width: 30px; height: 30px; border-radius: 50%; color: #fff; font-weight: 800; display: grid; place-items: center; font-size: .85rem; border: 2px solid var(--ink); }
.wpbaris .nm { font-weight: 800; }
.wpbaris .kd { font-variant-numeric: tabular-nums; font-size: .9rem; }
.wpbaris.sasaran { background: var(--bg2); }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; font-size: .72rem; font-weight: 800; border: 1px solid currentColor; margin-left: 4px; vertical-align: middle; }
.tag.amaran { background: var(--amaran); color: var(--amaranInk); }
.tag.bahaya { background: var(--bahaya); color: var(--bahayaInk); }
.kaki { margin: 0 0 0 42px; padding: 4px 8px 6px; font-size: .84rem; border-left: 3px dashed var(--garis); }
.kaki b { font-variant-numeric: tabular-nums; }
.kaki .beza { color: var(--bahaya); font-weight: 800; }
html.malam .kaki .beza { color: #ff8a8a; }
label.pilih { display: flex; align-items: center; gap: 10px; min-height: 48px; font-weight: 700; }
label.pilih input { width: 26px; height: 26px; flex: none; }
select, input[type="text"] { min-height: 48px; padding: 6px 10px; border: 2px solid var(--ink); border-radius: var(--jejari); background: var(--bg); width: 100%; font-size: 1rem; }
ul.rapi { margin: 6px 0; padding-left: 20px; } ul.rapi li { margin: 3px 0; }
p { margin: 6px 0; }

/* dialog & toast */
dialog { border: 3px solid var(--ink); border-radius: 14px; padding: 16px; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); overflow: auto; background: var(--bg); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 8px; font-size: 1.15rem; }
#dlgButang { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 14px; }
#toast { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; max-width: calc(100vw - 24px); background: #07121d; color: #fff; border: 2px solid #fff; padding: 10px 14px; border-radius: 10px; font-weight: 700; opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.tunjuk { opacity: 1; pointer-events: auto; }
#toast button { margin-left: 10px; min-height: 40px; padding: 4px 12px; border-radius: 8px; border: 2px solid #fff; background: var(--amaran); color: #111; font-weight: 800; }
table.pratonton { width: 100%; border-collapse: collapse; font-size: .84rem; margin: 6px 0; }
table.pratonton td, table.pratonton th { border: 1px solid var(--garis); padding: 3px 6px; text-align: left; vertical-align: top; }

.maplibregl-ctrl-attrib { font-size: 11px !important; }
.maplibregl-ctrl-scale { font-size: 12px; font-weight: 700; border-width: 2px; border-color: #07121d; color: #07121d; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* pautan & kawalan ikut tema (mod malam: elak biru/putih terang) */
a { color: inherit; text-decoration: underline; }
html.malam input[type="checkbox"] { accent-color: #b0483a; }
html.malam #toast { background: #1a1a1d; color: #ffb9a6; border-color: #7a4a40; }
html.malam #toast button { background: #4a3d00; color: #ffe680; border-color: #7a4a40; }
html.malam .maplibregl-ctrl-attrib, html.malam .maplibregl-ctrl-scale { filter: brightness(.55); }
