/* ============================================================
   수업용 종목 추천 — DTW 종목추천 시스템의 디자인 언어를 이식(팔레트는 연두 계열).
   토큰·타이포·테이블·카드·버튼 규격을 dtw/system.html 에서 그대로 가져왔다.
   (dtw 는 단일 파일 SPA, 이쪽은 Flask 다중 페이지라 라우팅만 다르게 처리)
   ============================================================ */

:root {
    /* 포근한 연두.
       - 색상을 순수 초록(≈85°)에서 노랑 쪽(≈72°)으로 당겨 날카로움을 뺐다.
       - 채도를 낮추고 회색기를 섞어 형광 느낌을 없앴다.
       - 셋 다 같은 색상 위 명도 사다리: surface2 < bg < surface.
         (카드를 순수 흰색으로 두면 배경의 연두와 어긋나 카드만 떠 보인다.) */
    --bg:      #f6f8e7;   /* 페이지 바탕 */
    --surface: #fcfdf4;   /* 카드 — 바탕보다 밝게 */
    --surface2:#eaefd7;   /* 표 헤더·칩 — 바탕보다 어둡게 */
    --border:  rgba(96,100,66,0.11);
    --border2: rgba(96,100,66,0.18);
    --accent:  #6f8c4c;   /* 올리브 쪽으로 옮긴 부드러운 연두 */
    --danger:  #b94040;
    --text:    #2f3128;   /* 따뜻한 먹색 */
    --text2:   #5f6154;
    --text3:   #9d9f8d;
    --ok:      #2e7d56;
    /* 한글은 JetBrains Mono 에 없음 → Pretendard 폴백(시스템 임의 폰트 방지) */
    --mono:    'JetBrains Mono', 'Pretendard', monospace;
    --sans:    'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* 스크롤바 유무로 폭이 흔들리지 않게 항상 표시 */
html { zoom: 1.15; overflow-y: scroll; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 13px;
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;   /* iOS: 100vh 는 주소창을 포함한 높이라 실제보다 크다 */
    display: flex;
}

a { color: var(--accent); text-decoration: none; }
a:hover { opacity: .8; }

/* ─────────────────────────── 사이드바 ─────────────────────────── */

.sidebar {
    width: 222px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 0.5px solid var(--border2);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-logo {
    padding: 22px 18px 18px;
    border-bottom: 0.5px solid var(--border);
}
.sidebar-logo-title {
    font-size: 14px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.02em;
    display: block;
}
.sidebar-logo-sub {
    font-size: 10px;
    color: var(--text3);
    margin-top: 3px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text3);
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--surface2); color: var(--text2); opacity: 1; }
.nav-item.active {
    background: var(--surface2);
    color: var(--accent);
    font-weight: 800;
}
.nav-icon { font-size: 15px; font-weight: 800; opacity: .7; line-height: 1; width: 18px; text-align: center; }

.nav-section-label {
    font-size: 10px;
    font-weight: 800;
    color: var(--text3);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 14px 12px 4px;
    cursor: default;
}

.sidebar-foot { margin-top: auto; padding: 12px 8px 16px; }
.btn-logout {
    width: 100%;
    display: flex; align-items: center; gap: 8px;
    padding: 9px 10px; border-radius: 8px; border: none;
    background: transparent; color: var(--danger);
    font-family: var(--sans); font-size: 12px; font-weight: 600;
    cursor: pointer; text-align: left; transition: background 0.12s;
}
.btn-logout:hover { background: rgba(185,64,64,0.07); opacity: 1; }
.sidebar-who {
    font-size: 10px; color: var(--text3);
    padding: 0 12px 8px;
}
.sidebar-who b { color: var(--text2); font-weight: 700; }

/* ─────────────────────────── 본문 ─────────────────────────── */

.content {
    margin-left: 222px;
    flex: 1;
    padding: 28px 24px 40px;
    min-width: 0;
}
.page { display: flex; flex-direction: column; gap: 16px; max-width: 1160px; }

.top-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    background: var(--surface);
    border: 0.5px solid var(--border2);
    border-radius: 16px;
    padding: 14px 22px;
    box-shadow: 0 2px 8px rgba(96,100,66,0.05);
}
.header-title { font-size: 16px; font-weight: 800; color: var(--text); letter-spacing: -0.02em; }
.header-sub   { font-size: 11px; color: var(--text3); margin-top: 2px; }
.header-date  { font-size: 11px; color: var(--text3); font-family: var(--mono); white-space: nowrap; }

/* ─────────────────────────── 카드 ─────────────────────────── */

