/* Main Application Styles */

/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-primary);
  background-color: var(--theme-bg-secondary);
  color: var(--theme-text-secondary);
  line-height: var(--leading-normal);
  font-size: var(--text-base);
  transition:
    background-color 0.3s ease,
    color 0.3s ease;
}

/* Layout */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

/* Header & Sections */
.header,
.section,
.exchange-rates,
.subscriptions,
.purchases-section {
  background: var(--theme-bg);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--theme-border);
}

.header-content,
.header-top,
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

@media (max-width: 768px) {
  .header-content,
  .header-top,
  .section-header {
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
  }
}

.title,
.section-title,
.subscription-title {
  font-size: var(--text-2xl);
  font-weight: 600;
  color: var(--theme-text-primary);
  margin-bottom: 0;
}

.section-title {
  margin-bottom: 1.5rem;
}

/* Buttons */
.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  min-height: 32px;
}

.btn-primary {
  background: var(--theme-primary);
  color: var(--theme-bg);
  /* Usually white or inverted text */
}

[data-theme="dark"] .btn-primary {
  color: #1a1a1a;
}

.btn-primary:hover {
  background: var(--theme-primary-hover);
}

.btn-primary:disabled {
  background: var(--ds-gray-400);
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--theme-secondary);
  color: var(--theme-secondary-text);
}

.btn-secondary:hover {
  background: var(--theme-secondary-hover);
}

.btn-danger {
  background: var(--theme-danger);
  color: white;
}

.btn-danger:hover {
  background: var(--theme-danger-hover);
}

/* Icon-only button */
.btn-icon {
  padding: 0.5rem;
  min-width: 36px;
  min-height: 36px;
  font-size: 1rem;
}

.btn-warning {
  background: var(--theme-warning);
  color: white;
}

.btn-warning:hover {
  background: var(--theme-warning-text);
}

.btn-success {
  background: var(--theme-success);
  color: white;
}

.btn-success:hover {
  background: var(--theme-success-text);
}

.actions,
.nav-actions,
.system-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

@media (max-width: 768px) {
  .actions,
  .nav-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
}

@media (max-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.form-group {
  margin-bottom: 1rem;
}

/* Form Row - Horizontal grouping */
.form-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.form-row > .form-group {
  flex: 1;
  margin-bottom: 0;
}

.form-row.three-cols > .form-group {
  flex: 1;
}

@media (max-width: 600px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .form-row > .form-group {
    margin-bottom: 1rem;
  }
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--theme-text-secondary);
  font-size: 0.875rem;
}

.form-control {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--theme-border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  background-color: var(--input-bg);
  color: var(--input-text);
  transition: border-color 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--theme-text-secondary);
}

.form-control::placeholder {
  color: var(--input-placeholder);
}

.form-hint {
  font-size: 0.75rem;
  color: var(--theme-text-muted);
  margin-top: 0.25rem;
}

/* Cards & Stats */
.stats-grid,
.system-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat-card,
.system-card {
  background: var(--theme-bg);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--theme-border);
  text-align: center;
}

.system-card {
  text-align: left;
  border-left: 4px solid var(--theme-primary);
  transition:
    transform 0.2s,
    box-shadow 0.2s;
}

.system-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.system-card.healthy {
  border-left-color: var(--theme-success);
}

.system-card.warning {
  border-left-color: var(--theme-warning);
}

.system-card.error {
  border-left-color: var(--theme-danger);
}

.stat-value,
.card-value {
  font-size: var(--text-4xl);
  font-weight: 600;
  color: var(--theme-text-primary);
  margin-bottom: 0.5rem;
}

.card-value {
  font-size: var(--text-lg);
}

.stat-label,
.card-description {
  color: var(--theme-text-muted);
  font-size: 0.875rem;
}

/* Tables */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--theme-border);
}

.subscriptions-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--theme-bg);
}

.subscriptions-table th {
  background: var(--theme-bg-secondary);
  color: var(--theme-text-primary);
  font-weight: 600;
  text-align: left;
  padding: 0.75rem;
  border-bottom: 1px solid var(--theme-border);
  font-size: 0.875rem;
}

.subscriptions-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--theme-border);
  color: var(--theme-text-secondary);
  font-size: 0.875rem;
}

.subscriptions-table tbody tr:hover {
  background: var(--theme-bg-tertiary);
}

/* Status Badges & Indicators */
.subscription-status,
.status-badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

.status-active {
  background: var(--theme-success-bg);
  color: var(--theme-success-text);
}

.status-warning {
  background: var(--theme-warning-bg);
  color: var(--theme-warning-text);
}

.status-expired {
  background: var(--theme-bg-secondary);
  color: var(--theme-text-muted);
}

