:root {
  --bg: #f2f3f5;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --border: #d5d9e0;
  --border-soft: #e4e7ec;
  --text: #14181f;
  --text-dim: #4d5561;
  --text-faint: #838b99;

  --amber: #a06a0a;
  --amber-soft: #fbf0d9;
  --amber-border: #e3bd75;

  --teal: #0e8a73;
  --teal-soft: #e0f4f0;
  --teal-border: #8ed4c5;

  --green: #1a9a52;
  --red: #cf3a3a;
  --orange: #c06a0a;
  --yellow: #93820a;

  --red-soft: #fbe3e3;
  --red-border: #eaa8a8;
  --orange-soft: #fbebd9;
  --orange-border: #e3b875;
  --green-soft: #e0f5e8;
  --green-border: #8ed9ac;
  --yellow-soft: #f7f2d9;
  --yellow-border: #d9c875;

  --radius: 10px;
  --radius-sm: 6px;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard", "Malgun Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: 88px;
  min-height: 100vh;
}

.mono, .summary-value, .criteria-value, .data-table td,
input[type="number"] {
  font-family: "SFMono-Regular", "Consolas", "Menlo", "Roboto Mono", monospace;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.app-header h1 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  justify-self: center;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  justify-self: start;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  justify-self: end;
}

.icon-btn {
  min-width: 40px;
  min-height: 40px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  /* <a class="icon-btn">(보고서 링크)도 <button>과 똑같이 보이게 */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.icon-btn:active {
  background: var(--bg);
  color: var(--text);
}

.icon-btn[hidden] {
  display: none;
}

/* Layout */
#main-content {
  max-width: 520px;
  margin: 0 auto;
  padding: 12px;
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin: 0 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Fields */
.field-group {
  margin-bottom: 14px;
}

.field-group:last-child {
  margin-bottom: 0;
}

.field-group label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

input[type="number"], input[type="text"], input[type="date"] {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
}

input:focus {
  outline: none;
  border-color: var(--amber);
}

.toggle-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-dim);
  min-height: 44px;
}

.toggle-inline input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--amber);
}

.inline-field {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.inline-field .field-group {
  flex: 1;
  margin-bottom: 0;
}

.inline-result {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}

/* Buttons */
.btn {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn:active {
  filter: brightness(1.15);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
  display: block;
}

.btn-primary {
  background: var(--amber);
  border-color: var(--amber);
  color: #1a1206;
}

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--text);
}

.btn-buy {
  background: var(--amber-soft);
  border-color: var(--amber-border);
  color: var(--amber);
}

.btn-sell {
  background: var(--teal-soft);
  border-color: var(--teal-border);
  color: var(--teal);
}

.btn-danger {
  background: transparent;
  border-color: var(--red-border);
  color: var(--red);
}

.link-btn {
  background: none;
  border: none;
  color: var(--amber);
  font-size: 13px;
  padding: 10px 0;
  cursor: pointer;
  min-height: 44px;
}

/* ---------- View: List ---------- */

.list-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.list-toolbar .btn {
  flex: 1;
}

.list-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin: 20px 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.total-summary-block {
  margin-bottom: 12px;
}

.total-summary-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text-dim);
  font-size: 13px;
  min-height: 44px;
  cursor: pointer;
  margin-bottom: 6px;
}

.total-lines {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
}

.total-line {
  white-space: nowrap;
}

.total-eval-line {
  color: var(--text-faint);
  font-size: 12.5px;
}

.total-highlight-line {
  font-weight: 700;
  color: var(--text);
  margin-top: 2px;
}

.currency-switch {
  display: flex;
  gap: 6px;
}

.currency-pill {
  flex: 1;
  min-height: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.currency-pill.active {
  background: var(--amber-soft);
  border-color: var(--amber-border);
  color: var(--amber);
}

.total-missing-note {
  font-size: 11.5px;
  color: var(--orange);
  margin: 6px 2px 0;
}

.total-missing-note[hidden] {
  display: none;
}

.chevron {
  color: var(--text-faint);
  transition: transform 0.15s ease;
}

.chevron.open {
  transform: rotate(180deg);
}

.total-summary-detail {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 12px;
}

.total-summary-detail[hidden] {
  display: none;
}

.total-detail-item {
  padding: 6px 0;
  border-bottom: 1px solid var(--border-soft);
}

.total-detail-item:last-child {
  border-bottom: none;
}

.total-detail-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-dim);
}

.total-detail-eval-row {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 2px;
}

.fx-settings {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
}

.fx-status {
  font-size: 12px;
  color: var(--text-faint);
  margin: 0 0 10px;
}

.fx-rate-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.fx-rate-row span {
  flex-shrink: 0;
}

.fx-rate-input {
  flex: 1;
  min-height: 40px;
  padding: 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: "SFMono-Regular", "Consolas", "Menlo", "Roboto Mono", monospace;
  font-size: 14px;
}

.fx-rate-input:focus {
  outline: none;
  border-color: var(--amber);
}

.fx-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.stock-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stock-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  color: var(--text);
}

.stock-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.stock-card-signal {
  font-size: 16px;
  line-height: 1;
}

