*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy: #1F3A5F;
  --sky: #5499C7;
  --bg: #eef3f7;
  --card: #fff;
  --muted: #6b7c8d;
  --border: #dde4ea;
}

body {
  font-family: 'PingFang TC', 'Microsoft JhengHei', system-ui, sans-serif;
  color: #1a2a3a;
  background: var(--bg);
  min-height: 100vh;
}

/* — login — */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  background: linear-gradient(145deg, #e8f4fb 0%, #eef3f7 50%, #dce9f3 100%);
}

.login-card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,.1);
  padding: 2rem 2.2rem;
  width: min(100%, 360px);
}

.login-card h1 { font-size: 1.6rem; margin-bottom: .25rem; }
.login-card .sub { color: var(--muted); font-size: .95rem; margin-bottom: 1.5rem; }
.login-card label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .35rem; }
.login-card input {
  width: 100%; padding: .65rem .75rem; border: 1px solid #cfd8dc;
  border-radius: 8px; font-size: 1rem; margin-bottom: 1rem;
}
.login-card button[type=submit] {
  width: 100%; padding: .7rem; background: var(--navy); color: #fff;
  border: none; border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.login-card button[type=submit]:hover { filter: brightness(1.08); }
.error { color: #c0392b; font-size: .9rem; margin-bottom: .75rem; }

/* — app shell — */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .75rem 1.25rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; color: var(--navy); text-decoration: none; font-size: 1.05rem; }

.btn-ghost {
  background: none; border: 1px solid #cfd8dc; border-radius: 6px;
  padding: .35rem .75rem; cursor: pointer; font-size: .85rem; color: #566573;
}

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: calc(100vh - 49px);
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; }
  .sidebar { max-height: none; border-right: none; border-bottom: 1px solid var(--border); }
  .detail-wrap { min-height: 60vh; }
}

.sidebar {
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .85rem;
}

