/* ─── Reset & Variables ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f0f2f5;
    --surface: #ffffff;
    --surface2: #f7f8fa;
    --border: #e2e5ed;
    --text: #1a1d2e;
    --text2: #6b7280;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-bg: rgba(79, 70, 229, .08);
    --success: #059669;
    --success-bg: rgba(5, 150, 105, .08);
    --warn: #d97706;
    --warn-bg: rgba(217, 119, 6, .08);
    --danger: #dc2626;
    --danger-bg: rgba(220, 38, 38, .08);
    --info: #2563eb;
    --info-bg: rgba(37, 99, 235, .08);
    --radius: 14px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html { font-size: 14px; }

/* 인증 전 페이지 완전 숨김 - JS 인증 통과 후 .authed 클래스 추가 시 표시 */
html:not(.authed) body { visibility: hidden !important; }
html:not(.authed).login-page body { visibility: visible !important; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }

/* ─── Navbar ───────────────────────────────────────────── */
.navbar {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px; height: 56px;
    position: sticky; top: 0; z-index: 100;
    box-shadow: var(--shadow-sm);
}
.nav-brand {
    font-size: 1.15rem; font-weight: 700; color: var(--text);
    display: flex; align-items: center; gap: 8px;
}
.nav-brand i { color: var(--primary); font-size: 1.3rem; }
.nav-right { display: flex; align-items: center; gap: 16px; }
.nav-link {
    color: var(--text2); font-size: .9rem; padding: 6px 12px;
    border-radius: var(--radius-sm); transition: .2s;
}
.nav-link:hover { color: var(--text); background: var(--surface2); }
.nav-user {
    display: flex; align-items: center; gap: 8px;
    font-size: .9rem; color: var(--text2);
}
.nav-btn {
    background: transparent; border: 1px solid var(--border);
    color: var(--text2); padding: 6px 14px; border-radius: var(--radius-sm);
    cursor: pointer; font-size: .85rem; transition: .2s; font-family: var(--font);
}
.nav-btn:hover { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }

@media (max-width: 600px) {
    .navbar { padding: 0 12px; height: auto; min-height: 48px; flex-wrap: wrap; gap: 6px; padding-top: 8px; padding-bottom: 8px; }
    .nav-brand { font-size: 1rem; }
    .nav-brand i { font-size: 1.1rem; }
    .nav-right { gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
    .nav-link { font-size: .75rem; padding: 4px 8px; }
    .nav-link i { display: none; }
    .nav-user { font-size: .75rem; gap: 4px; }
    .nav-user i { display: none; }
    .nav-btn { font-size: .75rem; padding: 4px 10px; }
}

/* ─── Badges ───────────────────────────────────────────── */
.badge {
    font-size: .7rem; padding: 2px 8px; border-radius: 20px;
    font-weight: 600; display: inline-block;
}
.badge-primary { background: var(--primary-bg); color: var(--primary); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }

/* ─── Buttons ──────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 20px; border-radius: var(--radius-sm);
    font-weight: 600; font-size: .9rem; cursor: pointer;
    border: none; transition: .2s; font-family: var(--font);
    background: var(--surface2); color: var(--text2);
}
.btn:hover { background: var(--border); color: var(--text); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: .85; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn-outline {
    background: transparent; border: 1px solid var(--border); color: var(--text2);
}
.btn-outline:hover { background: var(--surface2); color: var(--text); }
.btn-dashed {
    background: transparent; border: 2px dashed var(--border); color: var(--text2);
}
.btn-dashed:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon {
    width: 32px; height: 32px; padding: 0; justify-content: center;
    border-radius: 8px; font-size: .9rem;
}

/* ─── Login ────────────────────────────────────────────── */
.login-wrapper {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 24px;
    background: linear-gradient(135deg, #f0f2f5 0%, #e8eaf0 100%);
}
.login-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 40px; width: 100%; max-width: 400px;
    box-shadow: var(--shadow);
}
.login-icon {
    text-align: center; font-size: 2.5rem; color: var(--primary); margin-bottom: 8px;
}
.login-title { text-align: center; font-size: 1.5rem; font-weight: 800; margin-bottom: 4px; color: var(--text); }
.login-sub { text-align: center; color: var(--text2); margin-bottom: 24px; }

/* ─── Forms ────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-size: .85rem; font-weight: 600;
    color: var(--text2); margin-bottom: 6px;
}
.input-icon { position: relative; }
.input-icon i {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    color: var(--text2); font-size: 1rem;
}
.input-icon input { padding-left: 38px; }

input[type="text"], input[type="password"], input[type="date"],
input[type="number"], select, textarea {
    width: 100%; padding: 10px 14px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text);
    font-size: .9rem; font-family: var(--font);
    transition: border-color .2s;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}
textarea { resize: vertical; min-height: 60px; }
select { cursor: pointer; }

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

.error-msg {
    background: var(--danger-bg); color: var(--danger);
    padding: 10px 14px; border-radius: var(--radius-sm);
    font-size: .85rem; margin-bottom: 12px;
}

/* ─── Layout (Doctor Page) ────────────────────────────── */
.layout {
    display: grid; grid-template-columns: 380px 1fr; gap: 0;
    min-height: calc(100vh - 56px);
}
.panel-left {
    border-right: 1px solid var(--border);
    background: var(--surface);
    display: flex; flex-direction: column;
    overflow-y: auto; max-height: calc(100vh - 56px);
}
.panel-right {
    padding: 24px;
    overflow-y: auto; max-height: calc(100vh - 56px);
    background: var(--bg);
}
.mobile-back { display: none; }

@media (max-width: 900px) {
    .layout { grid-template-columns: 1fr; min-height: auto; }
    .panel-left { max-height: calc(100vh - 48px); border-right: none; border-bottom: none; }
    .panel-right { display: none; }
    .layout.patient-selected .panel-left { display: none; }
    .layout.patient-selected .panel-right { display: block; }
    .mobile-back { display: inline-flex; }
}

/* ─── Card ─────────────────────────────────────────────── */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.panel-left .card { border: none; border-radius: 0; border-bottom: 1px solid var(--border); box-shadow: none; }

.card-head {
    padding: 14px 20px; font-weight: 700; font-size: .95rem;
    display: flex; align-items: center; gap: 8px;
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
}
.card-head.accent { background: var(--primary-bg); color: var(--primary); }
.card-head i { font-size: 1.1rem; }
.card-body { padding: 16px 20px; }
.card-foot { padding: 12px 20px; border-top: 1px solid var(--border); }
.card-title {
    font-size: 1.1rem; font-weight: 700; margin-bottom: 16px;
    display: flex; align-items: center; gap: 8px;
}
.card-title i { color: var(--primary); }

/* ─── Upload ───────────────────────────────────────────── */
.file-input-wrap {
    display: flex; gap: 8px; align-items: center;
}
.file-input-wrap input[type="file"] {
    flex: 1; font-size: .85rem;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 8px 12px;
    color: var(--text2);
}

/* ─── Patient Search ───────────────────────────────────── */
.patient-search {
    position: relative; padding: 8px 12px;
    border-bottom: 1px solid var(--border); background: var(--surface);
}
.patient-search i {
    position: absolute; left: 22px; top: 50%; transform: translateY(-50%);
    color: var(--text2); font-size: .85rem;
}
.patient-search input {
    width: 100%; padding: 8px 12px 8px 32px;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 20px; font-size: .82rem; color: var(--text);
}
.patient-search input:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-bg);
}

