/* ──────────────────────────────────────
   CSS 변수 (라이트/다크)
   ────────────────────────────────────── */
:root {
  --bg: #f0f2f5;
  --surface: #fff;
  --text: #1a1a2e;
  --text-sub: #6b7280;
  --text-muted: #9ca3af;
  --border: #d1d5db;
  --border-light: #e5e7eb;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --card-shadow: rgba(0, 0, 0, 0.06);
  --card-shadow-hover: rgba(0, 0, 0, 0.1);
  --tab-bg: #f3f4f6;
  --input-bg: #fff;
  --badge-bg: #eff6ff;
  --summary-bg: #f8fafc;
  --summary-border: #e2e8f0;
  --highlight-bg: #fefce8;
  --highlight-border: #facc15;
  --toast-bg: #1f2937;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #e2e8f0;
  --text-sub: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --border-light: #1e293b;
  --primary: #60a5fa;
  --primary-hover: #3b82f6;
  --card-shadow: rgba(0, 0, 0, 0.2);
  --card-shadow-hover: rgba(0, 0, 0, 0.4);
  --tab-bg: #0f172a;
  --input-bg: #0f172a;
  --badge-bg: #1e3a5f;
  --summary-bg: #0f172a;
  --summary-border: #334155;
  --highlight-bg: #422006;
  --highlight-border: #a16207;
  --toast-bg: #e2e8f0;
}

[data-theme="dark"] .toast {
  color: #0f172a;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* Header */
header {
  margin-bottom: 24px;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-row > div {
  text-align: center;
  flex: 1;
}

header h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
}

.subtitle {
  font-size: 14px;
  color: var(--text-sub);
  margin-top: 4px;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  line-height: 1;
}

.icon-btn:hover {
  border-color: var(--primary);
  background: var(--badge-bg);
}

/* Channel Tabs */
.channel-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--tab-bg);
  border-radius: 12px;
  padding: 4px;
}

.channel-tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-sub);
  transition: all 0.2s;
}

.channel-tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
}

.channel-tab:not(.active):hover {
  color: var(--text);
  background: var(--surface);
}

/* Budget badge */
.card-budget {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #dcfce7;
  color: #166534;
  font-weight: 600;
}

[data-theme="dark"] .card-budget {
  background: #052e16;
  color: #86efac;
}

/* Controls */
.controls {
  margin-bottom: 20px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.filter-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text-sub);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.search-sort {
  display: flex;
  gap: 8px;
}

#search {
  flex: 1;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s;
}

#search:focus {
  border-color: var(--primary);
}

#sort {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  outline: none;
}

/* Stats */
.stats {
  font-size: 13px;
  color: var(--text-sub);
  margin-bottom: 12px;
}

/* Section */
.section-wrap {
  margin-bottom: 16px;
}

.section-label {
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 8px;
  margin-bottom: 10px;
  display: inline-block;
}

.urgent-label {
  background: #fee2e2;
  color: #991b1b;
}

[data-theme="dark"] .urgent-label {
  background: #450a0a;
  color: #fca5a5;
}

/* Card List */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.loading, .empty {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

/* Card */
.card {
  background: var(--surface);
  border-radius: 12px;
  padding: 16px 20px;
  border-left: 4px solid #22c55e;
  box-shadow: 0 1px 3px var(--card-shadow);
  transition: box-shadow 0.2s, background 0.3s;
}

.card:hover {
  box-shadow: 0 4px 12px var(--card-shadow-hover);
}

.card.urgent {
  border-left-color: #ef4444;
}

.card.warning {
  border-left-color: #f59e0b;
}

.card.highlight {
  background: var(--highlight-bg);
  border-left-color: var(--highlight-border);
  position: relative;
}

.card.highlight::after {
  content: "관심";
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--highlight-border);
  color: #422006;
}

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

.dday-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.dday-badge.green {
  background: #dcfce7;
  color: #166534;
}

.dday-badge.yellow {
  background: #fef3c7;
  color: #92400e;
}

.dday-badge.red {
  background: #fee2e2;
  color: #991b1b;
}