/* — stats hero — */
.stats-hero {
  background: linear-gradient(135deg, var(--navy) 0%, #2c5282 100%);
  color: #fff;
  border-radius: 14px;
  padding: 1rem 1.1rem;
}

.hero-label { font-size: .78rem; opacity: .85; margin-bottom: .15rem; }
.hero-value { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.hero-value span { font-size: 1rem; font-weight: 600; opacity: .9; }
.hero-stats {
  display: flex; flex-wrap: wrap; gap: .5rem 1rem;
  margin-top: .5rem; font-size: .78rem; opacity: .88;
}

/* — charts — */
.chart-card {
  background: #f8fafb;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .85rem;
}

.chart-card h3, .list-section h3 {
  font-size: .82rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .65rem;
}

.donut-wrap {
  position: relative;
  width: 140px;
  margin: 0 auto .5rem;
}

#donut-chart { width: 100%; height: auto; display: block; }

.donut-seg {
  cursor: pointer;
  transition: opacity .15s, transform .15s;
  transform-origin: 60px 60px;
}
.donut-seg:hover, .donut-seg.active { opacity: 1; filter: brightness(1.05); }
.donut-seg:not(.active) { opacity: .88; }

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-size: .72rem;
  color: var(--muted);
}
.donut-center strong { font-size: 1.15rem; color: var(--navy); line-height: 1; }

.legend { list-style: none; display: flex; flex-direction: column; gap: .25rem; }

.legend-btn {
  display: flex;
  align-items: center;
  gap: .4rem;
  width: 100%;
  padding: .35rem .45rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: .78rem;
  cursor: pointer;
  text-align: left;
  color: #2c3e50;
  transition: background .12s;
}
.legend-btn:hover, .legend-btn.active { background: #e8f0f8; }
.legend-btn .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.legend-amt { margin-left: auto; font-weight: 600; color: var(--navy); }

/* — unified ship list (compact) — */
.ships-unified { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.ship-list { list-style: none; display: flex; flex-direction: column; gap: .4rem; overflow-y: auto; flex: 1; min-height: 0; }

.ship-item {
  width: 100%;
  text-align: left;
  background: #f8fafb;
  border: 1px solid #e0e6eb;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .12s;
  font: inherit;
}
.ship-item:hover { border-color: var(--sky); background: #eef6fc; }
.ship-item.active { border-color: var(--navy); background: #e8f0f8; }

.ship-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.ship-info { flex: 1; min-width: 0; }
.ship-name { display: block; font-weight: 600; font-size: .88rem; line-height: 1.25; }
.ship-meta { display: block; font-size: .72rem; color: var(--muted); margin-top: .1rem; }
.ship-icon { font-size: 1.1rem; flex-shrink: 0; }
.ship-amt { font-size: .78rem; font-weight: 700; color: var(--navy); white-space: nowrap; }

.bar-track {
  height: 8px;
  background: #e0e6eb;
  border-radius: 999px;
  overflow: hidden;
  display: block;
}
.bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width .35s ease;
}

.ship-compact {
  display: grid;
  grid-template-columns: 8px 1fr 52px 36px 1.1rem;
  align-items: center;
  gap: .4rem;
  padding: .5rem .55rem;
}
.ship-compact-main { min-width: 0; }
.ship-compact .ship-name { font-size: .78rem; }
.ship-compact .ship-meta { font-size: .68rem; margin-top: 0; }
.bar-track--inline { height: 6px; min-width: 0; }
.ship-compact .ship-amt { font-size: .68rem; text-align: right; }

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
}

.filter-clear {
  font-size: .72rem;
  padding: .2rem .5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  color: var(--sky);
}

/* — detail panel (full bleed right) — */
.detail-wrap {
  position: relative;
  display: grid;
  grid-template: 1fr / 1fr;
  overflow: hidden;
  background: #e8eef3;
  min-height: 0;
}

.detail-empty,
.detail-panel {
  grid-area: 1 / 1;
  min-height: 0;
}

.detail-empty[hidden],
.detail-panel[hidden] {
  display: none !important;
}

.detail-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #95a5a6;
}

.empty-inner { text-align: center; }
.empty-icon { font-size: 3rem; opacity: .35; display: block; margin-bottom: .75rem; }

.detail-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background: var(--card);
  animation: fadeUp .3s ease;
  overflow-y: auto;
}

.detail-hero {
  position: relative;
  min-height: min(32vh, 260px);
  flex-shrink: 0;
  --hero-accent: var(--sky);
}

.detail-scene {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.scene {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.scene-icon { font-size: clamp(4rem, 12vw, 7rem); filter: drop-shadow(0 8px 24px rgba(0,0,0,.12)); z-index: 2; }
.scene-sun { position: absolute; top: 12%; right: 12%; font-size: clamp(2rem, 5vw, 3.5rem); }
.scene-wave {
  position: absolute;
  bottom: 0; left: 0; right: 0; height: 35%;
  background: linear-gradient(180deg, transparent, rgba(84,153,199,.35));
}
.scene.building { background: linear-gradient(135deg, #ecf0f1 0%, #d5dbdb 50%, #e8ecef 100%); }
.scene.sailing { background: linear-gradient(135deg, #d6eaf8 0%, #aed6f1 60%, #85c1e9 100%); }
.scene.sailing.loan { background: linear-gradient(135deg, #d5f5e3 0%, #abebc6 50%, #a9dfbf 100%); }
.scene.sailing.div { background: linear-gradient(135deg, #d5f5e3 0%, #aed6f1 50%, #85c1e9 100%); }
.scene.sold .scene-icon { opacity: .45; }
.scene.default { background: linear-gradient(135deg, #d6eaf8 0%, #aed6f1 100%); }

.hero-overlay {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.75rem 2rem;
  background: linear-gradient(180deg, transparent 0%, rgba(255,255,255,.92) 55%, #fff 100%);
}

.hero-eyebrow {
  font-size: .85rem;
  font-weight: 600;
  color: var(--hero-accent, var(--muted));
  margin-bottom: .25rem;
  letter-spacing: .02em;
}

.hero-text h2 {
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  font-weight: 800;
  color: var(--navy);
  line-height: 1.15;
  word-break: break-word;
}

.status-pill {
  display: inline-block;
  padding: .45rem 1rem;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid transparent;
  flex-shrink: 0;
}

.detail-body {
  flex: 1;
  padding: 1.5rem 2rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: linear-gradient(145deg, #f8fafb 0%, #fff 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.15rem;
  border-top: 3px solid var(--accent, var(--navy));
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(31,58,95,.08); }
.stat-card.warn { border-top-color: #E67E22; background: linear-gradient(145deg, #fef9f0 0%, #fff 100%); }

.stat-label {
  display: block;
  font-size: .72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .35rem;
}

.stat-value {
  display: block;
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--navy);
  line-height: 1.1;
}
.stat-value small { font-size: .9rem; font-weight: 600; margin-left: .15rem; color: var(--muted); }
.stat-sub { display: block; font-size: .72rem; color: var(--muted); margin-top: .35rem; }

.detail-columns {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 1.25rem;
  flex: 1;
  min-height: 0;
}

@media (max-width: 1100px) {
  .detail-columns { grid-template-columns: 1fr; }
  .hero-overlay { padding: 1.25rem 1.5rem; }
  .detail-body { padding: 1.25rem 1.5rem 1.5rem; }
}

.panel-card {
  background: #fafcfd;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
}

.panel-card h3, .panel-head h3 {
  font-size: .78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 1rem;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .75rem;
}
.panel-head h3 { margin-bottom: 0; }

.flow-header { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.25rem; }

.flow-tag {
  display: inline-block;
  padding: .3rem .7rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 700;
}
.flow-tag.warn { background: #fdebd0; color: #9a6700; }

.flow-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 1.5rem 1rem;
  flex: 1;
}

.flow-node {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--flow-color, var(--navy));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.06);
  flex-shrink: 0;
}
.flow-node.mid { font-size: 2rem; background: color-mix(in srgb, var(--flow-color, var(--navy)) 8%, #fff); }

.flow-line {
  flex: 1;
  max-width: 80px;
  height: 3px;
  background: linear-gradient(90deg, var(--flow-color, var(--navy)), color-mix(in srgb, var(--flow-color) 40%, #fff));
  border-radius: 999px;
  position: relative;
}
.flow-line::after {
  content: '›';
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-55%);
  color: var(--flow-color, var(--navy));
  font-size: 1.2rem;
  font-weight: 800;
}

.flow-bullets {
  list-style: none;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}
.flow-bullets li {
  font-size: .88rem;
  line-height: 1.55;
  color: #7d6608;
  padding: .35rem 0 .35rem 1.1rem;
  position: relative;
}
.flow-bullets li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: #E67E22;
  font-weight: 800;
}

.info-panel .detail-note {
  font-size: .95rem;
  line-height: 1.75;
  color: #2c3e50;
  margin-bottom: 1rem;
  flex: 1;
}

.detail-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .4rem 1rem;
  font-size: .85rem;
  padding-top: .75rem;
  border-top: 1px solid var(--border);
}
.detail-meta dt { color: var(--muted); }
.detail-meta dd { font-weight: 600; font-family: ui-monospace, monospace; }

.dividends-panel { flex-shrink: 0; }

.div-badge {
  font-size: .72rem;
  font-weight: 700;
  padding: .25rem .6rem;
  border-radius: 999px;
  background: #d5f5e3;
  color: #1e8449;
}

.dividends-hint {
  font-size: .78rem;
  color: var(--muted);
  margin: -.35rem 0 .75rem;
}

.div-table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid #d5f0e0; }

.div-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}
.div-table th, .div-table td { padding: .55rem .85rem; text-align: left; }
.div-table thead { background: #27AE60; color: #fff; }
.div-table tbody tr:nth-child(even) { background: #f2fbf5; }
.div-table td:nth-child(2) { font-weight: 700; color: #27AE60; white-space: nowrap; }
.div-table tfoot { background: #e8f8ef; font-weight: 700; }

.panel-actions { display: flex; gap: .65rem; flex-wrap: wrap; padding-top: .25rem; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.btn {
  display: inline-block;
  padding: .45rem .8rem;
  background: var(--navy);
  color: #fff;
  text-decoration: none;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 600;
}
.btn:hover { filter: brightness(1.08); }
.btn.btn-ghost { background: #fff; color: var(--navy); border: 1px solid var(--navy); }