.status-light {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.status-light.green {
  background: var(--theme-success);
  box-shadow: 0 0 8px rgba(76, 175, 80, 0.4);
}

.status-light.red {
  background: var(--theme-danger);
  box-shadow: 0 0 8px rgba(244, 67, 54, 0.4);
}

.status-light.yellow {
  background: var(--theme-warning);
  box-shadow: 0 0 8px rgba(255, 152, 0, 0.4);
}

.status-light.orange {
  background: #f57c00;
  box-shadow: 0 0 8px rgba(245, 124, 0, 0.4);
}

.status-light.gray {
  background: var(--ds-gray-400);
}

/* Login Page Specific */
.login-container {
  background: var(--theme-bg);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 400px;
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
}

.modal-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--theme-bg);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 700px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--theme-border);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  position: relative;
}

.modal-header .modal-title {
  margin: 0;
  font-size: 1.5rem;
}

.modal-header .close {
  position: absolute;
  top: 0;
  right: 0;
  background: none;
  border: none;
  font-size: 1.75rem;
  cursor: pointer;
  color: var(--theme-text-secondary);
  padding: 0;
  line-height: 1;
  transition: color 0.2s;
}

.modal-header .close:hover {
  color: var(--theme-danger);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: relative;
  width: 44px;
  height: 24px;
  background-color: var(--theme-bg-secondary);
  border-radius: 24px;
  transition: background-color 0.3s;
  border: 1px solid var(--theme-border);
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: transform 0.3s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--theme-primary);
  border-color: var(--theme-primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* Toast */
.toast {
  position: fixed;
  top: 1rem;
  right: 1rem;
  padding: 1rem 1.5rem;
  border-radius: 4px;
  color: white;
  font-weight: 500;
  z-index: 1000;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

.toast-success {
  background: var(--theme-success);
}

.toast-error {
  background: var(--theme-danger);
}

/* Theme Toggle */
.theme-toggle-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--theme-text-secondary);
  padding: 0.5rem;
  border-radius: 50%;
  transition:
    background-color 0.2s,
    color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle-btn:hover {
  background-color: var(--theme-bg-secondary);
  color: var(--theme-text-primary);
}

/* Loading */
.loading {
  display: none;
}

.loading.show {
  display: inline-block;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* Mobile */
@media (max-width: 480px) {
  body {
    padding: 0.5rem;
  }

  .login-container {
    padding: 1.5rem;
  }

  .form-control {
    font-size: 16px;
  }

  /* iOS zoom fix */
}

/* Rate Cards */
.rates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.rate-item {
  text-align: center;
  padding: 0.75rem;
  background: var(--theme-bg-secondary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--theme-border);
}

.rate-currency {
  font-size: 0.875rem;
  color: var(--theme-text-muted);
}

.rate-value {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--theme-text-primary);
}

.total-monthly-fee {
  background: rgba(33, 150, 243, 0.1) !important;
  border: 1px solid #2196f3;
}

/* Mobile/Desktop Visibility Utility */
.mobile-only {
  display: none;
}

@media (max-width: 768px) {
  .mobile-only {
    display: block;
  }

  .desktop-only {
    display: none;
  }
}

/* Filters Layout */
.filter-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
  align-items: center;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filter-select {
  padding: 0.5rem;
  border: 1px solid var(--theme-border);
  border-radius: var(--radius-sm);
  background-color: var(--input-bg);
  color: var(--input-text);
}

.filter-reset {
  padding: 0.5rem 1rem;
  background: var(--theme-bg-secondary);
  border: 1px solid var(--theme-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--theme-text-primary);
}

/* Login Page Alignment Fix */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

/* Existing content... */
.total-monthly-fee .rate-value {
  color: #1976d2;
}

/* === 訂閱卡片樣式 (Mobile View) === */
.subscription-card {
  background: var(--theme-bg);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--theme-border);
  border-left: 4px solid var(--theme-text-muted);
}

.subscription-card.status-active {
  border-left-color: var(--theme-success);
}

.subscription-card.status-warning {
  border-left-color: var(--theme-warning);
}

.subscription-card.status-expired {
  border-left-color: var(--theme-text-muted);
}

/* 卡片標題區域 */
.subscription-card .card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
}

.subscription-card .card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--theme-text-primary);
  word-break: break-word;
  margin: 0;
}

.subscription-card .card-type {
  font-size: 0.75rem;
  color: var(--theme-text-muted);
  margin-top: 0.25rem;
}

.subscription-card .card-status {
  flex-shrink: 0;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

/* 卡片資訊區域 */
.subscription-card .card-info {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.subscription-card .card-info-item {
  display: flex;
  flex-direction: column;
}

.subscription-card .card-info-label {
  font-size: 0.7rem;
  color: var(--theme-text-muted);
  margin-bottom: 0.125rem;
}

.subscription-card .card-info-value {
  font-size: 0.875rem;
  color: var(--theme-text-secondary);
  font-weight: 500;
}

.subscription-card .card-price {
  color: var(--theme-primary);
  font-weight: 600;
}

/* 卡片操作區域 */
.subscription-card .card-actions {
  display: flex;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--theme-border);
}

.subscription-card .card-actions .btn {
  flex: 1;
}