/* ─── Patient List ─────────────────────────────────────── */
.patient-list { flex: 1; overflow-y: auto; min-height: 0; }
.patient-item {
    padding: 12px 20px; border-bottom: 1px solid var(--border);
    cursor: pointer; transition: .15s;
}
.patient-item:hover { background: var(--surface2); }
.patient-item.active { background: var(--primary-bg); border-left: 3px solid var(--primary); }
.patient-item.done { opacity: .45; }
.patient-row { display: flex; align-items: center; gap: 8px; }
.patient-row.sub { margin-top: 4px; font-size: .8rem; color: var(--text2); }
.patient-name { font-weight: 700; font-size: .95rem; }
.patient-chart { color: var(--text2); font-size: .82rem; }
.patient-age { color: var(--text2); font-size: .82rem; }
.done-icon { color: var(--success); margin-left: auto; }

/* ─── Current Time Line ───────────────────────────────── */
.time-now-line {
    position: relative;
    display: flex; align-items: center; justify-content: center;
    padding: 0; height: 24px;
}
.time-now-line::before {
    content: ''; position: absolute; left: 0; right: 0; top: 50%;
    border-top: 2px solid var(--danger);
}
.time-now-line span {
    position: relative; z-index: 1;
    background: var(--surface); color: var(--danger);
    font-size: .7rem; font-weight: 700;
    padding: 1px 10px; border-radius: 10px;
    border: 1.5px solid var(--danger);
}

/* ─── Procedure Card ───────────────────────────────────── */
.proc-card {
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: 12px;
    transition: .2s;
}
.proc-card.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-bg); }
.proc-head {
    padding: 14px 18px; display: flex; align-items: center; gap: 12px;
}
.proc-name { font-weight: 700; font-size: 1rem; }
.proc-body { padding: 0 18px 18px; }

