* { box-sizing: border-box; }

:root {
    --bg-page: #f4f6f9;
    --bg-card: #ffffff;
    --bg-login: #eef2f7;
    --text-1: #222222;
    --text-2: #555555;
    --text-3: #333333;
    --border-1: #ccd3dc;
    --border-2: #eef1f5;
    --border-3: #e2e6ec;
    --border-4: #f0f2f5;
    --accent: #2b5faa;
    --accent-hover: #234d8c;
    --accent-soft: #dce8ff;
    --part-bg: #e8eefa;
    --part-text: #234d8c;
    --resource-link: #6c8bbd;
    --danger: #c62828;
    --danger-bg: #fdecea;
    --muted-btn-bg: #e8ecf1;
    --muted-btn-text: #333333;
    --shadow: rgba(0,0,0,0.05);
    --overlay-bg: rgba(0,0,0,0.4);
    --success: #2e7d32;
}

[data-theme="dark"] {
    --bg-page: #12161c;
    --bg-card: #1b212b;
    --bg-login: #0d1117;
    --text-1: #e4e7ec;
    --text-2: #9aa4b2;
    --text-3: #d4d8de;
    --border-1: #333d4b;
    --border-2: #262e3a;
    --border-3: #2c3542;
    --border-4: #232b36;
    --accent: #5b9bf0;
    --accent-hover: #7bb0f5;
    --accent-soft: #24344d;
    --part-bg: #1e2c42;
    --part-text: #8fb8ee;
    --resource-link: #7fa3d6;
    --danger: #ff6b6b;
    --danger-bg: #3a1f1f;
    --muted-btn-bg: #2a323e;
    --muted-btn-text: #d4d8de;
    --shadow: rgba(0,0,0,0.4);
    --overlay-bg: rgba(0,0,0,0.65);
    --success: #4caf50;
}

html, body { height:100%; }
body { margin:0; font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif; background:var(--bg-page); color:var(--text-1); transition: background 0.2s, color 0.2s; display:flex; flex-direction:column; overflow:hidden; }

.login-body { display:flex; align-items:center; justify-content:center; min-height:100vh; background:var(--bg-login); }
.login-box { background:var(--bg-card); padding:36px 40px; border-radius:10px; box-shadow:0 4px 24px var(--shadow); width:320px; }
.login-box h1 { font-size:1.2rem; color:var(--accent); margin:0 0 20px; }
.login-box label { display:block; font-size:0.8rem; color:var(--text-2); margin:12px 0 4px; }
.login-box input { width:100%; padding:9px 10px; border:1px solid var(--border-1); border-radius:6px; font-size:0.9rem; background:var(--bg-card); color:var(--text-1); }
.login-box button { width:100%; margin-top:18px; padding:10px; background:var(--accent); color:#fff; border:none; border-radius:6px; font-size:0.9rem; cursor:pointer; }
.login-box button:hover { background:var(--accent-hover); }
.login-box .error { background:var(--danger-bg); color:var(--danger); padding:8px 10px; border-radius:6px; font-size:0.82rem; margin-bottom:6px; }

.topbar { display:flex; justify-content:space-between; align-items:center; background:var(--accent); color:#fff; padding:14px 26px; flex-wrap:wrap; gap:8px; flex-shrink:0; }
.topbar-title { font-size:1.1rem; font-weight:600; }
.topbar-user { font-size:0.82rem; display:flex; align-items:center; gap:10px; }
.topbar-user a { color:#dce8ff; text-decoration:none; }
.topbar-user a:hover { text-decoration:underline; }
.account-menu { position:relative; display:inline-block; }
.account-menu-trigger { background:rgba(255,255,255,0.15); border:none; color:#fff; cursor:pointer; padding:5px 10px; border-radius:6px; font-size:0.78rem; }
.account-menu-trigger:hover { background:rgba(255,255,255,0.25); }
.account-menu-dropdown { display:none; position:absolute; top:calc(100% + 6px); right:0; background:var(--bg-card); border:1px solid var(--border-1); border-radius:8px; box-shadow:0 4px 16px var(--shadow); min-width:150px; overflow:hidden; z-index:100; }
.account-menu-dropdown.open { display:block; }
.account-menu-dropdown a { display:block; padding:10px 14px; color:var(--text-1); text-decoration:none; font-size:0.82rem; }
.account-menu-dropdown a:hover { background:var(--border-2); text-decoration:none; }
.account-menu { position:relative; display:inline-block; }
.account-menu-trigger { background:rgba(255,255,255,0.15); border:none; color:#fff; cursor:pointer; padding:5px 10px; border-radius:6px; font-size:0.78rem; }
.account-menu-trigger:hover { background:rgba(255,255,255,0.25); }
.account-menu-dropdown { display:none; position:absolute; top:calc(100% + 6px); right:0; background:var(--bg-card); border:1px solid var(--border-1); border-radius:8px; box-shadow:0 4px 16px var(--shadow); min-width:150px; overflow:hidden; z-index:100; }
.account-menu-dropdown.open { display:block; }
.account-menu-dropdown a { display:block; padding:10px 14px; color:var(--text-1); text-decoration:none; font-size:0.82rem; }
.account-menu-dropdown a:hover { background:var(--border-2); text-decoration:none; }

.theme-toggle { position:relative; display:inline-block; width:38px; height:20px; flex-shrink:0; }
.theme-toggle input { opacity:0; width:0; height:0; }
.theme-toggle-slider { position:absolute; cursor:pointer; inset:0; background:rgba(255,255,255,0.3); border-radius:20px; transition:0.2s; }
.theme-toggle-slider::before { content:"\2600\FE0F"; position:absolute; height:14px; width:14px; left:3px; bottom:3px; background:#fff; border-radius:50%; transition:0.2s; font-size:9px; display:flex; align-items:center; justify-content:center; line-height:1; }
.theme-toggle input:checked + .theme-toggle-slider { background:rgba(0,0,0,0.35); }
.theme-toggle input:checked + .theme-toggle-slider::before { transform:translateX(18px); content:"\1F319"; }

.layout { display:flex; gap:24px; margin:24px; padding:0; align-items:stretch; flex:1; min-height:0; overflow:hidden; }
.main-col { flex:1; min-width:0; display:flex; flex-direction:column; gap:20px; overflow-y:auto; min-height:0; }
.checklist-col { width:25%; min-width:340px; flex-shrink:0; min-height:0; }

.card { background:var(--bg-card); border-radius:10px; padding:20px 24px; box-shadow:0 2px 10px var(--shadow); }
.card h2 { margin:0 0 14px; font-size:1rem; color:var(--accent); }
.card-header-row { display:flex; justify-content:space-between; align-items:center; margin-bottom:14px; }
.card-header-row h2 { margin:0; }
.mini-toggle-btn { background:var(--muted-btn-bg); color:var(--muted-btn-text); border:none; padding:6px 14px; border-radius:6px; font-size:0.72rem; cursor:pointer; text-transform:uppercase; letter-spacing:0.5px; white-space:nowrap; }
.mini-toggle-btn:hover { opacity:0.85; }
.manage-panel { display:none; }
.manage-panel.open { display:block; }
.manage-group { padding:14px 0; border-top:1px solid var(--border-2); }
.manage-group:first-child { border-top:none; padding-top:0; }
.manage-label { font-size:0.72rem; font-weight:600; color:var(--text-2); text-transform:uppercase; letter-spacing:0.5px; margin-bottom:8px; }
.card-header-row { display:flex; justify-content:space-between; align-items:center; margin-bottom:14px; }
.card-header-row h2 { margin:0; }
.mini-toggle-btn { background:var(--muted-btn-bg); color:var(--muted-btn-text); border:none; padding:6px 14px; border-radius:6px; font-size:0.72rem; cursor:pointer; text-transform:uppercase; letter-spacing:0.5px; white-space:nowrap; }
.mini-toggle-btn:hover { opacity:0.85; }
.manage-panel { display:none; }
.manage-panel.open { display:block; }
.manage-group { padding:14px 0; border-top:1px solid var(--border-2); }
.manage-group:first-child { border-top:none; padding-top:0; }
.manage-label { font-size:0.72rem; font-weight:600; color:var(--text-2); text-transform:uppercase; letter-spacing:0.5px; margin-bottom:8px; }

.doc-list { list-style:none; margin:0 0 14px; padding:0; }
.doc-list li { display:flex; justify-content:space-between; align-items:center; padding:8px 0; border-bottom:1px solid var(--border-2); }
.doc-list a { color:var(--accent); text-decoration:none; font-size:0.9rem; }
.doc-list a:hover { text-decoration:underline; }
.mini-btn { background:none; border:none; color:var(--text-2); cursor:pointer; font-size:1rem; line-height:1; padding:2px 6px; opacity:0.6; }
.mini-btn:hover { color:var(--danger); opacity:1; }
.resource-list { max-height:260px; overflow-y:auto; }
.resource-list li { padding:6px 0; }
.resource-list a { font-size:0.82rem; }

.inline-form { display:flex; gap:8px; flex-wrap:wrap; margin-top:10px; }
.inline-form input, .inline-form select { flex:1; min-width:140px; padding:8px 10px; border:1px solid var(--border-1); border-radius:6px; font-size:0.85rem; background:var(--bg-card); color:var(--text-1); }
.inline-form button { padding:8px 16px; background:var(--accent); color:#fff; border:none; border-radius:6px; font-size:0.85rem; cursor:pointer; white-space:nowrap; }
.inline-form button:hover { background:var(--accent-hover); }

.checklist-panel { background:var(--bg-card); border-radius:10px; box-shadow:0 2px 10px var(--shadow); height:100%; display:flex; flex-direction:column; overflow:hidden; }
.checklist-header { padding:16px 20px 10px; border-bottom:1px solid var(--border-2); }
.checklist-header h2 { margin:0 0 8px; font-size:1rem; color:var(--accent); }
.progress-summary { display:flex; gap:16px; font-size:0.8rem; color:var(--text-2); }
.checklist-body { overflow-y:auto; padding:0 4px; }

.checklist-table { width:100%; border-collapse:collapse; font-size:0.78rem; }
.checklist-table th { position:sticky; top:0; background:var(--bg-page); padding:8px; text-align:left; border-bottom:1px solid var(--border-3); z-index:1; color:var(--text-1); }
.checklist-table th:not(:first-child) { text-align:center; width:60px; }
.checklist-table td { padding:7px 8px; border-bottom:1px solid var(--border-4); vertical-align:top; }
.checklist-table td:not(:first-child) { text-align:center; }
.part-row td { background:var(--part-bg); font-weight:600; color:var(--part-text); }
.chapter-name { padding-left:18px !important; color:var(--text-3); }
.chapter-resources { margin-top:3px; display:flex; flex-wrap:wrap; gap:8px; }
.chapter-resources a { font-size:0.68rem; color:var(--resource-link); text-decoration:none; }
.chapter-resources a:hover { text-decoration:underline; color:var(--accent); }
.checklist-table input[type=checkbox] { width:16px; height:16px; cursor:pointer; }
.part-status-dot { display:inline-block; width:14px; height:14px; border-radius:4px; background:var(--danger); transition:background 0.2s; }
.part-status-dot.done { background:var(--success); }
.part-status-dot.in-progress { background:#f5a623; }

.modal-overlay { display:none; position:fixed; inset:0; background:var(--overlay-bg); align-items:center; justify-content:center; z-index:999; }
.modal-overlay.open { display:flex; }
.modal-panel { background:var(--bg-card); border-radius:10px; padding:24px 28px; width:320px; }
.modal-panel h2 { margin:0 0 16px; font-size:1rem; color:var(--accent); }
.modal-panel label { display:block; font-size:0.8rem; color:var(--text-2); margin:10px 0 4px; }
.modal-panel input { width:100%; padding:8px 10px; border:1px solid var(--border-1); border-radius:6px; font-size:0.85rem; background:var(--bg-card); color:var(--text-1); }
.modal-actions { display:flex; justify-content:flex-end; gap:10px; margin-top:18px; }
.modal-actions button { padding:8px 16px; border:none; border-radius:6px; font-size:0.85rem; cursor:pointer; }
.modal-actions button[type=submit] { background:var(--accent); color:#fff; }
.modal-actions button[type=button] { background:var(--muted-btn-bg); color:var(--muted-btn-text); }
.status-msg { font-size:0.8rem; margin-top:8px; min-height:16px; }
.modal-panel-large { width:95vw; max-width:1750px; height:95vh; display:flex; flex-direction:column; padding:16px 20px; }
.modal-panel-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:10px; }
.modal-panel-header h2 { margin:0; font-size:0.95rem; color:var(--accent); word-break:break-word; padding-right:12px; }
.modal-panel-body { flex:1; overflow:auto; background:var(--bg-card); }

@media(max-width:900px) {
    body { overflow:auto; display:block; }
    .layout { flex-direction:column; height:auto; overflow:visible; }
    .main-col { overflow-y:visible; height:auto; }
    .checklist-col { width:100%; min-width:0; height:auto; }
    .checklist-panel { height:auto; max-height:500px; }
}