.card {
    background: var(--surface);
    border: 0.5px solid var(--border2);
    border-radius: 14px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.card-head {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: 10px; flex-wrap: wrap;
}
.card-head h2 { font-size: 13px; font-weight: 800; letter-spacing: -0.01em; }
.card-sub { font-size: 11px; color: var(--text3); font-family: var(--mono); }

.grid-two {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 288px;
    gap: 16px;
    align-items: start;
}
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.empty-card {
    background: var(--surface);
    border: 0.5px dashed var(--border2);
    border-radius: 14px;
    padding: 36px 20px;
    text-align: center;
}
.empty-card h2 { font-size: 14px; font-weight: 800; margin-bottom: 5px; }
.empty-card p { font-size: 11px; color: var(--text3); }

.muted { color: var(--text3); }
.small { font-size: 11px; }
.mono  { font-family: var(--mono); }

/* ─────────────────────────── 플래시 ─────────────────────────── */

.flash-stack { display: flex; flex-direction: column; gap: 7px; margin-bottom: 4px; }
.flash {
    padding: 10px 14px; border-radius: 10px;
    font-size: 12px; font-weight: 600;
    border: 0.5px solid var(--border2);
    background: var(--surface2); color: var(--text2);
}
.flash-success { background: rgba(46,125,86,0.08); color: var(--ok);     border-color: rgba(46,125,86,0.25); }
.flash-error   { background: rgba(185,64,64,0.07); color: var(--danger); border-color: rgba(185,64,64,0.28); }

/* ─────────────────────────── 주차 탭 ─────────────────────────── */

.week-tabs {
    display: flex; gap: 6px; overflow-x: auto;
    padding-bottom: 4px;
}
.tab {
    flex: 0 0 auto;
    background: var(--surface);
    border: 0.5px solid var(--border2);
    border-radius: 9px;
    padding: 7px 12px;
    color: var(--text2);
    display: flex; flex-direction: column; gap: 1px;
    transition: border-color .12s, background .12s;
}
.tab:hover { background: var(--surface2); opacity: 1; }
.tab-label { font-weight: 700; font-size: 12px; }
.tab-date { font-size: 10px; color: var(--text3); font-family: var(--mono); white-space: nowrap; }
.tab-active { border-color: var(--accent); background: var(--surface2); }
.tab-active .tab-label { color: var(--accent); font-weight: 800; }

/* ─────────────────────────── 테이블 ─────────────────────────── */

.lb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.lb-table th, .lb-table td {
    border-bottom: 0.5px solid var(--border);
    padding: 7px 10px;
    text-align: left;
    vertical-align: middle;
}
.lb-table th {
    font-size: 10px;
    font-weight: 800;
    color: var(--text3);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: var(--surface2);
    white-space: nowrap;
}
.lb-table th:first-child { border-top-left-radius: 8px; }
.lb-table th:last-child  { border-top-right-radius: 8px; }
.lb-table tbody tr:last-child td { border-bottom: none; }
.lb-table td.num, .lb-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.lb-table tr.active-row td { background: var(--surface2); }
.table-wrap { overflow-x: auto; border-radius: 8px; border: 0.5px solid var(--border); }

/* 순위 (dtw 메달 색) */
.rank-cell {
    width: 34px; text-align: center;
    font-family: var(--mono); font-weight: 800; font-size: 12px;
    color: var(--text3);
}
.rank-cell.gold   { color: #b8860b; font-size: 13px; }
.rank-cell.silver { color: #808080; font-size: 13px; }
.rank-cell.bronze { color: #a0522d; font-size: 13px; }

.lb-name-cell { font-weight: 700; color: var(--text); font-size: 12px; }

/* 수익률 — 한국 시장 관례: 빨강 = 상승, 파랑 = 하락 */
.ret-pos  { color: #c0392b; font-weight: 700; font-family: var(--mono); }
.ret-neg  { color: #2980b9; font-weight: 700; font-family: var(--mono); }
.ret-zero { color: var(--text3); font-family: var(--mono); }

.lb-code { font-family: var(--mono); font-weight: 700; color: var(--text); font-size: 12px; }
.lb-name-pick { font-size: 10px; color: var(--text3); font-weight: 500; margin-top: 1px; }
.lb-price { font-family: var(--mono); color: var(--text2); font-size: 11px; }

.type-badge { display: inline-block; padding: 2px 7px; border-radius: 4px; font-size: 10px; font-weight: 800; }
.badge-ok   { background: rgba(46,125,86,0.10);  color: var(--ok); }
.badge-err  { background: rgba(185,64,64,0.10);  color: var(--danger); }
.badge-miss { background: var(--surface2);       color: var(--text3); }

/* ─────────────────────────── 버튼 ─────────────────────────── */

.btn-all {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 9px;
    padding: 10px 22px;
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
}
.btn-all:hover  { opacity: 0.88; }
.btn-all:active { transform: scale(0.97); }
.btn-all:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-cancel {
    background: var(--surface2); color: var(--text2); border: none;
    border-radius: 9px; padding: 9px 18px; font-family: var(--sans);
    font-size: 12px; font-weight: 700; cursor: pointer; transition: opacity 0.15s;
}
.btn-cancel:hover { opacity: 0.8; }

.btn-sm {
    border-radius: 5px; padding: 4px 9px; font-family: var(--sans);
    font-size: 10px; font-weight: 800; cursor: pointer; transition: opacity 0.15s;
    border: 0.5px solid; background: transparent;
}
.btn-sm:hover { opacity: 0.75; }
.btn-edit { color: var(--accent); border-color: rgba(111,140,76,0.30); background: rgba(111,140,76,0.10); }
.btn-del  { color: var(--danger); border-color: rgba(185,64,64,0.30);  background: rgba(185,64,64,0.06); }
.btn-ghost {
    color: var(--text2); border-color: var(--border2); background: var(--surface);
    border-radius: 8px; padding: 7px 12px; font-size: 11px; font-weight: 700;
    border-width: 0.5px; border-style: solid; cursor: pointer; font-family: var(--sans);
    display: inline-flex; align-items: center; gap: 5px; transition: background .12s;
}
.btn-ghost:hover { background: var(--surface2); opacity: 1; }

/* ─────────────────────────── 폼 ─────────────────────────── */

.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.form-label { font-size: 11px; font-weight: 700; color: var(--text2); }
.form-input {
    width: 100%; padding: 9px 12px;
    border: 0.5px solid var(--border2); border-radius: 8px;
    font-family: var(--sans); font-size: 12px; background: var(--bg);
    color: var(--text); outline: none; transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--accent); }
textarea.form-input { resize: vertical; min-height: 140px; font-family: var(--mono); font-size: 11.5px; line-height: 1.65; }
.form-sep { height: 0.5px; background: var(--border); margin: 14px 0; }
.input-btn-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.input-btn-row .form-row { flex: 1; margin-bottom: 0; min-width: 140px; }

.inline-edit { display: flex; gap: 5px; align-items: center; }
.inline-edit .form-input {
    padding: 4px 8px; font-family: var(--mono); font-size: 11px; width: 108px;
}

/* ─────────────────────────── 로그인 ─────────────────────────── */

.login-wrap {
    position: fixed; inset: 0; background: var(--bg);
    display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
    background: var(--surface); border: 0.5px solid var(--border2);
    border-radius: 20px; padding: 44px 48px; width: 360px; max-width: 100%;
    box-shadow: 0 8px 32px rgba(96,100,66,0.11);
}
.login-title { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 4px; }
.login-sub   { font-size: 11px; color: var(--text3); margin-bottom: 30px; }
.login-input {
    width: 100%; padding: 11px 14px;
    border: 0.5px solid var(--border2); border-radius: 9px;
    font-family: var(--sans); font-size: 13px;
    background: var(--bg); color: var(--text);
    outline: none; margin-bottom: 10px;
    transition: border-color 0.15s;
}
.login-input:focus { border-color: var(--accent); }
.btn-login {
    width: 100%; padding: 12px; background: var(--accent); color: #fff;
    border: none; border-radius: 9px; font-family: var(--sans);
    font-size: 13px; font-weight: 800; cursor: pointer; transition: opacity 0.15s;
}
.btn-login:hover { opacity: 0.88; }
.login-back { display: block; text-align: center; margin-top: 14px; font-size: 11px; color: var(--text3); }

/* ─────────────────────────── 내 등수 조회 결과 ─────────────────────────── */

.result-card {
    background: var(--surface2);
    border: 0.5px solid var(--border2);
    border-radius: 10px; padding: 11px 13px;
    display: flex; flex-direction: column; gap: 4px;
}
.result-name { font-weight: 800; font-size: 12.5px; }
.result-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; padding: 2px 0; }
.result-row.sub { font-size: 11px; color: var(--text3); padding-top: 0; margin-top: -3px; }
.result-row.hl { border-top: 0.5px solid var(--border2); padding-top: 6px; margin-top: 4px; }
.result-row strong { font-weight: 800; font-family: var(--mono); }
.result-history { margin-top: 8px; border-top: 0.5px solid var(--border2); padding-top: 8px; }
.result-history-title {
    font-size: 10px; color: var(--text3); font-weight: 800;
    letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 6px;
}
.history-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.history-table th, .history-table td { padding: 4px 5px; text-align: left; border-bottom: 0.5px solid var(--border); }
.history-table th { color: var(--text3); font-weight: 800; font-size: 9.5px; letter-spacing: .04em; text-transform: uppercase; }
.history-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.history-table tr.missed td { color: var(--text3); }
.history-table tr:last-child td { border-bottom: none; }
.lookup-err { color: var(--danger); font-size: 11.5px; font-weight: 600; }

/* ─────────────────────────── 프롬프트 ─────────────────────────── */

.prompt-item {
    border: 0.5px solid var(--border2);
    border-radius: 10px;
    padding: 11px 13px;
    background: var(--surface2);
}
.prompt-item + .prompt-item { margin-top: 9px; }
.prompt-meta {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 7px; font-size: 11px;
}
.prompt-week { font-weight: 800; color: var(--accent); font-size: 11px; }
.prompt-body {
    white-space: pre-wrap; word-break: break-word;
    font-family: var(--mono); font-size: 11.5px; line-height: 1.6;
    background: var(--surface); border: 0.5px solid var(--border);
    border-radius: 8px; padding: 9px 11px;
    max-height: 280px; overflow: auto;
}

/* ─────────────────────────── 차트 ─────────────────────────── */

.hidden { display: none !important; }

.chart-tabs {
    display: inline-flex;
    background: var(--surface2);
    border-radius: 8px;
    padding: 2px;
    gap: 2px;
}
.chart-tab {
    padding: 4px 12px; border: none; background: transparent;
    color: var(--text3); font-size: 11px; font-weight: 700;
    cursor: pointer; border-radius: 6px; font-family: var(--sans);
    transition: background .12s, color .12s;
}
.chart-tab:hover { color: var(--text2); }
.chart-tab.is-active { background: var(--surface); color: var(--accent); font-weight: 800; }

.chart-canvas-wrap { position: relative; height: 240px; width: 100%; }
.chart-canvas-wrap canvas { width: 100% !important; height: 100% !important; }
.chart-empty {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: var(--text3); font-size: 11px;
}
.chart-legend {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 5px;
    padding-top: 10px;
    border-top: 0.5px solid var(--border);
}
.leg-item {
    display: grid; grid-template-columns: 8px 1fr auto;
    align-items: center; gap: 7px;
    padding: 5px 8px; border-radius: 7px;
    background: var(--surface2); border: 0.5px solid var(--border);
}
.leg-dot { width: 8px; height: 8px; border-radius: 999px; }
.leg-name { font-size: 11px; color: var(--text); font-weight: 700; line-height: 1.15; }
.leg-ticker { font-family: var(--mono); font-size: 10px; color: var(--text3); }
.leg-ret { font-family: var(--mono); font-size: 11px; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }

/* ─────────────────────────── 모바일 ─────────────────────────── */

.mtabbar { display: none; }

@media (max-width: 768px) {
    /* 모바일은 1배율. 전역 zoom 1.15 는 폰에서 가용 폭을 깎아먹는다. */
    html { zoom: 1; }
    body { font-size: 12px; display: block; }

    .sidebar { display: none !important; }
    .content { margin-left: 0; padding: 16px 12px 84px; }

    /* 하단 탭바 — 엄지가 닿는 위치에 주요 페이지 고정 */
    .mtabbar {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
        background: var(--surface); border-top: 0.5px solid var(--border2);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        box-shadow: 0 -2px 12px rgba(0,0,0,0.07);
    }
    .mtab {
        flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
        padding: 9px 4px 8px; border: none; background: transparent;
        color: var(--text3); font-family: var(--sans); font-size: 10px; font-weight: 700;
        cursor: pointer;
    }
    .mtab.active { color: var(--accent); font-weight: 800; }
    .mtab .mtab-ico { font-size: 16px; line-height: 1; opacity: .8; }

    .top-header { border-radius: 12px; padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
    .header-title { font-size: 15px; }

    .grid-two { grid-template-columns: 1fr; gap: 12px; }
    .stack { gap: 12px; }
    .card { border-radius: 12px; padding: 12px 13px; }

    .lb-table { font-size: 11.5px; }
    .lb-table th, .lb-table td { padding: 6px 7px; }
    .table-wrap { -webkit-overflow-scrolling: touch; }

    .chart-canvas-wrap { height: 190px; }
    .chart-legend { grid-template-columns: 1fr 1fr; }

    /* iOS 는 16px 미만 입력 필드를 탭하면 확대하고 되돌리지 않는다 */
    .form-input, .login-input, textarea.form-input { font-size: 16px !important; }
    .btn-all { width: 100%; justify-content: center; padding: 12px; }
    .login-card { padding: 32px 24px; border-radius: 16px; }
    .login-title { font-size: 20px; }
}

@media (max-width: 400px) {
    .chart-legend { grid-template-columns: 1fr; }
    .chart-canvas-wrap { height: 170px; }
}
