/* ============================================================
   Lineage Clan Manager — Modern UI Design System
   ============================================================ */
:root {
    --bg: #0f1117;
    --surface: #ffffff;
    --surface-2: #f6f7fb;
    --sidebar-bg: #14161f;
    --sidebar-hover: #1e2130;
    --sidebar-active: #6d5efc;
    --border: #e6e8ef;
    --text: #1c2030;
    --text-muted: #6b7280;
    --text-invert: #e7e9f3;
    --primary: #6d5efc;
    --primary-dark: #5847e0;
    --success: #17b26a;
    --danger: #f04438;
    --warning: #f79009;
    --info: #2e90fa;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
    --shadow-md: 0 4px 16px rgba(16, 24, 40, .08);
    --sidebar-w: 248px;
    --font: 'Segoe UI', 'Malgun Gothic', Pretendard, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    color: var(--text);
    background: var(--surface-2);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 700; }

/* ---------------- App shell ---------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--text-invert);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 40;
}

.sidebar-brand {
    display: flex; align-items: center; gap: .7rem;
    padding: 1.25rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand-emblem { font-size: 1.6rem; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 1.05rem; color: #fff; }
.brand-text span { font-size: .72rem; color: #8b90a8; letter-spacing: .05em; text-transform: uppercase; }

.sidebar-nav { flex: 1; padding: .75rem .6rem; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item {
    display: flex; align-items: center; gap: .7rem;
    padding: .65rem .8rem;
    border-radius: var(--radius-sm);
    color: #b8bcd0;
    font-weight: 500;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: #fff; box-shadow: 0 4px 12px rgba(109,94,252,.35); }
.nav-ico { font-size: 1.05rem; width: 1.3rem; text-align: center; }

.sidebar-footer {
    padding: .9rem 1rem;
    border-top: 1px solid rgba(255,255,255,.06);
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
.user-chip { font-size: .82rem; color: #b8bcd0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-form { margin: 0; }
.btn-logout {
    background: transparent; border: 1px solid rgba(255,255,255,.15); color: #b8bcd0;
    border-radius: 6px; padding: .3rem .6rem; font-size: .78rem; cursor: pointer;
}
.btn-logout:hover { background: rgba(255,255,255,.08); color: #fff; }

/* ---------------- Content ---------------- */
.content-area { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

.topbar {
    height: 64px; flex-shrink: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 1rem;
    padding: 0 1.5rem;
    position: sticky; top: 0; z-index: 30;
}
.page-title { font-size: 1.25rem; margin: 0; flex: 1; }
.topbar-actions { display: flex; gap: .5rem; align-items: center; }
.nav-hamburger { display: none; font-size: 1.4rem; cursor: pointer; }

.page-body { padding: 1.5rem; flex: 1; max-width: 1400px; width: 100%; }

/* ---------------- Cards ---------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-pad { padding: 1.25rem; }
.card + .card { margin-top: 1rem; }
/* 카드가 form 안팎으로 섞여 있어도 섹션 간 여백 유지 (예: 참여 체크 화면) */
form + .card, .card + form, form + form { margin-top: 1rem; }
.card-header {
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.card-header h2, .card-header h3 { margin: 0; font-size: 1.05rem; }

/* 2열 카드 그리드(대시보드). .card+.card 마진이 그리드 안에서 높이를 어긋나게 하므로 초기화 */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: stretch; }
.grid-2 .card { margin-top: 0; display: flex; flex-direction: column; }
.grid-2 .card .table-wrap { flex: 1; }
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; } }

/* Stat cards (dashboard) */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.stat-card .stat-label { color: var(--text-muted); font-size: .82rem; display: flex; align-items: center; gap: .4rem; }
.stat-card .stat-value { font-size: 1.9rem; font-weight: 800; margin-top: .35rem; letter-spacing: -.02em; }
.stat-card .stat-sub { font-size: .78rem; color: var(--text-muted); margin-top: .2rem; }
a.stat-link { display: block; color: inherit; }
a.stat-link:hover { text-decoration: none; border-color: var(--primary); box-shadow: var(--shadow-md); }

/* ---------------- Buttons ---------------- */
.btn {
    display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
    padding: .5rem .9rem; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    font-weight: 600; font-size: .86rem; cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.93); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: .3rem .6rem; font-size: .78rem; }
