* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #f0f2f5; color: #1a1a2e; }
a { color: #4f46e5; text-decoration: none; }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: #fff; padding: 2.5rem; border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,.08); width: 380px; }
.login-box h1 { font-size: 1.4rem; margin-bottom: .5rem; }
.login-box p { color: #666; font-size: .875rem; margin-bottom: 1.5rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: .4rem; }
.form-group input { width: 100%; padding: .6rem .8rem; border: 1px solid #ddd; border-radius: 8px; font-size: .9rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; padding: .6rem 1.2rem; border: none; border-radius: 8px; font-size: .9rem; font-weight: 600; cursor: pointer; transition: background .2s; }
.btn-primary { background: #4f46e5; color: #fff; }
.btn-primary:hover { background: #4338ca; }
.btn-primary:disabled { background: #a5b4fc; cursor: not-allowed; }
.btn-outline { background: #fff; border: 1px solid #ddd; color: #333; }
.btn-sm { padding: .35rem .8rem; font-size: .8rem; }
.error-msg { color: #dc2626; font-size: .8rem; margin-top: .5rem; }

/* Layout */
.header { background: #1a1a2e; color: #fff; padding: .8rem 1.5rem; display: flex; align-items: center; justify-content: space-between; }
.header h1 { font-size: 1.1rem; }
.header-right { display: flex; align-items: center; gap: 1rem; font-size: .85rem; }
.container { max-width: 1280px; margin: 0 auto; padding: 1.5rem; }

/* Banner */
.estimated-banner { background: #fef3c7; border: 1px solid #f59e0b; border-radius: 8px; padding: .6rem 1rem; font-size: .85rem; color: #92400e; margin-bottom: 1rem; }

/* Search */
.search-bar { background: #fff; border-radius: 12px; padding: 1.2rem; box-shadow: 0 1px 4px rgba(0,0,0,.06); margin-bottom: 1.5rem; }
.search-row { display: flex; gap: .8rem; flex-wrap: wrap; align-items: flex-end; }
.chip-input-wrap { flex: 1; min-width: 280px; }
.chip-input { display: flex; flex-wrap: wrap; gap: .4rem; border: 1px solid #ddd; border-radius: 8px; padding: .4rem; min-height: 42px; cursor: text; }
.chip { background: #e0e7ff; color: #3730a3; padding: .2rem .6rem; border-radius: 16px; font-size: .8rem; display: flex; align-items: center; gap: .3rem; }
.chip .remove { cursor: pointer; font-weight: bold; }
.chip-input input { border: none; outline: none; flex: 1; min-width: 120px; font-size: .9rem; padding: .2rem; }
.filter-group select { padding: .5rem .8rem; border: 1px solid #ddd; border-radius: 8px; font-size: .85rem; }
.search-extra { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid #f1f5f9; }
.search-extra-label { font-size: .75rem; font-weight: 600; color: #555; margin-bottom: .4rem; }
.history-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.history-chip { background: #f8fafc; border: 1px solid #e2e8f0; padding: .2rem .55rem; border-radius: 14px; font-size: .75rem; cursor: pointer; }
.history-chip:hover { background: #e0e7ff; border-color: #a5b4fc; }
.history-chip.watch { background: #fef3c7; border-color: #fcd34d; }
.hint { color: #94a3b8; font-size: .75rem; font-weight: 400; }
.star-btn { background: none; border: none; cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 .2rem; }
.star-btn.on { filter: saturate(1.2); }

/* KPI */
.kpi-with-spark { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.kpi-main { flex: 1; }
.kpi-spark { width: 100px; flex-shrink: 0; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card { background: #fff; border-radius: 12px; padding: 1.2rem; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.kpi-card .label { font-size: .75rem; color: #666; text-transform: uppercase; letter-spacing: .05em; }
.kpi-card .value { font-size: 1.6rem; font-weight: 700; margin: .3rem 0; }
.kpi-card .sub { font-size: .8rem; color: #666; }
.kpi-card .up { color: #16a34a; }
.kpi-card .down { color: #dc2626; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.status-green { background: #16a34a; }
.status-yellow { background: #f59e0b; }
.status-red { background: #dc2626; }

/* Section */
.section { background: #fff; border-radius: 12px; padding: 1.2rem; box-shadow: 0 1px 4px rgba(0,0,0,.06); margin-bottom: 1.5rem; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.section-header h2 { font-size: 1rem; font-weight: 700; }
.section-note { font-size: .75rem; color: #888; margin-top: .2rem; }

/* Table */
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th { background: #f8fafc; text-align: left; padding: .6rem .8rem; border-bottom: 2px solid #e2e8f0; font-weight: 600; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: #eef2ff; }
th.sort-asc::after { content: ' ▲'; font-size: .65rem; }
th.sort-desc::after { content: ' ▼'; font-size: .65rem; }
td { padding: .6rem .8rem; border-bottom: 1px solid #f1f5f9; }
.spark-cell canvas { display: block; }
.badge-hot { background: #fee2e2; color: #b91c1c; }
.badge-rising { background: #ffedd5; color: #c2410c; }
.badge-opportunity { background: #d1fae5; color: #047857; }
.timing-badge { background: #eff6ff; border: 1px solid #93c5fd; color: #1e40af; padding: .6rem 1rem; border-radius: 8px; font-size: .85rem; margin-bottom: 1rem; }
.ratio-above { color: #16a34a; font-weight: 600; }
.ratio-below { color: #dc2626; }
.toolbar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.toolbar-label { font-size: .8rem; display: flex; align-items: center; gap: .3rem; }
.chart-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .6rem; }
.chart-filters { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; font-size: .8rem; }
.chart-filters select { padding: .3rem .5rem; border: 1px solid #ddd; border-radius: 6px; font-size: .8rem; }
.heatmap-wrap { overflow-x: auto; }
.heatmap-table { border-collapse: collapse; font-size: .7rem; }
.heatmap-table th, .heatmap-table td { padding: .35rem .4rem; text-align: center; border: 1px solid #f1f5f9; min-width: 28px; }
.heatmap-table th { background: #f8fafc; font-weight: 600; }
.heatmap-cell { border-radius: 3px; }
tr:hover td { background: #f8fafc; }
.badge { display: inline-block; padding: .15rem .5rem; border-radius: 12px; font-size: .7rem; font-weight: 600; }
.badge-new { background: #dbeafe; color: #1d4ed8; }
.badge-long { background: #d1fae5; color: #065f46; }
.badge-normal { background: #f3f4f6; color: #374151; }
.comp-low { color: #16a34a; }
.comp-mid { color: #f59e0b; }
.comp-high { color: #dc2626; }

/* Chart */
.chart-wrap { position: relative; height: 320px; }
.chart-tabs { display: flex; gap: .4rem; margin-bottom: .8rem; }
.chart-tab { padding: .3rem .8rem; border: 1px solid #ddd; border-radius: 6px; font-size: .8rem; cursor: pointer; background: #fff; }
.chart-tab.active { background: #4f46e5; color: #fff; border-color: #4f46e5; }

.ratio-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.no-data { text-align: center; padding: 2rem; color: #888; font-size: .9rem; }

/* Loading */
.loading-overlay { display: none; position: fixed; inset: 0; background: rgba(255,255,255,.7); z-index: 100; align-items: center; justify-content: center; flex-direction: column; gap: .8rem; }
.loading-overlay.show { display: flex; }
.spinner { width: 40px; height: 40px; border: 3px solid #e0e7ff; border-top-color: #4f46e5; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

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

.field-label { font-size: .8rem; font-weight: 600; margin-bottom: .4rem; display: block; }
.sub-title { font-size: .9rem; margin-bottom: .5rem; }
.header-btn { color: #fff !important; border-color: #555 !important; background: transparent !important; }
.custom-date-row { margin-top: .8rem; }
.custom-date-row input[type=date] { padding: .5rem .8rem; border: 1px solid #ddd; border-radius: 8px; font-size: .85rem; }

.memo-panel { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid #f1f5f9; }
.memo-form { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.memo-form input { padding: .4rem .6rem; border: 1px solid #ddd; border-radius: 6px; font-size: .85rem; }
.memo-list { display: flex; flex-direction: column; gap: .35rem; }
.memo-item { font-size: .85rem; padding: .4rem .6rem; background: #f8fafc; border-radius: 6px; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

/* Admin */
.admin-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.admin-form input, .admin-form select { padding: .4rem .6rem; border: 1px solid #ddd; border-radius: 6px; font-size: .85rem; }
.api-status-grid { display: flex; gap: .6rem; flex-wrap: wrap; }
.api-pill { padding: .5rem 1rem; border-radius: 8px; font-size: .85rem; font-weight: 600; }
.api-pill.ok { background: #d1fae5; color: #065f46; }
.api-pill.fail { background: #fee2e2; color: #991b1b; }

/* Dark mode */
body.dark-mode { background: #0f172a; color: #e2e8f0; }
body.dark-mode .section, body.dark-mode .search-bar, body.dark-mode .kpi-card, body.dark-mode .login-box { background: #1e293b; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
body.dark-mode th { background: #334155; border-color: #475569; }
body.dark-mode td { border-color: #334155; }
body.dark-mode tr:hover td { background: #334155; }
body.dark-mode .chip { background: #312e81; color: #c7d2fe; }
body.dark-mode .chip-input, body.dark-mode .filter-group select, body.dark-mode .chart-filters select,
body.dark-mode .memo-form input, body.dark-mode .admin-form input { background: #0f172a; color: #e2e8f0; border-color: #475569; }
body.dark-mode .chart-tab { background: #1e293b; color: #e2e8f0; border-color: #475569; }
body.dark-mode .chart-tab.active { background: #4f46e5; }
body.dark-mode .estimated-banner { background: #422006; border-color: #b45309; color: #fde68a; }
body.dark-mode .history-chip { background: #334155; border-color: #475569; color: #e2e8f0; }
body.dark-mode .btn-outline { background: #1e293b; color: #e2e8f0; border-color: #475569; }
body.dark-mode .loading-overlay { background: rgba(15,23,42,.85); }
body.dark-mode .ai-insight { color: #e2e8f0; }
body.dark-mode .ai-insight h1, body.dark-mode .ai-insight h2 { color: #a5b4fc; }
body.dark-mode .ai-insight strong { color: #e0e7ff; }
body.dark-mode .ai-insight blockquote { background: #334155; border-color: #6366f1; color: #cbd5e1; }

/* AI 인사이트 */
.ai-insight-wrap { padding: 0; }
.ai-insight-wrap.no-data { text-align: center; padding: 2rem; color: #888; }
.ai-insight { font-size: .92rem; line-height: 1.75; color: #1e293b; max-width: 900px; }
.ai-insight h1 { font-size: 1.25rem; margin: 0 0 1rem; padding-bottom: .5rem; border-bottom: 2px solid #e0e7ff; color: #312e81; }
.ai-insight h2 { font-size: 1.05rem; margin: 1.4rem 0 .6rem; color: #3730a3; }
.ai-insight h3 { font-size: .95rem; margin: 1rem 0 .4rem; color: #4338ca; }
.ai-insight p { margin: .5rem 0 .8rem; }
.ai-insight ul, .ai-insight ol { margin: .4rem 0 1rem 1.2rem; }
.ai-insight li { margin-bottom: .55rem; }
.ai-insight li::marker { color: #6366f1; }
.ai-insight strong { color: #1e1b4b; font-weight: 600; }
.ai-insight blockquote {
  margin: .8rem 0; padding: .75rem 1rem; background: #f8fafc;
  border-left: 4px solid #4f46e5; border-radius: 0 8px 8px 0; color: #475569; font-size: .88rem;
}
.ai-insight hr { border: none; border-top: 1px solid #e2e8f0; margin: 1.2rem 0; }
.ai-insight em { color: #64748b; font-size: .85rem; }

/* Print / PDF */
@media print {
  .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .section { box-shadow: none; border: 1px solid #ddd; page-break-inside: avoid; margin-bottom: 1rem; }
  .chart-wrap { height: 260px; }
  .container { max-width: 100%; padding: 0; }
}
