/* ===== 무한매수법 V4.0 스타일 ===== */

:root {
  --bg: #0f0d1a;
  --bg-card: #1a1625;
  --bg-input: #13102a;
  --border: #2a2545;
  --text: #e0dfe8;
  --text-dim: #8884a0;
  --primary: #8b5cf6;
  --primary-hover: #7c3aed;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --orange: #f97316;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 24px;
  padding-top: env(safe-area-inset-top, 0);
}

/* --- Top Bar --- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 8px;
}

.logo {
  font-size: 1.3rem;
  font-weight: 800;
  color: #fff;
}

.version-badge {
  font-size: 0.65rem;
  background: var(--primary);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  vertical-align: middle;
  margin-left: 4px;
}

.topbar-right { display: flex; gap: 8px; }

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all .15s;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary); }

/* --- Session Tabs --- */
.session-tabs {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.session-tabs::-webkit-scrollbar { display: none; }

.tab-list { display: flex; gap: 6px; }

.tab {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab:hover:not(.active) { border-color: var(--primary); }

.tab-add {
  min-width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px dashed var(--border);
  background: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all .15s;
}
.tab-add:hover { border-color: var(--primary); color: var(--primary); }

/* --- Market Bar --- */
.market-bar {
  display: flex;
  gap: 8px;
  padding: 10px 0;
  overflow-x: auto;
}

.market-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  min-width: 90px;
  flex: 1;
}

.market-label { font-size: 0.7rem; color: var(--text-dim); margin-bottom: 2px; }
.market-value { font-size: 0.85rem; font-weight: 700; color: var(--text); }

/* --- Views --- */
.view { padding-bottom: 16px; }

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}
.empty-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h2 { font-size: 1.2rem; margin-bottom: 8px; }
.empty-state p { color: var(--text-dim); margin-bottom: 24px; }

/* --- Card --- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 14px;
  color: #fff;
}

.card-title-inline {
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
}

/* ===== T Value Bar ===== */
.t-bar-card {
  padding: 16px 20px 12px;
}

.t-bar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.t-bar-left {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.t-label {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-dim);
}

.t-value-display {
  font-size: 1.8rem;
  font-weight: 900;
  color: #fff;
  font-family: 'Courier New', monospace;
}

.t-slider-wrap {
  margin-top: 4px;
}

.t-slider {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(90deg, var(--green) 0%, var(--yellow) 50%, var(--red) 100%);
  border-radius: 3px;
  outline: none;
  cursor: default;
}

.t-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--primary);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.t-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--primary);
}

.t-slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ===== Summary Grid 3-Column ===== */
.summary-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.sc3 {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
}

.sc3-label {
  font-size: 0.68rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.sc3-value {
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
}

.sc3-value small {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-dim);
}