[data-theme="dark"] .dday-badge.green { background: #052e16; color: #86efac; }
[data-theme="dark"] .dday-badge.yellow { background: #451a03; color: #fcd34d; }
[data-theme="dark"] .dday-badge.red { background: #450a0a; color: #fca5a5; }

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 13px;
  color: var(--text-sub);
  margin-bottom: 10px;
}

.card-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.card-category {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--badge-bg);
  color: var(--primary);
  font-weight: 500;
}

.card-source {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--tab-bg);
  color: var(--text-muted);
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.btn {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.2s;
}

.btn:hover {
  opacity: 0.85;
}

.btn-detail {
  background: var(--tab-bg);
  color: var(--text-sub);
}

.btn-summary {
  background: var(--badge-bg);
  color: var(--primary);
}

.btn-summary.no-key {
  opacity: 0.5;
}

.btn-summary.loading {
  opacity: 0.7;
  cursor: wait;
}

/* AI 요약 결과 */
.summary-box {
  margin-top: 12px;
  padding: 12px 16px;
  background: var(--summary-bg);
  border: 1px solid var(--summary-border);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
}

.summary-box .summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.summary-error {
  color: #ef4444;
  font-size: 13px;
  margin-top: 8px;
}

/* Footer */
footer {
  text-align: center;
  margin-top: 32px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ──────────────────────────────────────
   모달
   ────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 90%;
  max-width: 460px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 0;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 20px 24px;
}

.modal-footer {
  padding: 0 24px 20px;
}

.settings-section {
  margin-bottom: 4px;
}

.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0 20px;
}

/* Provider Tabs */
.provider-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--tab-bg);
  border-radius: 10px;
  padding: 4px;
}

.provider-tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-sub);
  transition: all 0.2s;
}

.provider-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px var(--card-shadow);
}

.provider-panel {
  display: none;
}

.provider-panel.active {
  display: block;
}

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

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

.field input[type="password"],
.field input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: var(--input-bg);
  color: var(--text);
  transition: border-color 0.2s;
}

.field input:focus {
  border-color: var(--primary);
}

.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--input-bg);
  color: var(--text);
  cursor: pointer;
  outline: none;
}

.key-input-row {
  display: flex;
  gap: 6px;
}

.key-input-row input {
  flex: 1;
}

.toggle-key-btn {
  background: var(--tab-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
}

.toggle-key-btn:hover {
  opacity: 0.8;
}

.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.field-hint a {
  color: var(--primary);
  text-decoration: none;
}

.field-hint a:hover {
  text-decoration: underline;
}

/* Radio */
.active-provider-select {
  display: flex;
  gap: 20px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}

.radio-label input[type="radio"] {
  accent-color: var(--primary);
}

/* Save button */
.btn-save {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

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

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

/* ──────────────────────────────────────
   반응형
   ────────────────────────────────────── */
@media (max-width: 600px) {
  .container {
    padding: 16px 12px;
  }

  header h1 {
    font-size: 22px;
  }

  .subtitle {
    font-size: 12px;
  }

  .icon-btn {
    padding: 6px 8px;
    font-size: 18px;
  }

  .filters {
    gap: 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .filter-btn {
    padding: 5px 10px;
    font-size: 12px;
    flex-shrink: 0;
  }

  .search-sort {
    flex-direction: column;
  }

  .card {
    padding: 14px 16px;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .card-meta {
    gap: 8px;
    font-size: 12px;
  }

  .card-actions {
    flex-wrap: wrap;
  }

  .btn {
    font-size: 12px;
    padding: 5px 12px;
  }

  .card.highlight::after {
    top: 6px;
    right: 8px;
    font-size: 9px;
  }

  .modal {
    width: 95%;
    max-height: 90vh;
  }

  .provider-tab {
    padding: 7px 8px;
    font-size: 12px;
  }
}

@media (max-width: 380px) {
  .header-row > div h1 {
    font-size: 20px;
  }

  .filter-btn {
    padding: 4px 8px;
    font-size: 11px;
  }
}
