/* Bootstrap 5 Custom Dark Theme Variables */
:root[data-bs-theme="dark"] {
  --bs-body-bg: #0f1419;
  --bs-body-color: #e5e7eb;
  --bs-border-color: #2d3748;
  --bs-card-bg: #1a1f2e;
  --bs-card-border-color: #2d3748;
  --bs-primary: #3b82f6;
  --bs-primary-rgb: 59, 130, 246;
  --bs-success: #10b981;
  --bs-danger: #ef4444;
  --bs-warning: #f59e0b;
  --bs-info: #06b6d4;
  --bs-secondary: #6b7280;
}

/* Custom Styles */
body {
  background: #0f1419;
  min-height: 100vh;
  padding: 20px;
}

/* Card Customization */
.card {
  background: #1a1f2e;
  border: 1px solid #2d3748;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid #2d3748;
}

/* Form Controls */
.form-control,
.form-select {
  background-color: #0f1419;
  border-color: #374151;
  color: #e5e7eb;
}

.form-control:focus,
.form-select:focus {
  background-color: #0f1419;
  border-color: #3b82f6;
  color: #e5e7eb;
  box-shadow: 0 0 0 0.25rem rgba(59, 130, 246, 0.25);
}

.form-control::placeholder {
  color: #6b7280;
}

/* Buttons */
.btn-primary {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  border: none;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
  transform: translateY(-1px);
}

.btn-success {
  background-color: #10b981;
  border-color: #10b981;
}

.btn-danger {
  background-color: #ef4444;
  border-color: #ef4444;
}

/* Direction Buttons */
.btn-direction {
  border: 2px solid #374151;
  font-weight: 600;
  transition: all 0.3s;
  background: #1a1f2e;
  color: #9ca3af;
}

.btn-direction:hover {
  background: #1f2937;
}