.btn-block { width: 100%; }
.btn-icon { padding: .4rem .55rem; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data th, table.data td { padding: .7rem .8rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data thead th {
    background: var(--surface-2); color: var(--text-muted);
    font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em;
    position: sticky; top: 0;
}
table.data tbody tr:hover { background: #fafbff; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .row-actions { display: flex; gap: .3rem; justify-content: flex-end; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state .emoji { font-size: 2.5rem; display: block; margin-bottom: .5rem; }

/* ---------------- Badges ---------------- */
.badge {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .18rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 700;
    background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.badge-cls-royal   { background: #fff4e5; color: #b54708; border-color: #fedf9b; }
.badge-cls-knight  { background: #eef2ff; color: #3538cd; border-color: #c7d0fe; }
.badge-cls-elf     { background: #e7f9ef; color: #067647; border-color: #a9e5c3; }
.badge-cls-mage    { background: #f3ecfe; color: #6941c6; border-color: #d9c7fb; }
.badge-cls-darkelf { background: #f2f4f7; color: #344054; border-color: #d0d5dd; }
.badge-boss { background: #fdecec; color: #b42318; border-color: #fbcfcb; }
.badge-siege { background: #eaf3ff; color: #175cd3; border-color: #b6d6fe; }
.badge-success { background: #e7f9ef; color: #067647; border-color: #a9e5c3; }
.badge-muted { background: var(--surface-2); color: var(--text-muted); }

/* ---------------- Forms ---------------- */
.form-field { margin-bottom: 1rem; }
.form-field label { display: block; font-weight: 600; font-size: .82rem; margin-bottom: .35rem; color: var(--text); }
.form-field input, .form-field select, .form-field textarea, .filter-bar input, .filter-bar select {
    width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: .88rem; font-family: inherit; background: var(--surface); color: var(--text);
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(109,94,252,.15);
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.form-actions { display: flex; gap: .6rem; margin-top: 1rem; }
.field-validation-error, .text-danger { color: var(--danger); font-size: .8rem; }
.validation-summary-errors ul { margin: 0; padding-left: 1.1rem; }

/* ---------------- Filter bar ---------------- */
.filter-bar {
    display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end;
    padding: 1rem 1.25rem; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1rem;
}
.filter-bar .filter-item { display: flex; flex-direction: column; gap: .3rem; }
.filter-bar .filter-item label { font-size: .74rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.filter-bar .filter-item input, .filter-bar .filter-item select { min-width: 140px; }
.filter-bar .spacer { flex: 1; }

/* ---------------- Alerts ---------------- */
.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: .88rem; border: 1px solid transparent; }
.alert-success { background: #e7f9ef; color: #067647; border-color: #a9e5c3; }
.alert-danger { background: #fdecec; color: #b42318; border-color: #fbcfcb; }
.alert-info { background: #eaf3ff; color: #175cd3; border-color: #b6d6fe; }

/* ---------------- Chips / toolbar ---------------- */
.toolbar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .spacer { flex: 1; }
.count-pill { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: .25rem .7rem; font-size: .8rem; color: var(--text-muted); font-weight: 600; }

/* ---------------- Modal (simple) ---------------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,17,23,.45); display: none; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-md); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; }
.modal-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 1.25rem; }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); }

/* ---------------- Login ---------------- */
.login-body {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: radial-gradient(1200px 600px at 50% -10%, #23263a 0%, #0f1117 60%);
    padding: 1rem;
}
.login-card {
    width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,.4); padding: 2.25rem 2rem;
}
.login-brand { text-align: center; margin-bottom: 1.75rem; }
.login-emblem { font-size: 2.6rem; }
.login-brand h1 { font-size: 1.4rem; margin: .5rem 0 .1rem; }
.login-brand p { color: var(--text-muted); font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; margin: 0; }

/* ---------------- Calendar ---------------- */
.cal-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.cal-title { font-size: 1.15rem; font-weight: 700; min-width: 160px; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; gap: 1px; }
.cal-dow { background: var(--surface-2); text-align: center; padding: .5rem; font-size: .78rem; font-weight: 700; color: var(--text-muted); }
.cal-dow.sun { color: #e5484d; } .cal-dow.sat { color: #2e90fa; }
.cal-cell { background: var(--surface); min-height: 108px; padding: .4rem; display: flex; flex-direction: column; gap: .25rem; }
.cal-cell.out { background: #fafbfc; }
.cal-daynum { font-size: .82rem; font-weight: 600; color: var(--text); display: flex; justify-content: space-between; align-items: center; }
.cal-cell.out .cal-daynum { color: #c1c6d0; }
.cal-cell.today .cal-daynum .d { background: var(--primary); color: #fff; border-radius: 999px; width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; }
.cal-daynum.sun .d { color: #e5484d; } .cal-daynum.sat .d { color: #2e90fa; }
.cal-add { opacity: 0; border: none; background: none; cursor: pointer; color: var(--text-muted); font-size: .95rem; line-height: 1; }
.cal-cell:hover .cal-add { opacity: 1; }
.cal-ev { font-size: .72rem; padding: .15rem .35rem; border-radius: 5px; border: 1px solid transparent; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
a.cal-ev { display: block; }
a.cal-ev:hover { text-decoration: none; filter: brightness(.94); }

/* ---------------- Utilities ---------------- */
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-sm { gap: .5rem; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mb-0 { margin-bottom: 0; }
.nav-toggle-checkbox { display: none; }

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); transition: transform .25s ease; }
    .nav-toggle-checkbox:checked ~ .app-shell .sidebar { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.4); }
    .content-area { margin-left: 0; }
    .nav-hamburger { display: inline-block; }
    .page-body { padding: 1rem; }
}

/* 모바일: 테이블을 카드형 스택으로 전환 (td의 data-label은 site.js가 부여) */
@media (max-width: 768px) {
    table.data thead { display: none; }
    table.data, table.data tbody, table.data tr, table.data td, table.data tfoot {
        display: block; width: 100%;
    }
    table.data tbody tr {
        border: 1px solid var(--border); border-radius: var(--radius-sm);
        margin: .6rem .5rem; padding: .3rem 0; background: var(--surface);
        box-shadow: var(--shadow);
    }
    table.data tbody tr:hover { background: var(--surface); }
    table.data td {
        display: flex; justify-content: space-between; align-items: center; gap: 1rem;
        border-bottom: 1px solid var(--surface-2);
        padding: .45rem .8rem; text-align: right;
    }
    table.data tr td:last-child { border-bottom: none; }
    table.data td::before {
        content: attr(data-label);
        font-weight: 600; font-size: .76rem; color: var(--text-muted);
        text-align: left; flex-shrink: 0;
    }
    table.data td:not([data-label])::before { content: none; }
    table.data td.num { text-align: right; }
    table.data td:empty { display: none; }
    table.data .row-actions { justify-content: flex-end; }
    table.data tfoot tr { display: flex; flex-wrap: wrap; gap: .5rem; padding: .5rem .8rem; }
    table.data tfoot td { display: inline-flex; border: none; padding: .2rem .4rem; }
}
