:root {
  --bg: var(--tg-theme-bg-color, #f4f4f5);
  --bg-2: var(--tg-theme-secondary-bg-color, #ffffff);
  --ink: var(--tg-theme-text-color, #1f2328);
  --hint: var(--tg-theme-hint-color, #707579);
  --link: var(--tg-theme-link-color, #2b8cef);
  --button: var(--tg-theme-button-color, #2b8cef);
  --button-ink: var(--tg-theme-button-text-color, #ffffff);
  --danger: #d64545;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  padding-bottom: 32px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(135deg, #0b2545 0%, #2b78dc 100%);
  padding: 12px 16px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

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

.brand-logo {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  flex: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.app-header h1 {
  margin: 0;
  font-size: 18px;
  color: #fff;
}

.tabs { display: flex; gap: 4px; }

.tab {
  flex: 1;
  padding: 9px 2px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tab.active {
  color: #fff;
  border-bottom-color: #fff;
}

main { padding: 14px 16px; }

.card {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 13px 14px;
  margin-bottom: 10px;
}

.card h3 { margin: 0 0 4px; font-size: 15px; }
.card .meta { color: var(--hint); font-size: 13px; }
.card a { color: var(--link); text-decoration: none; font-size: 13px; }

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

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(43, 140, 239, 0.1);
  color: var(--ink);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
}

.chip.exclude { background: rgba(214, 69, 69, 0.1); }

.chip button {
  border: none;
  background: none;
  color: var(--hint);
  font-size: 14px;
  padding: 0;
  cursor: pointer;
  line-height: 1;
}

.field-label {
  margin: 10px 0 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--hint);
}

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

input[type="text"] {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(112, 117, 121, 0.3);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  background: var(--bg);
  color: var(--ink);
}

button.primary {
  border: none;
  background: var(--button);
  color: var(--button-ink);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

button.ghost {
  border: 1px solid rgba(112, 117, 121, 0.3);
  background: transparent;
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}

button.danger { color: var(--danger); border-color: rgba(214, 69, 69, 0.4); }
button:disabled { opacity: 0.5; cursor: default; }

.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute;
  inset: 0;
  background: rgba(112, 117, 121, 0.35);
  border-radius: 999px;
  transition: background 0.15s;
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
}
.switch input:checked + .slider { background: var(--button); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.empty {
  text-align: center;
  color: var(--hint);
  padding: 36px 12px;
  font-size: 14px;
  white-space: pre-line;  /* honor the \n line breaks in empty-state copy */
}

.candidates { margin-top: 6px; display: flex; flex-direction: column; gap: 5px; }

.template-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }

.section-title {
  margin: 16px 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--hint);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13px;
  max-width: 86vw;
  z-index: 50;
  white-space: pre-line;
}

.feed-more { width: 100%; margin-top: 4px; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex: none;
  margin-right: 6px;
}
.badge-daily { background: #2b78dc; }   /* 일 — blue */
.badge-weekly { background: #0b2545; }   /* 주 — navy, matches the header */

.report-company {
  margin: 9px 0 2px;
  font-size: 13px;
  font-weight: 700;
}
.report-item {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 2px 0;
}
.report-item a { font-size: 13px; }
.report-major { font-size: 10px; flex: none; }

/* AI 시황 리포트 (market reports) */
.mr-card { cursor: pointer; }
.mr-card:active { opacity: 0.7; }
.mr-title {
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.mr-date { margin-top: 4px; }
.mr-chevron { color: var(--hint); font-size: 20px; flex: none; line-height: 1; }
.mr-back { margin-bottom: 10px; }
.mr-bubble {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.5;
}
.mr-bubble a { font-size: inherit; word-break: break-all; }
.mr-bubble b, .mr-bubble strong { font-weight: 700; }