.btn-high.active {
  background-color: #10b981 !important;
  border-color: #10b981 !important;
  color: white !important;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-low.active {
  background-color: #ef4444 !important;
  border-color: #ef4444 !important;
  color: white !important;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-high.active {
  background-color: #10b981;
  border-color: #10b981;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-low.active {
  background-color: #ef4444;
  border-color: #ef4444;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* Duration Buttons */
.btn-duration.active {
  background-color: #3b82f6;
  border-color: #3b82f6;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

/* Chart Container */
.chart-container {
  width: 100%;
  height: 500px;
  background: #0f1419;
  border: 1px solid #2d3748;
  border-radius: 8px;
  padding: 20px;
  position: relative;
}

#priceChart {
  width: 100% !important;
  height: 100% !important;
}

/* Statistics Cards */
.stat-card {
  background: linear-gradient(135deg, #1a1f2e 0%, #0f1419 100%);
  border: 1px solid #2d3748;
  border-left: 4px solid #3b82f6;
  transition: all 0.3s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* Crypto Cards */
.crypto-card {
  background: linear-gradient(135deg, #1a1f2e 0%, #0f1419 100%);
  border: 1px solid #2d3748;
  transition: all 0.3s;
  cursor: pointer;
}

.crypto-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.4);
  border-color: #3b82f6;
}

/* Trade Items */
.trade-item {
  background: linear-gradient(135deg, #1a1f2e 0%, #0f1419 100%);
  border: 1px solid #2d3748;
  transition: all 0.3s;
}

.trade-item:hover {
  border-color: #374151;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.trade-item.active {
  background: linear-gradient(135deg, #1e293b 0%, #1a1f2e 100%);
  border-color: #3b82f6;
}

/* Profit Box */
.profit-box.positive {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(16, 185, 129, 0.05) 100%);
  border-color: #10b981;
}

.profit-box.negative {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, rgba(239, 68, 68, 0.05) 100%);
  border-color: #ef4444;
}

/* Alert Messages */
.alert {
  border: 1px solid;
}

.alert-danger {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.alert-success {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
  color: #6ee7b7;
}

/* Navbar */
.navbar-dark {
  background-color: #1a1f2e !important;
}

.navbar-nav .nav-link.active {
  color: #3b82f6 !important;
  font-weight: 600;
}

.navbar-nav .nav-link:hover {
  color: #3b82f6 !important;
}

/* Utility Classes */
.text-muted {
  color: #9ca3af !important;
}

.border-secondary {
  border-color: #2d3748 !important;
}

/* Price Info */
.price-info {
  color: #9ca3af;
  font-size: 1rem;
  margin-top: 0.5rem;
}

.payout-info {
  color: #9ca3af;
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

/* Empty States */
.empty-message {
  color: #6b7280;
  text-align: center;
  padding: 2.5rem;
}

/* Loading States */
.loading {
  color: #6b7280;
  text-align: center;
  padding: 1.25rem;
}

/* ============================================
   MOBILE RESPONSIVE STYLES
   ============================================ */

/* Base responsive */
@media (max-width: 768px) {
  body {
    padding: 0;
  }
  
  .container {
    padding-left: 8px;
    padding-right: 8px;
  }
  
  .card {
    border-radius: 8px;
  }
  
  .card-body {
    padding: 0.75rem;
  }
}

/* Balance Card - Mobile */
.balance-card .balance-value {
  font-size: 1rem;
}

.balance-card .balance-value-main {
  font-size: 1.1rem;
}

@media (max-width: 576px) {
  .balance-card .balance-value {
    font-size: 0.85rem;
  }
  
  .balance-card .balance-value-main {
    font-size: 0.95rem;
  }
  
  .balance-item {
    padding: 0 2px;
  }
}

/* Chart Container - Mobile Optimized */
.chart-container {
  width: 100%;
  height: 500px;
  background: #0f1419;
  border: 1px solid #2d3748;
  border-radius: 8px;
  padding: 10px;
  position: relative;
}

#priceChart {
  width: 100% !important;
  height: 100% !important;
}

@media (max-width: 768px) {
  .chart-container {
    height: 280px;
    padding: 8px;
    border-radius: 6px;
  }
}

@media (max-width: 576px) {
  .chart-container {
    height: 220px;
    padding: 5px;
  }
}

/* Landscape mode on mobile - taller chart */
@media (max-width: 768px) and (orientation: landscape) {
  .chart-container {
    height: 200px;
  }
}

/* Crypto Select - Mobile */
.crypto-select {
  width: 100%;
  max-width: 200px;
}

@media (max-width: 576px) {
  .crypto-select {
    max-width: 100%;
    font-size: 0.875rem;
  }
}

/* Direction Buttons - コンパクトに */
.direction-buttons .btn-direction {
  padding: 8px 12px;
  font-size: 0.9rem;
  border-radius: 8px;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.direction-buttons .btn-direction i {
  font-size: 1.25rem;
}

.direction-buttons .btn-direction span {
  font-size: 0.9rem;
}

@media (max-width: 576px) {
  .direction-buttons .btn-direction {
    padding: 8px 6px;
    min-height: 48px;
  }
  
  .direction-buttons .btn-direction i {
    font-size: 1.2rem;
  }
  
  .direction-buttons .btn-direction span {
    font-size: 0.85rem;
  }
}

/* Duration Buttons - 中央寄せ・横スクロール対応 */
.duration-buttons {
  justify-content: center;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.duration-buttons::-webkit-scrollbar {
  display: none;
}

.duration-buttons .btn-duration {
  min-width: 60px;
  padding: 8px 12px;
}

@media (max-width: 576px) {
  .duration-buttons .btn-duration {
    min-width: 55px;
    padding: 10px 8px;
    font-size: 0.8rem;
  }
}

/* Quick Amount Buttons */
.quick-amount-buttons .btn {
  padding: 6px 4px;
  font-size: 0.75rem;
}

@media (max-width: 576px) {
  .quick-amount-buttons .btn {
    padding: 8px 4px;
    font-size: 0.7rem;
  }
}

/* Trade Submit Button */
.trade-submit-btn {
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: 10px;
}

@media (max-width: 576px) {
  .trade-submit-btn {
    padding: 16px 20px;
    font-size: 1rem;
    border-radius: 8px;
    position: sticky;
    bottom: 10px;
    z-index: 100;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
  }
}

/* Trade History - PC: テーブル表示 */
.trade-history-table {
  width: 100%;
  border-collapse: collapse;
}

.trade-history-table th,
.trade-history-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #2d3748;
  text-align: left;
  vertical-align: middle;
}

.trade-history-table thead th {
  font-weight: 600;
  color: #9ca3af;
  font-size: 0.8rem;
  text-transform: none;
}

.trade-history-table tbody .trade-item-row:hover {
  background: rgba(255, 255, 255, 0.03);
}

.trade-history-table .empty-message {
  padding: 2rem !important;
}

/* Trade History - SP: カード風（見やすく整理） */
@media (max-width: 767px) {
  .trade-history-table,
  .trade-history-table thead,
  .trade-history-table tbody,
  .trade-history-table tr,
  .trade-history-table th,
  .trade-history-table td {
    display: block;
  }

  .trade-history-table thead {
    display: none;
  }

  .trade-history-table tbody tr.trade-item-row {
    background: linear-gradient(160deg, #1e2433 0%, #151a24 100%);
    border: 1px solid #374151;
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    overflow: hidden;
  }

  .trade-history-table tbody tr.trade-item-row[data-result="win"] {
    border-left: 4px solid #10b981;
  }

  .trade-history-table tbody tr.trade-item-row[data-result="loss"] {
    border-left: 4px solid #ef4444;
  }

  .trade-history-table tbody tr.trade-item-row:last-child {
    margin-bottom: 0;
  }

  .trade-history-table tbody tr.trade-item-row {
    -webkit-tap-highlight-color: transparent;
  }

  /* ヘッダー行（通貨・方向・種別・結果）を1行にまとめて目立たせる */
  .trade-history-table tbody tr.trade-item-row .trade-mobile-header {
    display: inline-flex;
    align-items: center;
    padding: 12px 14px 10px;
    border: none;
    font-size: 0.85rem;
    gap: 0.35rem;
  }

  .trade-history-table tbody tr.trade-item-row .trade-mobile-header::before {
    display: none;
  }

  .trade-history-table tbody tr.trade-item-row .trade-mobile-header:not(.trade-mobile-result)::after {
    content: "·";
    color: #6b7280;
    font-weight: 400;
    margin-left: 4px;
  }

  .trade-history-table tbody tr.trade-item-row .trade-mobile-result {
    margin-left: auto;
  }

  .trade-history-table tbody tr.trade-item-row .trade-mobile-result::after {
    display: none !important;
  }

  /* ヘッダー行を flex で横並びにするため、tr を flex wrap */
  .trade-history-table tbody tr.trade-item-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }

  .trade-history-table tbody tr.trade-item-row .trade-mobile-header:first-child {
    flex: 1 1 auto;
    min-width: 0;
  }

  /* 詳細行（日時・エントリー・終了・投資額） */
  .trade-history-table tbody tr.trade-item-row td:not(.trade-mobile-header):not(.trade-mobile-profit) {
    width: 100%;
    flex: 0 0 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    font-size: 0.875rem;
    border-top: 1px solid rgba(55, 65, 81, 0.6);
    gap: 0.5rem;
  }

  .trade-history-table tbody tr.trade-item-row td:not(.trade-mobile-header):not(.trade-mobile-profit)::before {
    content: attr(data-label);
    font-weight: 500;
    color: #6b7280;
    font-size: 0.8rem;
    flex-shrink: 0;
  }

  /* 損益を大きく目立たせる */
  .trade-history-table tbody tr.trade-item-row .trade-mobile-profit {
    width: 100%;
    flex: 0 0 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    font-size: 1.05rem;
    font-weight: 600;
    border-top: 1px solid rgba(55, 65, 81, 0.6);
    background: rgba(0, 0, 0, 0.15);
    gap: 0.5rem;
  }

  .trade-history-table tbody tr.trade-item-row .trade-mobile-profit::before {
    content: attr(data-label);
    font-weight: 600;
    color: #9ca3af;
    font-size: 0.8rem;
  }

  .trade-history-table tbody td .badge {
    font-size: 0.7rem;
    padding: 4px 8px;
    border-radius: 6px;
  }

  .trade-history-table tbody tr:not(.trade-item-row) td {
    display: block !important;
    text-align: center;
    justify-content: center;
  }

  .trade-history-table tbody tr td.empty-message {
    display: block !important;
    text-align: center;
    padding: 2.5rem 1rem !important;
    font-size: 0.95rem;
    color: #9ca3af;
  }

  .trade-history-table tbody tr td.empty-message::before {
    display: none;
  }
}

/* Price Info - Mobile */
.price-info {
  color: #9ca3af;
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

@media (max-width: 576px) {
  .price-info {
    font-size: 0.85rem;
  }
}

/* Payout Info */
.payout-info {
  color: #9ca3af;
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

/* Input Group - Mobile */
@media (max-width: 576px) {
  .input-group .form-control-lg {
    font-size: 1.25rem;
    padding: 12px;
  }
  
  .input-group .input-group-text {
    font-size: 1.1rem;
    padding: 12px;
  }
}

/* Navbar - Mobile Fix */
@media (max-width: 576px) {
  .navbar-brand {
    font-size: 1.1rem;
  }
  
  .navbar-nav .nav-link {
    padding: 8px 12px;
    font-size: 0.9rem;
  }
}

/* Touch-friendly spacing */
@media (max-width: 768px) {
  .btn {
    min-height: 44px;
  }
  
  .form-control, .form-select {
    min-height: 44px;
  }
}

/* Prevent zoom on input focus (iOS) */
@media (max-width: 576px) {
  input[type="number"],
  input[type="text"],
  select {
    font-size: 16px !important;
  }
}

/* ============================================
   ACTIVE TRADES CARD (進行中の取引)
   ============================================ */

.active-trades-card {
  border-width: 2px;
  animation: pulse-border 2s ease-in-out infinite;
}

@keyframes pulse-border {
  0%, 100% { border-color: rgba(59, 130, 246, 0.5); }
  50% { border-color: rgba(59, 130, 246, 1); }
}

.active-trades-card .card-header {
  border-bottom: 1px solid rgba(59, 130, 246, 0.3);
}

/* 進行中取引アイテム */
.active-trade-item {
  background: linear-gradient(135deg, #1e293b 0%, #1a1f2e 100%);
  border: 1px solid #3b82f6;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
}

.active-trade-item:last-child {
  margin-bottom: 0;
}

/* 残り時間の大きな表示 */
.trade-timer {
  font-size: 1.5rem;
  font-weight: 700;
  color: #3b82f6;
  font-family: 'Courier New', monospace;
  text-align: center;
  padding: 8px 16px;
  background: rgba(59, 130, 246, 0.1);
  border-radius: 8px;
  min-width: 100px;
}

.trade-timer.warning {
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.1);
  animation: timer-pulse 1s ease-in-out infinite;
}

.trade-timer.danger {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
  animation: timer-pulse 0.5s ease-in-out infinite;
}

@keyframes timer-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* 取引情報 */
.active-trade-info {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.active-trade-crypto {
  font-weight: 600;
  font-size: 1rem;
}

.active-trade-amount {
  color: #9ca3af;
  font-size: 0.9rem;
}

/* スマホ対応 */
@media (max-width: 576px) {
  .active-trade-item {
    padding: 10px;
  }
  
  .trade-timer {
    font-size: 1.3rem;
    padding: 6px 12px;
    min-width: 80px;
  }
  
  .active-trade-crypto {
    font-size: 0.9rem;
  }
  
  .active-trade-amount {
    font-size: 0.8rem;
  }
}
