.plan-page .topbar-inner,
.plan-page main { max-width: 1040px; }

.num-font {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

[hidden] { display: none !important; }

button, input, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }
button:disabled { cursor: default; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Page header */

.plan-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.plan-hero h1 { margin-bottom: 4px; }

.date-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: -8px;
}

.date-field {
  position: relative;
  padding: 4px 8px;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
}

.date-field:hover { background: var(--accent-soft); }

.date-field input {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  cursor: pointer;
}

.date-field input::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

.text-btn {
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.text-btn:hover { background: var(--accent-soft); }

.market {
  display: grid;
  justify-items: end;
  gap: 2px;
  font-size: 14px;
  color: var(--muted);
  text-align: right;
}

.market-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 16px;
}

.market-state i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}

.market-state.open i { background: var(--gain); box-shadow: 0 0 0 4px var(--gain-soft); }
.market-state.pre i,
.market-state.post i { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft); }

.market-clock { font-size: 13px; }

.plan-bar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  min-height: 24px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 14px;
}

#plan-count.over { color: var(--warn); }
.save-state.failed { color: var(--loss); font-weight: 500; }

/* Stock cards */

.stocks { display: grid; gap: 16px; }

.stock {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  overflow: hidden;
}

.stock-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 16px;
}

.ident { min-width: 0; flex: 1; }

.ticker {
  display: block;
  width: 100%;
  max-width: 260px;
  padding: 0;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  font-size: 30px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.01em;
}

.ticker::placeholder { color: var(--muted); font-weight: 500; opacity: 0.7; }
.ticker:hover { border-bottom-color: var(--line); }
.ticker:focus { outline: none; border-bottom-color: var(--accent); }

.name {
  display: block;
  min-height: 22px;
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.name.error { color: var(--loss); }

.quote {
  display: grid;
  justify-items: end;
  gap: 2px;
  text-align: right;
}

.quote-main {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  flex-wrap: wrap;
  column-gap: 10px;
}

.price { font-size: 30px; font-weight: 600; line-height: 1.3; }
.change { font-size: 15px; font-weight: 500; }
.quote-time { color: var(--muted); font-size: 13px; }

.up { color: var(--gain); }
.down { color: var(--loss); }

.status {
  padding: 1px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
}

.status:empty { display: none; }
.status.gain { background: var(--gain-soft); color: var(--gain); }
.status.loss { background: var(--loss-soft); color: var(--loss); }
.status.warn { background: var(--warn-soft); color: var(--warn); }
.status.neutral { background: var(--line); color: var(--ink); }

.stock-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.panel { min-width: 0; padding: 16px 24px 20px; }
.panel + .panel { border-left: 1px solid var(--line); }

.panel h2 {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.panel-label {
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 14px;
}

.field { display: block; }

.field > span:first-child {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  font-weight: 500;
}

.field-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
}

.field input {
  width: 140px;
  min-height: 42px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 17px;
  font-weight: 500;
}

.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.pl { font-size: 15px; font-weight: 600; }

.levels { display: grid; gap: 8px; }
.levels-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.levels-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.level {
  min-width: 0;
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  text-align: center;
  transition: border-color 0.15s ease;
}

.level:not(:disabled):hover { border-color: var(--accent); }

.level span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.level strong {
  display: block;
  font-size: 16px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.level:disabled strong { color: var(--muted); font-weight: 500; }

.level.gain span { color: var(--gain); }
.level.loss span { color: var(--loss); }
.level.gain.reached { background: var(--gain-soft); border-color: var(--gain); }
.level.loss.reached { background: var(--loss-soft); border-color: var(--loss); }

.ladder { padding: 18px 8px 22px; }

.ladder-track {
  position: relative;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right,
    var(--loss) 0%, var(--loss) 14.28%,
    var(--line) 14.28%, var(--line) 35.71%,
    var(--gain) 35.71%, var(--gain) 100%);
}

.ladder-tick {
  position: absolute;
  top: 10px;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.ladder-tick::before {
  content: "";
  position: absolute;
  top: -12px;
  left: 50%;
  width: 1px;
  height: 8px;
  background: var(--muted);
}

.ladder-tick.base { color: var(--ink); font-weight: 500; }

.ladder-marker {
  position: absolute;
  top: 50%;
  z-index: 1;
  width: 14px;
  height: 14px;
  border: 3px solid var(--surface);
  border-radius: 50%;
  background: var(--ink);
  transform: translate(-50%, -50%);
  transition: left 0.4s ease;
}

.ladder-marker.up { background: var(--gain); }
.ladder-marker.down { background: var(--loss); }

.note-field { padding: 14px 24px 0; }

.note {
  display: block;
  width: 100%;
  min-height: 62px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 15px;
  line-height: 1.55;
  resize: none;
  overflow: hidden;
}

.note:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.note::placeholder { color: var(--muted); }

.stock-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 24px 18px;
}

.action {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
}

.action:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.action.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--surface);
}

.action.primary:hover:not(:disabled) { color: var(--surface); opacity: 0.9; }
.action:disabled,
.action.disabled { opacity: 0.45; pointer-events: none; }

.action.danger { margin-left: auto; color: var(--muted); }
.action.danger:hover { border-color: var(--loss); color: var(--loss); }
.action.danger.armed { border-color: var(--loss); background: var(--loss-soft); color: var(--loss); }

.add-stock {
  width: 100%;
  min-height: 56px;
  margin-top: 16px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: transparent;
  color: var(--accent);
  font-weight: 500;
}

.add-stock:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.add-stock:disabled { opacity: 0.5; }

.source-note {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 13px;
}

/* Live chart */

.live-panel {
  position: relative;
  height: 480px;
  border-top: 1px solid var(--line);
}

.live-panel::before {
  content: "กำลังโหลดกราฟ…";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.tradingview-widget-container,
.tradingview-widget-container__widget { position: relative; width: 100%; height: 100%; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 10;
  padding: 8px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--surface);
  font-size: 14px;
  transform: translateX(-50%);
}

@media (max-width: 760px) {
  .plan-hero { flex-direction: column; align-items: stretch; gap: 14px; }
  .market { justify-items: start; text-align: left; }
  .stock-head { padding: 16px 16px 12px; }
  .ticker { font-size: 25px; }
  .price { font-size: 24px; }
  .quote-time { max-width: 150px; }
  .stock-grid { grid-template-columns: minmax(0, 1fr); }
  .panel { padding: 14px 16px 16px; }
  .panel + .panel { border-left: 0; border-top: 1px solid var(--line); }
  .note-field { padding: 14px 16px 0; }
  .stock-actions { padding: 12px 16px 16px; }
  .live-panel { height: 380px; }
  .levels { gap: 6px; }
  .level { padding: 8px 2px; }
  .level strong { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