.sc3-sub {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.text-green { color: var(--green) !important; }
.text-red { color: var(--red) !important; }
.text-yellow { color: var(--yellow) !important; }
.text-orange { color: var(--orange) !important; }

/* ===== Exchange Inline ===== */
.exchange-inline {
  text-align: right;
  font-size: 0.72rem;
  color: var(--text-dim);
  padding: 2px 4px 8px;
}

.exchange-inline strong {
  color: var(--text);
}

/* ===== Recent Prices ===== */
.recent-prices-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.recent-avg {
  font-size: 0.78rem;
  color: var(--text);
  font-weight: 600;
}

.avg-badge {
  font-size: 0.65rem;
  background: var(--primary);
  color: #fff;
  padding: 2px 6px;
  border-radius: 6px;
  margin-right: 4px;
  font-weight: 600;
}

.recent-prices-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.rp-item {
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 8px 4px;
  text-align: center;
}

.rp-date {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.rp-price {
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
}

.rp-change {
  font-size: 0.62rem;
  margin-top: 2px;
}

/* ===== Fear & Greed ===== */
.fg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.fg-source {
  font-size: 0.65rem;
  color: var(--text-dim);
}

.fg-score-wrap {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
}

.fg-score {
  font-size: 2.2rem;
  font-weight: 900;
  color: #fff;
}

.fg-rating {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.fg-gauge {
  position: relative;
  height: 12px;
  border-radius: 6px;
  overflow: visible;
  margin-bottom: 4px;
}

.fg-gauge-bar {
  width: 100%;
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, #ef4444 0%, #f97316 25%, #eab308 50%, #84cc16 75%, #22c55e 100%);
}

.fg-gauge-pointer {
  position: absolute;
  top: -3px;
  width: 4px;
  height: 18px;
  background: #fff;
  border-radius: 2px;
  transform: translateX(-50%);
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
  transition: left 0.3s ease;
  left: 50%;
}

.fg-gauge-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.58rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ===== First Buy Info ===== */
.first-buy-info {
  padding: 4px 0;
}

.fbi-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

.fbi-row span {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.fbi-amount {
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--green);
}

.fbi-close {
  font-size: 0.85rem;
  padding: 10px 14px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.fbi-close strong {
  color: #fff;
}

.fbi-locs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.fbi-loc {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.fbi-loc-label {
  font-size: 0.72rem;
  color: var(--primary);
  font-weight: 600;
}

.fbi-loc-price {
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
}

.fbi-hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 4px;
}

.fbi-hint strong {
  color: var(--primary);
}

/* ===== Phase Badge ===== */
.phase-tag {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 14px;
  font-size: 0.78rem;
  font-weight: 700;
}

.phase-start { background: #1e3a5f; color: #60a5fa; }
.phase-first { background: #1e3a2f; color: #4ade80; }
.phase-second { background: #3a2e1e; color: #fbbf24; }
.phase-exhausted { background: #3a1e1e; color: #f87171; }
.phase-reverse { background: #2d1b4e; color: #c084fc; }
.phase-end { background: #1a1a2e; color: var(--text-dim); }

/* --- Orders --- */
.order-group { margin-bottom: 12px; }
.order-group-title {
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.buy-title { color: var(--green); }
.sell-title { color: var(--red); }

.order-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.order-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  padding: 4px 6px;
  font-size: 0.72rem;
}
.order-table td { padding: 5px 6px; }
.order-label { color: var(--primary); font-weight: 600; }

.empty-text { color: var(--text-dim); font-size: 0.85rem; text-align: center; padding: 20px; }

/* --- Action Bar Center --- */
.action-bar-center {
  text-align: center;
  margin-bottom: 12px;
}

.btn-record {
  padding: 14px 40px;
  font-size: 1rem;
  border-radius: 30px;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.btn-record:hover {
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.6);
}

/* --- Transaction List --- */
.tx-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.tx-row:last-child { border-bottom: none; }

.tx-info { display: flex; flex-direction: column; flex: 1; }
.tx-date { font-size: 0.72rem; color: var(--text-dim); }
.tx-type-label { font-size: 0.85rem; font-weight: 600; }
.tx-detail { font-size: 0.8rem; color: var(--text-dim); }

.tx-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
}
.tx-delete:hover { color: var(--red); }

/* --- Buttons --- */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
}
.btn-secondary:hover { background: var(--primary); color: #fff; }

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-danger:hover { background: var(--red); color: #fff; }

.full-width { width: 100%; }

/* --- Form --- */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  outline: none;
  transition: border-color .15s;
}
.input:focus { border-color: var(--primary); }

.hint { display: block; font-size: 0.72rem; color: var(--text-dim); margin-top: 4px; }

.btn-group { display: flex; gap: 6px; }

.btn-toggle {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all .15s;
}
.btn-toggle:hover { border-color: var(--primary); color: #fff; }
.btn-toggle.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* --- Transaction Type List --- */
.tx-type-list { display: flex; flex-direction: column; gap: 6px; }

.tx-type-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .15s;
}
.tx-type-btn:hover { border-color: var(--primary); }
.tx-type-btn.active { background: var(--primary); border-color: var(--primary); }

.tx-type-name { font-size: 0.85rem; font-weight: 600; color: #fff; }
.tx-type-desc { font-size: 0.72rem; color: var(--text-dim); }
.tx-type-btn.active .tx-type-desc { color: rgba(255,255,255,0.7); }

/* --- Modal --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover { color: #fff; }

.modal-body { padding: 20px; }

/* --- Auth --- */
.auth-info {
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 16px;
  color: #fff;
}

.error-msg {
  color: var(--red);
  font-size: 0.82rem;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: rgba(239, 68, 68, 0.1);
  border-radius: var(--radius-sm);
}

/* --- Responsive --- */
@media (max-width: 400px) {
  #app { padding: 0 10px 20px; }
  .summary-grid-3 { gap: 4px; }
  .sc3 { padding: 8px 4px; }
  .sc3-value { font-size: 0.88rem; }
  .card { padding: 14px; }
  .recent-prices-grid { grid-template-columns: repeat(4, 1fr); }
  .t-value-display { font-size: 1.4rem; }
}

@media (min-width: 481px) {
  .modal-content {
    border-radius: var(--radius);
    max-height: 70vh;
  }
  .modal {
    align-items: center;
  }
}
