* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: #eef2f7;
    color: #111827;
}

.page {
    width: 100%;
    min-height: 100vh;
    padding: 30px 16px;
}

.card {
    max-width: 1180px;
    margin: 0 auto;
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
    padding: 24px;
}

.shell-card {
    overflow: hidden;
}

.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding-bottom: 18px;
    margin-bottom: 20px;
    border-bottom: 1px solid #e5e7eb;
}

.brand {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.brand span,
.muted,
small {
    color: #6b7280;
}

.nav-links,
.action-row,
.todo-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.top-nav a,
.link-button {
    text-decoration: none;
    color: #374151;
    padding: 8px 10px;
    border-radius: 8px;
    border: 0;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
}

.top-nav a.active,
.top-nav a:hover,
.link-button:hover {
    background: #e0ecff;
    color: #1d4ed8;
}

h1, h2, h3 {
    margin: 0 0 8px;
}

h3 a,
td a {
    color: #1d4ed8;
    text-decoration: none;
}

h3 a:hover,
td a:hover {
    text-decoration: underline;
}

.page-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 18px;
}

.alert {
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 14px;
}

.alert-success {
    background: #dcfce7;
    color: #166534;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
}

.btn {
    display: inline-block;
    border: none;
    border-radius: 9px;
    padding: 9px 14px;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.2;
}

.btn-small {
    padding: 6px 9px;
    font-size: 12px;
}

.btn-primary {
    background: #2563eb;
    color: #ffffff;
}

.btn-secondary {
    background: #e5e7eb;
    color: #111827;
}

.btn-warning {
    background: #f59e0b;
    color: #ffffff;
}

.btn-danger {
    background: #dc2626;
    color: #ffffff;
}

.full-width {
    width: 100%;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 22px;
}

.stats-grid.two-stats {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
}

.stats-grid div {
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 14px;
}

.stats-grid strong {
    display: block;
    font-size: 28px;
    margin-bottom: 4px;
}

.stats-grid span {
    color: #6b7280;
    font-size: 13px;
}

.todo-list,
.subtodo-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.todo-card {
    border: 1px solid #e5e7eb;
    background: #ffffff;
    border-radius: 16px;
    padding: 18px;
}

.todo-card.level-1 {
    background: #f8fafc;
    margin-left: 20px;
}

.todo-header {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 14px;
}

.todo-type,
.section-label {
    text-transform: uppercase;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #6b7280;
    margin-bottom: 7px;
}

.grid.two-col {
    display: grid;
    grid-template-columns: repeat(2, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}

.progress-box {
    width: 100%;
    height: 22px;
    background: #e5e7eb;
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    min-width: 28px;
    max-width: 100%;
    height: 100%;
    background: #22c55e;
    color: #ffffff;
    font-size: 12px;
    text-align: center;
    line-height: 22px;
    white-space: nowrap;
}

.badge {
    display: inline-block;
    padding: 6px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.badge-completed {
    background: #dcfce7;
    color: #166534;
}

.badge-progress {
    background: #dbeafe;
    color: #1d4ed8;
}

.badge-pending {
    background: #f3f4f6;
    color: #4b5563;
}

.inline-progress-form {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--inline-progress-form-color);
    background: var(--inline-progress-form-bg);
    border: 1px solid var(--inline-progress-form-border);
    border-radius: 12px;
    padding: 12px;
    margin: 12px 0;
}

.inline-progress-form input[type="range"] {
    flex: 1;
}

.notice,
.demo-box {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
    border-radius: 12px;
    padding: 12px;
    margin: 12px 0;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
}

.compact-table {
    margin-top: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #ffffff;
}

th, td {
    text-align: left;
    padding: 12px;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: middle;
}

th {
    background: #f8fafc;
    color: #374151;
    font-size: 13px;
}

tr:last-child td {
    border-bottom: 0;
}

.form-card {
    border: 1px solid #e5e7eb;
    background: #f8fafc;
    border-radius: 16px;
    padding: 18px;
}

label {
    display: block;
    font-weight: 700;
    margin: 12px 0 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    background: #ffffff;
}

.check-row,
.checkbox-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-weight: normal;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(220px, 1fr));
    gap: 10px;
}

.checkbox-card {
    border: 1px solid #e5e7eb;
    background: #ffffff;
    padding: 12px;
    border-radius: 12px;
    margin: 0;
}

.checkbox-card span {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.error {
    color: #dc2626;
    font-size: 13px;
    margin-top: 5px;
    margin-bottom: 8px;
}

.auth-box {
    max-width: 480px;
    margin: 20px auto;
}

.top-gap {
    margin-top: 16px;
}

.small-text {
    font-size: 13px;
}

.empty-state {
    border: 1px dashed #cbd5e1;
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    color: #64748b;
}

code {
    background: #f3f4f6;
    padding: 2px 5px;
    border-radius: 5px;
}

.mb-10 {
    margin-bottom: 15px;
}

@media (max-width: 780px) {
    .top-nav,
    .page-title-row,
    .todo-header {
        flex-direction: column;
        align-items: stretch;
    }

    .stats-grid,
    .stats-grid.two-stats,
    .grid.two-col,
    .checkbox-grid {
        grid-template-columns: 1fr;
    }

    .todo-card.level-1 {
        margin-left: 0;
    }

    .inline-progress-form {
        flex-wrap: wrap;
    }
}

/* Simplified main todo table + popup progress view */
.main-todo-table table {
    table-layout: fixed;
}

.main-todo-table th:first-child,
.main-todo-table td:first-child {
    width: 32%;
}

.clickable-row:hover td {
    background: #f8fafc;
}

.topic-link,
.description-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.topic-link {
    font-weight: 700;
    color: #1d4ed8;
}

.description-link {
    color: #4b5563;
    line-height: 1.45;
}

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(15, 23, 42, 0.62);
    padding: 24px;
    overflow-y: auto;
}

.modal-overlay:target {
    display: block;
}

.modal-card {
    max-width: 1050px;
    margin: 24px auto;
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
    padding: 22px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid #e5e7eb;
}

.modal-close {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: #f3f4f6;
    color: #111827;
    font-size: 26px;
    line-height: 1;
    text-decoration: none;
}

.modal-close:hover {
    background: #e5e7eb;
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 16px 0;
}

.progress-panel {
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 16px;
    margin-top: 14px;
    background: #ffffff;
}

.progress-panel.level-1,
.progress-panel.level-2,
.progress-panel.level-3 {
    background: #f8fafc;
    margin-left: 18px;
}

.progress-panel-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
}

.progress-panel-title-row p {
    margin: 0;
    color: #4b5563;
    line-height: 1.45;
}

.modal-progress-grid {
    margin-bottom: 10px;
}

.compact-progress-form {
    margin: 10px 0;
}

.compact-notice {
    margin: 10px 0;
    padding: 10px 12px;
}

.modal-subtodos {
    margin-top: 16px;
}

.progress-panel td small {
    display: block;
    margin-top: 2px;
    color: #6b7280;
}

@media (max-width: 780px) {
    .main-todo-table table,
    .main-todo-table thead,
    .main-todo-table tbody,
    .main-todo-table th,
    .main-todo-table td,
    .main-todo-table tr {
        display: block;
        width: 100%;
    }

    .main-todo-table thead {
        display: none;
    }

    .main-todo-table tr {
        border-bottom: 1px solid #e5e7eb;
        padding: 12px;
    }

    .main-todo-table td {
        border-bottom: 0;
        padding: 5px 0;
    }

    .modal-overlay {
        padding: 10px;
    }

    .modal-card {
        margin: 12px auto;
        padding: 16px;
    }

    .modal-header,
    .progress-panel-title-row {
        flex-direction: column;
    }

    .progress-panel.level-1,
    .progress-panel.level-2,
    .progress-panel.level-3 {
        margin-left: 0;
    }
}

/* Collapsible tree main screen */
.todo-tree {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.root-tree {
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    overflow: hidden;
    background: #ffffff;
}

.child-tree {
    margin-left: 26px;
    padding-left: 16px;
    border-left: 2px solid #e5e7eb;
}

.tree-node {
    border-bottom: 1px solid #eef2f7;
}

.tree-node:last-child {
    border-bottom: 0;
}

.tree-node details {
    padding: 0;
}

.tree-node summary {
    display: grid;
    grid-template-columns: 26px minmax(220px, 1fr) minmax(150px, 260px);
    gap: 12px;
    align-items: center;
    padding: 13px 14px;
    cursor: pointer;
}

.tree-node summary::marker,
.tree-node summary::-webkit-details-marker {
    display: none;
}

.tree-node details[open] > summary .tree-toggle {
    transform: rotate(90deg);
}

.tree-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    transition: transform 0.18s ease;
}

.tree-main-link {
    display: flex;
    flex-direction: column;
    gap: 3px;
    color: #111827;
    text-decoration: none;
}

.tree-main-link strong {
    color: #1d4ed8;
}

.tree-main-link small {
    line-height: 1.4;
}

.tree-progress .progress-box {
    min-width: 145px;
}

.tree-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 14px 12px 52px;
}

.tree-actions form {
    display: inline-block;
}

.tree-node.level-1 > details > summary {
    background: #f8fafc;
}

.tree-node.level-2 > details > summary,
.tree-node.level-3 > details > summary {
    background: #f1f5f9;
}

.detail-block {
    border: 1px solid #e5e7eb;
    background: #ffffff;
    border-radius: 16px;
    padding: 18px;
    margin-bottom: 18px;
}

.detail-header,
.section-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 16px;
}

.detail-header p {
    color: #4b5563;
    line-height: 1.55;
    margin: 0;
}

.section-title-row {
    margin-top: 22px;
}

@media (max-width: 780px) {
    .tree-node summary {
        grid-template-columns: 22px 1fr;
    }

    .tree-progress {
        grid-column: 2;
        width: 100%;
    }

    .tree-actions {
        padding-left: 42px;
    }

    .child-tree {
        margin-left: 12px;
        padding-left: 10px;
    }

    .detail-header,
    .section-title-row {
        flex-direction: column;
    }
}

.auth-switch {
    margin-top: 14px;
    text-align: center;
    color: #6b7280;
}

.auth-switch a {
    color: #1d4ed8;
    font-weight: 700;
    text-decoration: none;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* Light / Dark mode */
:root {
    --app-bg: #eef2f7;
    --card-bg: #ffffff;
    --soft-bg: #f8fafc;
    --soft-bg-2: #f1f5f9;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border-main: #e5e7eb;
    --input-bg: #ffffff;
    --input-border: #d1d5db;
    --link-main: #1d4ed8;
    --nav-hover-bg: #e0ecff;
    --nav-hover-text: #1d4ed8;
    --progress-bg: #e5e7eb;
    --code-bg: #f3f4f6;
    --shadow-main: 0 18px 45px rgba(15, 23, 42, 0.08);
    --inline-progress-form-bg: #eff6ff;
    --inline-progress-form-color: #000;
    --inline-progress-form-border: #bfdbfe;
}

html[data-theme="dark"] {
    --app-bg: #0f172a;
    --card-bg: #111827;
    --soft-bg: #1f2937;
    --soft-bg-2: #273449;
    --text-main: #e5e7eb;
    --text-muted: #9ca3af;
    --border-main: #334155;
    --input-bg: #0f172a;
    --input-border: #475569;
    --link-main: #93c5fd;
    --nav-hover-bg: #1e3a5f;
    --nav-hover-text: #bfdbfe;
    --progress-bg: #334155;
    --code-bg: #0f172a;
    --shadow-main: 0 18px 45px rgba(0, 0, 0, 0.28);
    --inline-progress-form-bg: #212f41;
    --inline-progress-form-color: #fff;
    --inline-progress-form-border: #435061;
}

html[data-theme="dark"] a {
    color: #fff;
}

body {
    background: var(--app-bg);
    color: var(--text-main);
}

.card,
.todo-card,
.progress-panel,
table,
.modal-card,
.detail-block,
.root-tree {
    background: var(--card-bg);
    color: var(--text-main);
}

.card {
    box-shadow: var(--shadow-main);
}

.top-nav,
th,
td,
.table-wrap,
.form-card,
.todo-card,
.progress-panel,
.detail-block,
.root-tree,
.tree-node,
.checkbox-card {
    border-color: var(--border-main);
}

.form-card,
.stats-grid div,
th,
.todo-card.level-1,
.progress-panel.level-1,
.progress-panel.level-2,
.progress-panel.level-3,
.tree-node.level-1 > details > summary,
.checkbox-card {
    background: var(--soft-bg);
}

.tree-node.level-2 > details > summary,
.tree-node.level-3 > details > summary {
    background: var(--soft-bg-2);
}

.brand span,
.muted,
small,
.stats-grid span,
.tree-main-link small,
.detail-header p,
.progress-panel-title-row p,
.auth-switch,
.description-link {
    color: var(--text-muted);
}

.top-nav a,
.link-button,
.tree-main-link,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
    color: var(--text-main);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
    background: var(--input-bg);
    border-color: var(--input-border);
}

.top-nav a.active,
.top-nav a:hover,
.link-button:hover {
    background: var(--nav-hover-bg);
    color: var(--nav-hover-text);
}

h3 a,
td a,
.topic-link,
.tree-main-link strong,
.auth-switch a {
    color: var(--link-main);
}

.progress-box {
    background: var(--progress-bg);
}

code {
    background: var(--code-bg);
    color: var(--text-main);
}

.btn-secondary {
    background: var(--soft-bg-2);
    color: var(--text-main);
}

.guest-theme-row {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

.theme-toggle {
    border: 1px solid var(--border-main);
}

html[data-theme="dark"] .demo-box,
html[data-theme="dark"] .notice,
html[data-theme="dark"] .compact-notice {
    background: #312e17;
    border-color: #854d0e;
    color: #fde68a;
}

html[data-theme="dark"] .alert-success {
    background: #052e16;
    color: #bbf7d0;
}

html[data-theme="dark"] .alert-error {
    background: #450a0a;
    color: #fecaca;
}

html[data-theme="dark"] .badge-completed {
    background: #052e16;
    color: #bbf7d0;
}

html[data-theme="dark"] .badge-progress {
    background: #172554;
    color: #bfdbfe;
}

html[data-theme="dark"] .badge-pending {
    background: #334155;
    color: #cbd5e1;
}
