/* ============================================================
   PSTAR Simulator Platform — Stylesheet
   Palette: Deep navy, PPA teal, clean whites, maritime feel
   ============================================================ */

:root {
  --navy:       #0F2942;
  --navy-mid:   #173B57;
  --teal:       #1A7A8A;
  --teal-light: #E8F4F6;
  --teal-mid:   #C5E4E9;
  --green:      #1E6B4A;
  --green-light:#E6F4EE;
  --gold:       #C9952A;
  --gold-light: #FBF3E0;
  --red:        #9B2335;
  --red-light:  #FCECEA;
  --orange:     #B54708;
  --orange-light:#FEF3E2;
  --purple:     #5B3FA6;
  --purple-light:#F0ECFB;

  --bg:         #F0F3F7;
  --card:       #FFFFFF;
  --border:     #D1D9E3;
  --border-mid: #B8C4D0;
  --text:       #0F2942;
  --text-mid:   #3D5166;
  --text-muted: #6B7F93;
  --text-light: #98A8B8;

  --sidebar-w:  240px;
  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 1px 4px rgba(15,41,66,.07), 0 2px 12px rgba(15,41,66,.05);
  --shadow-md:  0 4px 20px rgba(15,41,66,.12);
}

/* ============================================================ RESET */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ============================================================ LOGIN */
.login-screen {
  min-height: 100vh;
  background: linear-gradient(145deg, var(--navy) 0%, #1A4A6E 50%, var(--teal) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}
.logo-mark {
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, var(--navy), var(--teal));
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -1px;
  flex-shrink: 0;
}
.login-title { font-size: 22px; font-weight: 900; color: var(--navy); letter-spacing: -.5px; }
.login-subtitle { font-size: 12px; color: var(--text-muted); font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
.login-divider { height: 1px; background: var(--border); margin: 20px 0; }
.login-desc { color: var(--text-mid); font-size: 13px; margin-bottom: 20px; line-height: 1.5; }
.login-error { color: var(--red); background: var(--red-light); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; margin-top: 12px; }
.login-footer { font-size: 12px; color: var(--text-muted); text-align: center; margin-top: 20px; line-height: 1.6; }

/* ============================================================ APP SHELL */
#appShell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ============================================================ SIDEBAR */
.sidebar {
  background: var(--navy);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow: hidden;
}
.sidebar-header {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-mark-sm {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, var(--teal), #2AABB8);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 17px;
  font-weight: 900;
  flex-shrink: 0;
}
.sidebar-title { font-size: 15px; font-weight: 800; color: #fff; }
.sidebar-sub { font-size: 10px; color: rgba(255,255,255,.45); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }
.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.3);
  padding: 14px 8px 5px;
}
.nav-section-label:first-child { padding-top: 4px; }
.nav-btn {
  width: 100%;
  background: transparent;
  border: none;
  text-align: left;
  padding: 9px 10px;
  border-radius: 9px;
  color: rgba(255,255,255,.65);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 1px 0;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: rgba(255,255,255,.08); color: rgba(255,255,255,.9); }
.nav-btn.active { background: rgba(26,122,138,.35); color: #fff; font-weight: 700; }
.nav-btn.active .nav-icon { color: #4CC9D4; }
.nav-icon { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; opacity: .7; }
.nav-btn.active .nav-icon { opacity: 1; }
.sidebar-footer {
  padding: 12px 12px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.user-avatar {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, var(--teal), #2AABB8);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 700; color: #fff; }
.user-role { font-size: 11px; color: rgba(255,255,255,.4); }
.sign-out-btn {
  width: 100%;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
  color: rgba(255,255,255,.6);
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  font-weight: 600;
  transition: background .15s;
}
.sign-out-btn:hover { background: rgba(255,255,255,.12); color: rgba(255,255,255,.85); }

/* ============================================================ MAIN CONTENT */
.main-content {
  overflow-y: auto;
  min-height: 100vh;
}
.page { display: none; padding: 24px; }
.page.active { display: block; }

/* ============================================================ PAGE HEADER */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-header h1 {
  font-size: 22px;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: -.4px;
}
.page-desc { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ============================================================ CARDS */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 14px;
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.table-card { overflow: auto; }

/* ============================================================ KPI GRID */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.kpi-label {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 6px;
}
.kpi-value {
  font-size: 26px;
  font-weight: 900;
  color: var(--navy);
  letter-spacing: -.5px;
  line-height: 1;
}
.kpi-note { font-size: 11px; color: var(--text-muted); margin-top: 5px; }
.kpi-card.highlight { border-left: 3px solid var(--teal); }
.kpi-card.warn { border-left: 3px solid var(--gold); }
.kpi-card.danger { border-left: 3px solid var(--red); }

/* ============================================================ BAR CHARTS */
.bar-row { margin: 10px 0; }
.bar-label-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-mid); margin-bottom: 4px; font-weight: 600; }
.bar-track { height: 10px; background: var(--bg); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; border-radius: 99px; transition: width .4s ease; }
.bar-fill.teal { background: linear-gradient(90deg, var(--teal), #2AABB8); }
.bar-fill.gold { background: linear-gradient(90deg, var(--gold), #E8A920); }
.bar-fill.red { background: linear-gradient(90deg, var(--orange), var(--red)); }

/* ============================================================ TABLES */
.data-table { border-collapse: collapse; width: 100%; font-size: 12px; }
.data-table th {
  background: var(--bg);
  color: var(--text-mid);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-mid);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--teal-light); }
.data-table .id-cell { font-weight: 700; color: var(--navy); font-size: 12px; }
.data-table .sub { font-size: 11px; color: var(--text-muted); }

/* ============================================================ TAGS / BADGES */
.tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
  letter-spacing: .02em;
}
.tag-inquiry    { background: #F1F5F9; color: #475569; }
.tag-hold       { background: var(--gold-light); color: var(--orange); }
.tag-review     { background: var(--red-light); color: var(--red); }
.tag-confirmed  { background: #E8F0FF; color: #2B55C9; }
.tag-contract   { background: var(--purple-light); color: var(--purple); }
.tag-finance    { background: var(--purple-light); color: var(--purple); }
.tag-inprogress { background: var(--teal-mid); color: #0E5A68; }
.tag-completed  { background: var(--green-light); color: var(--green); }
.tag-closed     { background: var(--green-light); color: var(--green); }
.tag-released   { background: #F1F5F9; color: #475569; }
.tag-cancelled  { background: var(--red-light); color: var(--red); }
.tag-exception  { background: var(--red-light); color: var(--red); }
.tag-pilot      { background: #E8F0FF; color: #2B55C9; }
.tag-project    { background: var(--green-light); color: var(--green); }
.tag-external   { background: var(--gold-light); color: var(--orange); }
.tag-maintenance{ background: #F1F5F9; color: #475569; }
.tag-priority-low      { background: #F1F5F9; color: #475569; }
.tag-priority-normal   { background: var(--teal-light); color: var(--teal); }
.tag-priority-high     { background: var(--gold-light); color: var(--orange); }
.tag-priority-critical { background: var(--red-light); color: var(--red); }
.tag-nra-active    { background: var(--teal-mid); color: #0E5A68; }
.tag-nra-scoping   { background: #F1F5F9; color: #475569; }
.tag-nra-completed { background: var(--green-light); color: var(--green); }
.tag-nra-hold      { background: var(--gold-light); color: var(--orange); }

/* ============================================================ FORMS */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 11px; font-weight: 700; color: var(--text-mid); text-transform: uppercase; letter-spacing: .05em; }
.form-input {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 13px;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.form-input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(26,122,138,.12); }
.form-input.inline { max-width: 170px; padding: 6px 9px; font-size: 12px; }
textarea.form-input { resize: vertical; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-group.full-width { grid-column: 1 / -1; }
.filter-select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  font-size: 12px;
  background: #fff;
  color: var(--text);
}

/* ============================================================ BUTTONS */
.btn-primary {
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 700;
  transition: background .15s;
}
.btn-primary:hover { background: var(--teal); }
.btn-secondary {
  background: #fff;
  color: var(--navy);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 700;
  transition: background .15s;
}
.btn-secondary:hover { background: var(--bg); }
.btn-danger {
  background: var(--red-light);
  color: var(--red);
  border: 1px solid #F5C6C6;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 700;
}
.btn-sm { padding: 5px 10px; font-size: 11px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.full-width { width: 100%; }

/* ============================================================ NOTICES */
.notice {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 16px;
}
.notice.info    { background: var(--teal-light); border: 1px solid var(--teal-mid); color: #0E5A68; }
.notice.warning { background: var(--gold-light); border: 1px solid #F0D89A; color: #7A4800; }
.notice.danger  { background: var(--red-light); border: 1px solid #F5C6C6; color: var(--red); }
.notice.success { background: var(--green-light); border: 1px solid #A8D5BE; color: var(--green); }

/* ============================================================ MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,41,66,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  background: var(--card);
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 17px; font-weight: 800; color: var(--navy); }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  padding: 4px 8px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--bg); }
.modal-body { padding: 20px 22px; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
}
.estimate-box {
  background: var(--teal-light);
  border: 1px solid var(--teal-mid);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-top: 14px;
  font-size: 13px;
  color: #0E5A68;
}

/* ============================================================ QR */
.qr-box {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 14px 0;
}
.qr-payload { font-size: 11px; color: var(--text-muted); text-align: center; line-height: 1.5; }

/* ============================================================ GANTT */
.gantt-wrap { overflow-x: auto; }
.gantt-row { display: grid; align-items: center; border-bottom: 1px solid var(--border); }
.gantt-row:last-child { border-bottom: none; }
.gantt-label { padding: 8px 10px; font-size: 12px; font-weight: 600; color: var(--text-mid); }
.gantt-bar-wrap { position: relative; height: 28px; }
.gantt-bar {
  position: absolute;
  height: 18px;
  top: 5px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  padding: 0 7px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
}
.gantt-bar.complete  { background: var(--green); }
.gantt-bar.inprogress{ background: var(--teal); }
.gantt-bar.pending   { background: var(--border-mid); color: var(--text-mid); }
.gantt-bar.blocked   { background: var(--red); }

/* ============================================================ TOAST */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--navy);
  color: #fff;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  z-index: 9999;
  max-width: 340px;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

/* ============================================================ TABS */
.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 0;
}
.tab-btn {
  background: none;
  border: none;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
  cursor: pointer;
}
.tab-btn:hover { color: var(--navy); }
.tab-btn.active { color: var(--teal); border-bottom-color: var(--teal); font-weight: 800; }
.fin-tab { display: none; }
.fin-tab.active { display: block; }

/* ============================================================ MISC */
.muted-note { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.linked-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  background: var(--teal-light);
  color: var(--teal);
  border: 1px solid var(--teal-mid);
  border-radius: 999px;
  padding: 2px 7px;
  font-weight: 700;
}
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13px;
}
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.permission-grid { display: grid; gap: 1px; }
.perm-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.perm-row:last-child { border-bottom: none; }
.perm-label { flex: 1; font-size: 12px; color: var(--text-mid); }
.perm-select { font-size: 11px; padding: 4px 7px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }

/* ============================================================ RESPONSIVE */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col, .three-col { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  #appShell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
@media print {
  .sidebar, .header-actions, .btn-primary, .btn-secondary, .modal-overlay { display: none !important; }
  .main-content { padding: 0; }
  .page { display: block !important; page-break-after: always; }
}