.stock-card-name-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.stock-card-name {
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stock-card-price-line {
  font-size: 12px;
  color: var(--text-faint);
}

.stock-card-return {
  font-size: 14px;
  font-weight: 700;
}

.stock-card-menu {
  flex-shrink: 0;
  min-width: 32px;
  min-height: 32px;
  margin: -4px -6px -4px 0;
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.stock-card-menu:active {
  background: var(--bg);
  color: var(--text);
}

.stock-card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.stock-card-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stock-card-label {
  font-size: 11px;
  color: var(--text-faint);
}

.stock-card-value {
  font-size: 13px;
  color: var(--text);
}

.empty-hint {
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
  padding: 30px 0;
  margin: 0;
}

.currency-badge {
  display: inline-block;
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

.deposit-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.deposit-card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px;
  color: var(--text);
}

.deposit-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.deposit-card-name {
  font-size: 15px;
  font-weight: 700;
  flex: 1;
}

.deposit-card-menu {
  flex-shrink: 0;
  min-width: 32px;
  min-height: 32px;
  margin: -4px -6px -4px 0;
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.deposit-card-menu:active {
  background: var(--bg);
  color: var(--text);
}

.deposit-card-amount {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

/* ---------- View: Detail ---------- */
.holding-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.summary-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-label {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.summary-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

/* Signal banner */
.signal-banner {
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--border);
}

.signal-banner[hidden] {
  display: none;
}

.btn-signal-ack {
  flex-shrink: 0;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  font-weight: 700;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.btn-signal-ack[hidden] {
  display: none;
}

.signal-acknowledged-note {
  font-size: 12px;
  color: var(--text-faint);
  margin: -6px 0 12px;
}

.signal-acknowledged-note[hidden] {
  display: none;
}

.signal-red {
  background: var(--red-soft);
  border-color: var(--red-border);
  color: var(--red);
}

.signal-orange {
  background: var(--orange-soft);
  border-color: var(--orange-border);
  color: var(--orange);
}

.signal-green {
  background: var(--green-soft);
  border-color: var(--green-border);
  color: var(--green);
}

.signal-yellow {
  background: var(--yellow-soft);
  border-color: var(--yellow-border);
  color: var(--yellow);
}

/* Criteria rows */
.criteria-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 8px;
}

.criteria-row:last-child {
  margin-bottom: 0;
}

.criteria-label {
  font-size: 13px;
  color: var(--text-dim);
}

.criteria-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.criteria-buy {
  background: var(--amber-soft);
  border-color: var(--amber-border);
}

.criteria-buy .criteria-value {
  color: var(--amber);
}

.criteria-profit {
  background: var(--green-soft);
  border-color: var(--green-border);
}

.criteria-profit .criteria-value {
  color: var(--green);
}

.criteria-stop {
  background: var(--teal-soft);
  border-color: var(--teal-border);
}

.criteria-stop .criteria-value {
  color: var(--teal);
}

/* Drawdown */
.drawdown-line {
  font-size: 14px;
  color: var(--text);
  margin: 0 0 6px;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  min-width: 320px;
}

.data-table th {
  text-align: right;
  color: var(--text-faint);
  font-weight: 600;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th:first-child,
.data-table td:first-child {
  text-align: center;
}

.data-table td {
  text-align: right;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
  color: var(--text);
}

.data-table tbody tr[data-clickable] {
  cursor: pointer;
}

.data-table tbody tr[data-clickable]:active {
  background: var(--bg-elevated);
}

.tx-hint {
  font-size: 12px;
  color: var(--text-faint);
  margin: -6px 0 10px;
}

.tx-edit-hint {
  color: var(--text-faint) !important;
  text-align: center !important;
}

.badge-buy {
  color: var(--amber);
  font-weight: 700;
}

.badge-sell {
  color: var(--teal);
  font-weight: 700;
}

.pnl-pos {
  color: var(--green);
}

.pnl-neg {
  color: var(--red);
}

/* Settings (details/summary) */
.settings-details summary {
  cursor: pointer;
  list-style: none;
}

.settings-details summary::-webkit-details-marker {
  display: none;
}

.settings-details summary::after {
  content: '▸';
  float: right;
  color: var(--text-faint);
}

.settings-details[open] summary::after {
  content: '▾';
}

.settings-details .field-group {
  margin-top: 14px;
}

.settings-danger-zone {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Sticky bottom actions */
.sticky-actions {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  z-index: 20;
}

.sticky-actions[hidden] {
  display: none;
}

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

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 380px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-box h3 {
  margin: 0 0 16px;
  font-size: 15px;
  color: var(--text);
}

.modal-message {
  font-size: 14px;
  color: var(--text);
  margin: 0 0 18px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

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

/* Toast */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  max-width: 90vw;
  text-align: center;
}

@media (min-width: 480px) {
  .stock-card-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* 스펙 13.5 -- 오프라인 저장본 배너 */
.offline-banner {
  position: sticky;
  top: 0;
  z-index: 300;
  background: var(--orange-soft);
  border-bottom: 1px solid var(--orange-border);
  color: var(--orange);
  font-size: 12px;
  padding: 6px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  text-align: center;
  justify-content: center;
}

.offline-banner[hidden] {
  display: none;
}

.panel-title-hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-faint);
}

.import-report {
  font-size: 13px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 10px 0;
  max-height: 240px;
  overflow-y: auto;
}

.import-report .import-error {
  color: var(--red);
}

.import-report ul {
  margin: 4px 0;
  padding-left: 18px;
}