.param-set + .param-set { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.set-header { display: flex; align-items: center; margin-bottom: 8px; }
.param-group { display: flex; flex-direction: column; gap: 12px; }
.param-label { font-size: .8rem; font-weight: 600; color: var(--text2); margin-bottom: 6px; }

.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { position: relative; cursor: pointer; }
.pill input { position: absolute; opacity: 0; width: 0; height: 0; }
.pill span {
    display: inline-block; padding: 6px 14px; border-radius: 20px;
    background: var(--surface); border: 1px solid var(--border);
    font-size: .82rem; transition: .2s; user-select: none;
    color: var(--text2);
}
.pill input:checked + span {
    background: var(--primary-bg); border-color: var(--primary);
    color: var(--primary); font-weight: 600;
}
.pill:hover span { border-color: var(--primary); }

/* Toggle Switch */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; inset: 0; background: var(--border); border-radius: 24px;
    cursor: pointer; transition: .3s;
}
.toggle-slider::before {
    content: ''; position: absolute; width: 18px; height: 18px;
    left: 3px; bottom: 3px; background: #fff; border-radius: 50%;
    transition: .3s; box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ─── Age Input in Procedure Form ──────────────────────── */
.age-input-wrap {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 16px; padding: 12px 16px;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.age-input-wrap label { font-weight: 600; font-size: .9rem; color: var(--text2); white-space: nowrap; margin: 0; }
.age-input-wrap input {
    width: 80px; text-align: center; font-weight: 700; font-size: 1rem;
}
.age-input-wrap span { font-size: .85rem; color: var(--text2); }

/* ─── Form Actions ─────────────────────────────────────── */
.form-actions { margin-top: 20px; }

/* ─── Empty State ──────────────────────────────────────── */
.empty {
    text-align: center; padding: 48px 24px; color: var(--text2);
}
.empty i { font-size: 2.5rem; display: block; margin-bottom: 12px; opacity: .4; }

/* ─── Modal ────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.35);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000; padding: 24px; opacity: 0; visibility: hidden;
    transition: .2s; backdrop-filter: blur(2px);
}
.modal-overlay.show { opacity: 1; visibility: visible; }
.modal {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); width: 100%; max-width: 520px;
    max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow);
    transform: translateY(20px); transition: .2s;
}
.modal-overlay.show .modal { transform: translateY(0); }
.modal-head {
    padding: 18px 24px; font-size: 1.05rem; font-weight: 700;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border);
}
.modal-head.accent { background: var(--primary-bg); color: var(--primary); }
.modal-close {
    background: none; border: none; color: var(--text2);
    font-size: 1.4rem; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px 24px; }
.modal-foot {
    padding: 14px 24px; display: flex; justify-content: flex-end;
    gap: 8px; border-top: 1px solid var(--border);
    align-items: center;
}

/* Guide */
.guide-step {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 12px 0; border-bottom: 1px solid var(--border);
}
.guide-step:last-child { border-bottom: none; }
.step-num {
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--primary); color: #fff; font-size: .8rem;
    font-weight: 700; display: flex; align-items: center;
    justify-content: center; flex-shrink: 0;
}
.check-label {
    display: flex; align-items: center; gap: 6px; margin-right: auto;
    font-size: .85rem; color: var(--text2); cursor: pointer;
}

/* ─── Toast ────────────────────────────────────────────── */
.app-toast {
    position: fixed; bottom: 24px; right: 24px;
    padding: 14px 24px; border-radius: var(--radius-sm);
    font-size: .9rem; font-weight: 600; z-index: 2000;
    transform: translateY(20px); opacity: 0; transition: .3s;
    display: flex; align-items: center; gap: 8px;
    box-shadow: var(--shadow);
}
.app-toast.show { transform: translateY(0); opacity: 1; }
.app-toast.success { background: #059669; color: #fff; }
.app-toast.error { background: #dc2626; color: #fff; }

/* ─── Container ────────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 24px; }

/* ─── Stats Cards ─────────────────────────────────────── */
.stat-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px; margin-bottom: 24px;
}
.stat-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px;
    display: flex; align-items: center; gap: 16px;
    box-shadow: var(--shadow-sm);
}
.stat-icon {
    width: 50px; height: 50px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem; flex-shrink: 0;
}
.stat-icon.purple { background: var(--primary-bg); color: var(--primary); }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.orange { background: var(--warn-bg); color: var(--warn); }
.stat-icon.blue { background: var(--info-bg); color: var(--info); }
.stat-value { font-size: 1.8rem; font-weight: 800; line-height: 1; }
.stat-label { font-size: .8rem; color: var(--text2); margin-top: 2px; }

/* ─── Tabs ─────────────────────────────────────────────── */
.tabs {
    display: flex; gap: 4px; margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
}
.tab-btn {
    padding: 10px 20px; background: none; border: none;
    color: var(--text2); font-size: .9rem; font-weight: 600;
    cursor: pointer; border-bottom: 2px solid transparent;
    transition: .2s; font-family: var(--font);
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-btn:hover { color: var(--text); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── Table ────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto; border-radius: var(--radius);
    border: 1px solid var(--border); background: var(--surface);
}
table { width: 100%; border-collapse: collapse; }
th, td {
    padding: 8px 10px; text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: .8rem; white-space: nowrap;
}
th {
    background: var(--surface2); color: var(--text2);
    font-weight: 600; font-size: .78rem; text-transform: uppercase;
    position: sticky; top: 0;
}
tr:hover td { background: var(--primary-bg); }

/* ─── Search Bar ───────────────────────────────────────── */
.search-bar {
    display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap;
    align-items: center;
}
.search-bar input, .search-bar select { flex: 1; min-width: 150px; }

/* ─── Chart ────────────────────────────────────────────── */
.chart-wrap {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 24px; margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}
.chart-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 24px;
}
@media (max-width: 900px) {
    .chart-grid { grid-template-columns: 1fr; }
}

/* ─── Row Actions ──────────────────────────────────────── */
td:last-child, th:last-child {
    position: sticky; right: 0; background: var(--surface);
    box-shadow: -2px 0 4px rgba(0,0,0,.05);
}
th:last-child { background: var(--surface2); }
.row-actions { display: flex; gap: 4px; }

/* ─── Misc ─────────────────────────────────────────────── */
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.text-center { text-align: center; }
.text-muted { color: var(--text2); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }
