:root {
    --bg: #f6f8fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --border: #dbe3ee;
    --border-strong: #c8d3e1;
    --ink: #172033;
    --muted: #64748b;
    --muted-soft: #94a3b8;
    --brand: #1d4ed8;
    --brand-hover: #1e40af;
    --accent: #0f766e;
    --danger: #be123c;
    --warning: #b45309;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 12px 24px rgba(15, 23, 42, 0.08);
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
    letter-spacing: 0;
}

code,
pre,
.mono {
    font-family: "SF Mono", Menlo, Consolas, monospace;
}

a,
button,
input,
select,
textarea,
summary {
    transition: border-color 140ms ease, background-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
    outline: 2px solid rgba(29, 78, 216, 0.35);
    outline-offset: 2px;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    border-bottom: 1px solid rgba(219, 227, 238, 0.9);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(14px);
}

.app-nav {
    max-width: 80rem;
    min-height: 3.75rem;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    color: var(--ink);
    font-weight: 700;
    white-space: nowrap;
}

.brand-mark {
    width: 1.875rem;
    height: 1.875rem;
    border-radius: 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #172033;
    color: #ffffff;
    font-size: 0.8125rem;
    box-shadow: inset 0 -2px 0 rgba(255, 255, 255, 0.14);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--muted);
    font-size: 0.875rem;
}

.nav-link {
    border-radius: 7px;
    padding: 0.5rem 0.7rem;
    color: var(--muted);
    text-decoration: none;
}

.nav-link:hover {
    background: var(--surface-soft);
    color: var(--ink);
}

.nav-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.app-main {
    width: min(100% - 2rem, 72rem);
    margin: 0 auto;
    padding: 1.75rem 0 3rem;
}

.app-main-narrow {
    width: min(100% - 2rem, 44rem);
}

.app-main-wide {
    width: min(100% - 2rem, 88rem);
}

.app-flash {
    width: min(100% - 2rem, 80rem);
    margin: 1rem auto 0;
    display: grid;
    gap: 0.5rem;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.page-title {
    color: var(--ink);
    font-size: 1.6rem;
    line-height: 1.15;
    font-weight: 700;
}

.page-subtitle {
    margin-top: 0.35rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.panel-pad {
    padding: 1.25rem;
}

.section-title {
    color: var(--ink);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 2.125rem;
    border-radius: 7px;
    padding: 0.45rem 0.75rem;
    border: 1px solid transparent;
    font-size: 0.875rem;
    font-weight: 650;
    line-height: 1.1;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--brand);
    color: #ffffff;
    box-shadow: 0 1px 2px rgba(29, 78, 216, 0.18);
}

.btn-primary:hover {
    background: var(--brand-hover);
}

.btn-secondary {
    border-color: var(--border);
    background: #ffffff;
    color: var(--ink);
}

.btn-secondary:hover {
    border-color: var(--border-strong);
    background: var(--surface-soft);
}

.btn-danger {
    border-color: #fecdd3;
    background: #fff1f2;
    color: var(--danger);
}

.btn-danger:hover {
    background: #ffe4e6;
}

.btn-link {
    color: var(--brand);
    font-weight: 650;
    text-decoration: none;
}

.btn-link:hover {
    color: var(--brand-hover);
}

.tabs {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.25rem;
}

.tab {
    display: inline-flex;
    align-items: center;
    min-height: 2.5rem;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-size: 0.875rem;
    font-weight: 650;
    padding: 0 0.75rem;
    text-decoration: none;
}

.tab:hover {
    color: var(--ink);
}

.tab-active {
    border-color: var(--brand);
    color: var(--brand);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border-radius: 999px;
    padding: 0.18rem 0.5rem;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.2;
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge-featured {
    border-color: #fde68a;
    background: #fffbeb;
    color: #92400e;
}

.badge-private {
    border-color: #e2e8f0;
    background: #f8fafc;
    color: #475569;
}

.badge-team {
    border-color: #99f6e4;
    background: #f0fdfa;
    color: #0f766e;
}

.badge-danger {
    border-color: #fecdd3;
    background: #fff1f2;
    color: var(--danger);
}

.badge-role {
    border-color: #c7d2fe;
    background: #eef2ff;
    color: #3730a3;
}

.meta-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.45rem 0.7rem;
    color: var(--muted);
    font-size: 0.78rem;
}

.meta-row code,
.code-chip {
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #f8fafc;
    color: #334155;
    padding: 0.08rem 0.35rem;
    font-size: 0.75rem;
}

.session-card {
    display: block;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    padding: 1rem;
}

.session-card:hover {
    border-color: #93c5fd;
    box-shadow: var(--shadow-md);
}

.empty-state {
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.7);
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--muted);
}

.alert {
    border-radius: var(--radius);
    border: 1px solid;
    padding: 0.75rem 0.9rem;
    font-size: 0.875rem;
}

.alert-success {
    border-color: #a7f3d0;
    background: #ecfdf5;
    color: #047857;
}

.alert-error {
    border-color: #fecdd3;
    background: #fff1f2;
    color: #be123c;
}

.alert-warning {
    border-color: #fed7aa;
    background: #fff7ed;
    color: #9a3412;
}

.field-label {
    display: block;
    margin-bottom: 0.4rem;
    color: #334155;
    font-size: 0.84rem;
    font-weight: 650;
}

.form-control {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: #ffffff;
    color: var(--ink);
    font-size: 0.875rem;
}

select.form-control {
    min-height: 2.125rem;
    padding: 0.35rem 0.55rem;
}

textarea.form-control {
    padding: 0.55rem 0.65rem;
}

.form-control:focus {
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.35);
    outline: 0;
}

.table-card {
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.data-table {
    width: 100%;
    min-width: 720px;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.875rem;
}

.data-table thead {
    background: #f8fafc;
    color: #475569;
}

.data-table th,
.data-table td {
    border-bottom: 1px solid #e8eef6;
    padding: 0.7rem 0.85rem;
    text-align: left;
    vertical-align: middle;
}

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

.detail-hero {
    border-bottom: 1px solid var(--border);
    background: #ffffff;
}

.detail-head {
    width: min(100% - 2rem, 88rem);
    margin: 0 auto;
    padding: 1rem 0;
}

.detail-grid {
    width: min(100% - 2rem, 88rem);
    margin: 0 auto;
    padding: 1.25rem 0 2.5rem;
    display: grid;
    grid-template-columns: minmax(180px, 220px) minmax(0, 1fr) minmax(230px, 280px);
    gap: 1.25rem;
}

.side-panel {
    position: sticky;
    top: 5rem;
    align-self: start;
    max-height: calc(100vh - 6rem);
    overflow: auto;
}

.timeline-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #ffffff;
    box-shadow: var(--shadow-sm);
}

.timeline-card-strong {
    border-color: #bfdbfe;
    box-shadow: inset 3px 0 0 var(--brand), var(--shadow-sm);
}

.thinking-bg {
    border-color: #fde68a;
    background: #fffbeb;
}

.outline-link.active {
    border-left-color: var(--brand);
    background: #eff6ff;
    color: var(--brand);
}

.turn-anchor.flash {
    animation: flashHighlight 1.2s ease-out;
}

@keyframes flashHighlight {
    0% { box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.25); }
    100% { box-shadow: 0 0 0 0 rgba(29, 78, 216, 0); }
}

.clip {
    display: -webkit-box;
    -webkit-line-clamp: 8;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.content-card {
    display: grid;
    gap: 0.75rem;
}

.content-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.content-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    min-width: 0;
}

.content-title {
    color: var(--ink);
    font-size: 0.95rem;
    font-weight: 650;
}

.content-summary {
    color: var(--muted);
    font-size: 0.78rem;
}

.content-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.toggle-btn {
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #ffffff;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 650;
    padding: 0.22rem 0.55rem;
}

.toggle-btn:hover {
    border-color: var(--border-strong);
    color: var(--ink);
}

.toggle-btn.is-active {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: var(--brand);
}

.content-pane[hidden] {
    display: none !important;
}

.content-body.is-collapsed .content-pane-preview {
    max-height: 16rem;
    overflow: hidden;
    position: relative;
}

.content-body.is-collapsed .content-pane-preview::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3rem;
    background: linear-gradient(to bottom, rgba(255,255,255,0), rgba(255,255,255,1));
}

.rendered-markdown,
.rendered-xml,
.rendered-plain {
    color: #1e293b;
    font-size: 0.9rem;
    line-height: 1.6;
}

.rendered-markdown > * + *,
.rendered-xml > * + *,
.rendered-plain > * + * {
    margin-top: 0.75rem;
}

.rendered-h1,
.rendered-h2,
.rendered-h3,
.rendered-h4 {
    color: var(--ink);
    font-weight: 700;
    line-height: 1.25;
}

.rendered-h1 { font-size: 1.2rem; }
.rendered-h2 { font-size: 1.08rem; }
.rendered-h3 { font-size: 1rem; }
.rendered-h4 { font-size: 0.95rem; }

.rendered-list {
    padding-left: 1.15rem;
    list-style: disc;
}

.rendered-list-ordered {
    list-style: decimal;
}

.rendered-paragraph,
.rendered-quote p {
    margin: 0;
}

.rendered-quote {
    border-left: 3px solid #cbd5e1;
    padding-left: 0.85rem;
    color: #475569;
}

.rendered-pre {
    border: 1px solid #dbe3ee;
    border-radius: 7px;
    background: #f8fafc;
    color: #0f172a;
    font-size: 0.8rem;
    line-height: 1.55;
    overflow: auto;
    padding: 0.8rem 0.9rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.rendered-inline-code {
    border: 1px solid #dbe3ee;
    border-radius: 6px;
    background: #f8fafc;
    color: #0f172a;
    font-size: 0.82em;
    padding: 0.08rem 0.3rem;
}

.rendered-xml-head {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.rendered-chip {
    display: inline-flex;
    align-items: center;
    border: 1px solid #dbe3ee;
    border-radius: 999px;
    background: #f8fafc;
    color: #475569;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.18rem 0.5rem;
}

.rendered-xml-summary {
    color: var(--ink);
    font-size: 0.92rem;
    font-weight: 650;
}

.rendered-xml-body {
    display: grid;
    gap: 0.7rem;
}

.rendered-xml-section {
    display: grid;
    gap: 0.3rem;
}

.rendered-xml-label {
    color: #64748b;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.rendered-xml-value {
    color: #1e293b;
}

@media (max-width: 900px) {
    .app-nav {
        min-height: auto;
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
        flex-wrap: wrap;
    }

    .nav-links {
        order: 3;
        width: 100%;
        overflow-x: auto;
        padding-bottom: 0.1rem;
    }

    .nav-user {
        margin-left: auto;
    }

    .page-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .side-panel {
        position: static;
        max-height: none;
    }
}

@media (max-width: 640px) {
    .app-main {
        width: min(100% - 1rem, 72rem);
        padding-top: 1rem;
    }

    .app-nav {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .page-title {
        font-size: 1.35rem;
    }

    .session-card {
        padding: 0.9rem;
    }
}
