* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #0a0e17;
    --fg: #e0e0e0;
    --muted: #888;
    --accent: #00d4ff;
    --accent2: #7b2ff7;
    --card: rgba(255, 255, 255, 0.03);
    --border: rgba(255, 255, 255, 0.08);
    --sidebar-w: 248px;
}

html { scroll-behavior: smooth; }

body {
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', 'Meiryo', sans-serif;
    background-color: var(--bg);
    color: var(--fg);
    line-height: 1.7;
    min-height: 100vh;
}

.grid-bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(0, 212, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 212, 255, 0.03) 1px, transparent 1px);
    background-size: 60px 60px;
}

.container {
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 24px;
}

/* Header */
.site-header {
    position: sticky;
    top: 0;
    background: rgba(10, 14, 23, 0.85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    z-index: 10;
}
.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 18px;
    padding-bottom: 18px;
}
.logo {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-decoration: none;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.site-nav { display: flex; gap: 24px; }
.site-nav a {
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
    transition: color 0.2s;
}
.site-nav a:hover { color: var(--accent); }

/* Hero */
.hero {
    padding: 96px 0 72px;
    text-align: center;
}
.eyebrow {
    display: inline-block;
    font-size: 12px;
    letter-spacing: 3px;
    color: var(--accent);
    padding: 6px 14px;
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 999px;
    margin-bottom: 24px;
}
.hero h1 {
    font-size: clamp(1.8rem, 4.5vw, 2.8rem);
    line-height: 1.3;
    margin-bottom: 20px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.hero .lead {
    color: #bbb;
    font-size: 1.05rem;
    margin-bottom: 36px;
}
.cta-row {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}
.btn {
    display: inline-block;
    padding: 12px 28px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
}
.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #fff;
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 212, 255, 0.25);
}
.btn-ghost {
    border: 1px solid var(--border);
    color: var(--fg);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* Sections */
.section { padding: 72px 0; }
.section-alt { background: rgba(255, 255, 255, 0.015); }
.section h2 {
    font-size: 1.6rem;
    margin-bottom: 40px;
    text-align: center;
    color: var(--fg);
}

/* Cards */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
}
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px;
    transition: border-color 0.2s, transform 0.2s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
/* Home quick-access cards (anchor variant) */
.hero-home { padding: 64px 0 24px; text-align: left; }
.section-home { padding: 0 0 64px; }
.section-home .nav-section {
    margin: 28px 0 14px;
    font-size: 12px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #888;
}
.section-home .nav-section:first-child { margin-top: 0; }
a.home-card {
    position: relative;
    display: block;
    text-decoration: none;
    text-align: left;
    padding: 22px 24px;
    overflow: hidden;
}
a.home-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 2px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.25s ease;
}
a.home-card:hover::before { transform: scaleX(1); }
a.home-card::after {
    content: "→";
    position: absolute;
    top: 22px;
    right: 22px;
    color: var(--muted);
    font-size: 16px;
    transition: transform 0.2s ease, color 0.2s ease;
}
a.home-card:hover::after { color: var(--accent); transform: translateX(3px); }
a.home-card .card-icon { font-size: 26px; margin-bottom: 10px; }
a.home-card h3 { color: var(--fg); margin-bottom: 6px; }
a.home-card:hover h3 { color: var(--accent); }
a.home-card p { color: var(--muted); font-size: 13px; margin: 0; }
.card-icon { font-size: 32px; margin-bottom: 14px; }
.card h3 { font-size: 1.1rem; margin-bottom: 10px; color: var(--accent); }
.card p { font-size: 14px; color: #bbb; }

/* Steps */
.steps {
    list-style: none;
    max-width: 640px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.steps li {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px 24px;
}
.step-num {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #fff;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}
.step-body { color: #bbb; font-size: 14px; }
.step-body strong { color: var(--fg); font-size: 15px; }

/* FAQ */
.faq { max-width: 720px; margin: 0 auto; }
.faq dt {
    font-weight: 600;
    color: var(--accent);
    margin-top: 22px;
    margin-bottom: 6px;
}
.faq dt:first-child { margin-top: 0; }
.faq dd { color: #bbb; font-size: 14px; margin-left: 18px; }

/* Footer */
.site-footer {
    border-top: 1px solid var(--border);
    padding: 32px 0;
    text-align: center;
}
.footer-nav {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.footer-nav a {
    font-size: 13px;
    color: var(--muted);
    text-decoration: none;
    transition: color 0.2s;
}
.footer-nav a:hover { color: var(--accent); }
.back-dash { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 20px; padding: 14px 36px; font-size: 15px; }
.copy { font-size: 12px; color: #555; }

/* 控えめな削除ボタン（誤操作防止のため目立たせない） */
.btn-danger-quiet {
    background: none;
    border: none;
    padding: 4px 0;
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
    transition: color 0.2s;
}
.btn-danger-quiet:hover { color: #ff5a5a; }

@media (max-width: 600px) {
    .site-nav { gap: 14px; font-size: 13px; }
    .hero { padding: 64px 0 48px; }
    .section { padding: 56px 0; }
    .header-user { gap: 10px; }
    /* 狭い画面ではユーザー名テキストを省き、アバター＋▾だけ表示（メニューは維持） */
    .user-menu-name { display: none; }
}

/* Auth */
.container-narrow { max-width: 420px; }
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-top: 24px;
}
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-form input {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--fg);
    font-size: 14px;
}
.auth-form input:focus { outline: none; border-color: var(--accent); }
.auth-form button { margin-top: 8px; cursor: pointer; border: none; }
.auth-alt { margin-top: 18px; font-size: 13px; color: var(--muted); text-align: center; }
.auth-alt a { color: var(--accent); }

/* Nav additions */
.site-nav { align-items: center; }
.nav-user { color: var(--muted); font-size: 13px; }
a.nav-user { text-decoration: none; transition: color 0.2s; }
a.nav-user:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.inline-form { display: inline; }
.link-button {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font: inherit;
    font-size: 14px;
    padding: 0;
}
.link-button:hover { color: var(--accent); }
.logo { text-decoration: none; }

/* Flash */
.flash-area { margin-top: 18px; display: flex; flex-direction: column; gap: 8px; }
.flash {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    border: 1px solid var(--border);
    background: var(--card);
}
.flash-error { border-color: rgba(255, 90, 90, 0.5); color: #ff8a8a; }
.flash-message { border-color: rgba(110, 255, 176, 0.4); color: #6effb0; }
.flash-success { border-color: rgba(110, 255, 176, 0.4); color: #6effb0; }
.flash-info { border-color: rgba(110, 170, 255, 0.4); color: #8ab6ff; }
.badge-ok { color: #6effb0; font-weight: 600; }
.badge-err { color: #ff8a8a; font-weight: 600; }
.err-text { color: #ff8a8a; word-break: break-word; }
.pl-plus { color: #6effb0; }
.pl-minus { color: #ff8a8a; }

/* Danger / withdrawal */
.btn-danger {
    background: linear-gradient(135deg, #ff5a5a, #c2185b);
    color: #fff;
    border: none;
}
.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(255, 90, 90, 0.25);
}
.danger-box {
    margin-top: 24px;
    padding: 16px 20px;
    border-radius: 10px;
    background: rgba(255, 90, 90, 0.06);
    border: 1px solid rgba(255, 90, 90, 0.4);
    color: #ff8a8a;
    font-size: 14px;
}
.danger-box ul { margin-top: 8px; padding-left: 20px; }
.danger-box li { margin: 4px 0; }
.danger-box strong { color: #ffb3b3; }

/* Verification banner */
.verify-banner {
    margin-top: 14px;
    padding: 10px 14px;
    border-radius: 8px;
    background: rgba(255, 215, 110, 0.08);
    border: 1px solid rgba(255, 215, 110, 0.4);
    color: #ffd76e;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}
.verify-banner .link-button { color: #ffd76e; text-decoration: underline; }
.verify-banner .link-button:hover { color: var(--accent); }

/* Section subhead */
.section-subhead {
    margin-top: 32px;
    margin-bottom: 12px;
    font-size: 1.05rem;
    color: var(--fg);
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

/* Billing */
.plan-card {
    margin-top: 24px;
    padding: 18px 20px;
    border-radius: 10px;
    background: var(--card);
    border: 1px solid var(--border);
}
.status-active { color: #6effb0; }
.status-inactive { color: var(--muted); }

/* Invoices */
.invoice-table-wrap {
    margin-top: 24px;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
}
.invoice-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    color: var(--fg);
}
.invoice-table th,
.invoice-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.invoice-table tr:last-child td { border-bottom: none; }
.invoice-table th {
    color: var(--muted);
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 0.5px;
}
.invoice-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.invoice-table .mono { font-family: 'SFMono-Regular', Consolas, monospace; font-size: 12px; }
.invoice-table a { color: var(--accent); text-decoration: none; margin-right: 10px; }
.invoice-table a:hover { text-decoration: underline; }
.status-pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 11px;
    border: 1px solid var(--border);
    color: var(--muted);
}
.status-pill.status-paid { color: #6effb0; border-color: rgba(110, 255, 176, 0.4); }
.status-pill.status-open { color: #ffd76e; border-color: rgba(255, 215, 110, 0.4); }
.status-pill.status-uncollectible,
.status-pill.status-void { color: #ff8a8a; border-color: rgba(255, 138, 138, 0.4); }

/* Viewer filter */
.filter-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    margin: 24px 0 16px;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
}
.filter-form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--muted);
}
.filter-form input {
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--fg);
    font-size: 13px;
}
.filter-form input:focus { outline: none; border-color: var(--accent); }
.filter-actions { display: flex; gap: 8px; }
.filter-form .btn { padding: 8px 16px; font-size: 13px; cursor: pointer; }

.dropzone {
    flex: 1 1 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 28px 18px;
    border: 2px dashed var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--muted);
    text-align: center;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease, color .15s ease;
}
.dropzone:hover,
.dropzone:focus { outline: none; border-color: var(--accent); color: var(--fg); }
.dropzone.is-dragover {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, var(--bg));
    color: var(--fg);
}
.dropzone-icon { font-size: 28px; line-height: 1; }
.dropzone-text { font-size: 14px; font-weight: 600; color: var(--fg); }
.dropzone-sub { font-size: 12px; }
.result-count { font-size: 12px; color: var(--muted); margin-bottom: 8px; }

/* Date preset row */
.preset-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: -4px 0 14px;
    font-size: 12px;
}
.preset-label { color: var(--muted); margin-right: 4px; }
.btn-pill {
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--fg);
    text-decoration: none;
    font-size: 12px;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.btn-pill:hover { border-color: var(--accent); color: var(--accent); }
.btn-pill.is-active {
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.15), rgba(123, 47, 247, 0.15));
    border-color: var(--accent);
    color: var(--accent);
}

/* Company-grouped disclosure list */
.company-groups {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 16px;
}
.company-group {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    overflow: hidden;
}
.company-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.015);
}
.company-header h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--fg);
    font-weight: 600;
}
.company-header h3 .mono {
    color: var(--muted);
    font-weight: 400;
    font-size: 0.85rem;
    margin-left: 8px;
}
.company-count {
    color: var(--muted);
    font-size: 12px;
}
.disclosure-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.disclosure-list li {
    display: grid;
    grid-template-columns: 140px 1fr auto;
    gap: 16px;
    align-items: center;
    padding: 10px 18px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    transition: background-color 0.12s ease, color 0.12s ease;
}
.disclosure-list li:hover {
    background: rgba(0, 212, 255, 0.09);
    box-shadow: inset 3px 0 0 var(--accent);
}
.disclosure-list li:hover .disclosure-title,
.disclosure-list li:hover .disclosure-date {
    color: #fff;
}
.disclosure-list li:hover .disclosure-link {
    color: #fff;
    text-decoration: underline;
}
.disclosure-title {
    color: var(--fg);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.doc-title {
    font-size: 1rem;
    color: var(--fg);
    margin-top: 8px;
    line-height: 1.4;
}
.missing-html {
    margin-top: 24px;
    padding: 18px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    color: var(--muted);
}
.disclosure-list li:last-child { border-bottom: none; }
.disclosure-date {
    font-variant-numeric: tabular-nums;
    color: var(--fg);
}
.disclosure-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 13px;
}
.disclosure-link:hover { text-decoration: underline; }

/* Search suggest */
.filter-suggest { position: relative; min-width: 240px; }
.suggest-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin: 4px 0 0;
    list-style: none;
    padding: 4px 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
    max-height: 280px;
    overflow-y: auto;
    z-index: 20;
}
.suggest-dropdown li {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--fg);
    display: flex;
    gap: 10px;
    align-items: baseline;
}
.suggest-dropdown li:hover,
.suggest-dropdown li[aria-selected="true"] {
    background: rgba(0, 212, 255, 0.08);
    color: var(--accent);
}
.suggest-dropdown .mono { color: var(--muted); font-size: 12px; }

/* Viewer doc */
.doc-meta { margin-bottom: 24px; }
.back-link-row { margin: 0 0 18px; }
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    border-color: rgba(0, 212, 255, 0.45);
    background: rgba(0, 212, 255, 0.08);
    color: var(--accent);
}
.back-link:hover {
    border-color: var(--accent);
    background: rgba(0, 212, 255, 0.16);
    color: var(--accent);
}
.back-link .back-link-arrow {
    font-size: 16px;
    line-height: 1;
    transition: transform 0.15s ease;
}
.back-link:hover .back-link-arrow { transform: translateX(-3px); }
.doc-meta-list {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 6px 16px;
    margin-top: 12px;
    font-size: 13px;
}
.doc-meta-list dt { color: var(--muted); }
.doc-meta-list dd { color: var(--fg); }
.doc-meta-list a,
.missing-html a {
    color: #ffd76e;
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
}
.doc-meta-list a:hover,
.missing-html a:hover { color: #ffe9a3; }
.doc-frame {
    width: 100%;
    height: 75vh;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

/* Inline document rendering (HTML, not iframe) */
.doc-body {
    color: #222;
    line-height: 1.85;
    font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
}
.doc-body .page,
.doc-body div[id^="page"] {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    padding: 32px 40px;
    margin: 0 0 24px;
}
.doc-body .page > *:first-child,
.doc-body div[id^="page"] > *:first-child { margin-top: 0; }
.doc-body .page > *:last-child,
.doc-body div[id^="page"] > *:last-child { margin-bottom: 0; }
.doc-body h1, .doc-body h2, .doc-body h3, .doc-body h4 {
    font-weight: 600;
    color: #222;
}
.doc-body h1 { font-size: 1.4em; margin: 1.4em 0 .6em; }
.doc-body h2 {
    font-size: 1.2em;
    margin: 1.4em 0 .6em;
    border-bottom: 1px solid #ddd;
    padding-bottom: .2em;
}
.doc-body h3 {
    font-size: 1.1em;
    margin: 1.4em 0 .5em;
    border-left: 3px solid #4a6cf7;
    padding-left: .6em;
}
.doc-body h4 { font-size: 1em; margin: 1.1em 0 .4em; color: #444; }
.doc-body h3.sec {
    font-size: 1.1em;
    margin: 1.8em 0 .6em;
    font-weight: 600;
    color: #222;
    border-left: 3px solid #4a6cf7;
    padding-left: .6em;
}
.doc-body h4.subsec { font-size: 1em; margin: 1.2em 0 .4em; color: #444; }
.doc-body p { margin: .7em 0; color: #222; }
.doc-body p.end-mark {
    text-align: right;
    font-size: .95em;
    color: #555;
    margin-top: 1.8em;
}
.doc-body table { border-collapse: collapse; margin: .7em 0; }
.doc-body th, .doc-body td {
    border: 1px solid #e0e0e0;
    padding: 6px 10px;
    text-align: left;
    vertical-align: top;
}
.doc-body th { background: #fafafa; font-weight: 600; }
.doc-body img { max-width: 100%; height: auto; }
.doc-body pre.tabular {
    white-space: pre;
    overflow-x: auto;
    font-family: "SFMono-Regular", "Menlo", "Consolas", "Noto Sans Mono CJK JP", monospace;
    font-size: .88em;
    background: #fafafa;
    border: 1px solid #eee;
    padding: 12px;
    border-radius: 4px;
    line-height: 1.5;
    margin: .7em 0;
    color: #222;
}
.doc-body pre.preserve {
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
    font-size: 1em;
    line-height: 1.85;
    background: transparent;
    border: none;
    padding: 0;
    margin: .7em 0;
    color: #222;
}
.doc-body ul.cells {
    list-style: none;
    padding: 0;
    margin: .6em 0;
    column-count: auto;
    column-width: 11em;
    column-gap: 1em;
    font-size: .92em;
    line-height: 1.5;
}
.doc-body ul.cells li {
    padding: 3px 8px;
    border-bottom: 1px solid #f0f0f0;
    break-inside: avoid;
}

/* Color mode: PyMuPDF html output uses absolute positioning inside the
   page div with explicit pt sizes. The children have top/left but no
   `position` declaration — we add it here. Don't add padding to the
   page (would shift coords) and let the inline width/height stand. */
.doc-body--color { overflow-x: auto; }
.doc-body--color div[id^="page"] {
    position: relative;
    padding: 0;
    margin: 0 auto 24px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    background: #fff;
}
.doc-body--color div[id^="page"] > p,
.doc-body--color div[id^="page"] > img {
    position: absolute;
    margin: 0;
}
.doc-body--color div[id^="page"] > img { max-width: none; height: auto; }
.doc-mode-toggle {
    margin-top: 16px;
    text-align: center;
    font-size: 12px;
    color: var(--muted);
}
.doc-mode-toggle a { color: var(--accent); text-decoration: none; }
.doc-mode-toggle a:hover { text-decoration: underline; }

/* ============ analysis (銘柄分析 / 財務分析 / PDCA) ============ */
.analysis { padding: 32px 0 64px; }
.analysis.narrow { max-width: 640px; }
.analysis h1 { font-size: 26px; margin: 0 0 8px; }
.analysis h2 { font-size: 18px; margin: 32px 0 12px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.analysis h3 { font-size: 14px; margin: 20px 0 8px; }
.analysis .crumb { margin: 0 0 8px; }
.analysis .crumb a, .analysis a { color: var(--accent); text-decoration: none; }
.analysis .crumb a:hover, .analysis a:hover { text-decoration: underline; }
.analysis .code { color: var(--muted); font-size: 13px; font-family: monospace; margin-left: 6px; }
.analysis .muted, .muted { color: var(--muted); }
.analysis .small { font-size: 12px; }
.analysis .note { color: var(--muted); font-size: 12px; margin-top: 8px; }
.diff-explain { margin-top: 8px; }
.diff-explain p { margin: 0 0 6px; }
.diff-explain ul { margin: 0; padding-left: 1.2em; line-height: 1.7; }
.diff-explain li { margin: 2px 0; }

.search-form { display: flex; gap: 8px; margin: 16px 0; }
.search-form input[type="text"] {
    flex: 1; padding: 10px 12px; background: var(--card);
    border: 1px solid var(--border); border-radius: 8px; color: var(--fg); font-size: 14px;
}
.search-form input:focus { outline: none; border-color: var(--accent); }

.result-list, .doc-timeline, .note-list, .action-list { list-style: none; padding: 0; margin: 12px 0; }
.result-list li { border-bottom: 1px solid var(--border); }
.result-list li a { display: flex; gap: 12px; padding: 10px 4px; }
.result-list .name { color: var(--fg); }

.doc-timeline li { padding: 8px 4px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; }
.doc-timeline .date { color: var(--muted); font-size: 12px; font-family: monospace; min-width: 130px; }

.fin-table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.fin-table th, .fin-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.fin-table td.num, .fin-table th.num { text-align: right; font-family: monospace; }
.fin-table.compare th { color: var(--fg); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* クリックで内訳ページへ飛ぶ行 */
.fin-table tbody tr.row-link { cursor: pointer; }
.fin-table tbody tr.row-link:hover { background: rgba(255, 255, 255, 0.05); }
.fin-table tbody tr.row-link .cell-link { color: inherit; text-decoration: none; }
.fin-table tbody tr.row-link:hover .cell-link { text-decoration: underline; }

/* 現物・信用を分けて並べるセクション */
.product-section { margin: 28px 0; padding: 18px 18px 6px; border: 1px solid var(--border); border-radius: 12px; background: rgba(255, 255, 255, 0.015); }
.product-title { margin-top: 0; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.product-section h3 { margin-top: 22px; }
.product-section h4 { margin: 16px 0 6px; font-size: 14px; color: var(--muted); }

/* 集計表: 行選択して実現損益を合計 */
.sum-group { margin: 6px 0 16px; }
.pick-cell { width: 34px; text-align: center !important; }
.pick-cell input { cursor: pointer; }
.sum-table tbody tr:hover { background: rgba(255, 255, 255, 0.04); }
.sum-bar { display: flex; align-items: center; gap: 14px; margin-top: 8px; padding: 8px 12px; border: 1px dashed var(--border); border-radius: 8px; font-size: 13px; color: var(--muted); background: var(--card); }
.sum-group.has-selection .sum-bar { border-style: solid; border-color: var(--accent); color: var(--fg); }
.sum-bar .sel-sum { font-family: monospace; font-weight: 700; font-size: 15px; }
.sum-bar .btn-pill { padding: 4px 12px; }

/* 期間表示・期間フィルタ */
.period-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 12px 0 18px; padding: 12px 14px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; }
.period-info { margin: 0; white-space: nowrap; }
.period-form { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0; }
.period-form label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.period-form input[type="date"] { padding: 6px 8px; background: var(--card); border: 1px solid var(--border); border-radius: 6px; color: var(--fg); color-scheme: dark; }
.period-form .btn { padding: 6px 14px; }

/* 発散型横棒グラフ（プラス=右/緑, マイナス=左/赤） */
.bar-chart { margin: 12px 0 20px; }
.chart-row { display: flex; align-items: center; gap: 10px; margin: 5px 0; }
.chart-label { flex: none; width: 130px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-track { position: relative; flex: 1; height: 16px; min-width: 120px; background: var(--card); border-radius: 4px; }
.chart-track::before { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--border); }
.chart-bar { position: absolute; top: 2px; bottom: 2px; border-radius: 3px; min-width: 1px; }
.chart-bar.pos { left: 50%; background: #6effb0; }
.chart-bar.neg { right: 50%; background: #ff8a8a; }
.chart-val { flex: none; width: 110px; text-align: right; font-family: monospace; font-size: 13px; }
@media (max-width: 640px) { .chart-label { width: 84px; } .chart-val { width: 88px; } }

/* 年度別×銘柄別クロス表: 合計行・合計列を強調 */
.pivot-table tfoot th, .pivot-table tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }
.pivot-table thead th:last-child, .pivot-table tbody td:last-child, .pivot-table tfoot td:last-child { font-weight: 700; border-left: 1px solid var(--border); }
.pivot-table tbody tr:hover { background: var(--card); }

.next-actions { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin: 16px 0; }
.next-actions h2 { margin-top: 0; border: none; }
.action-list li, .note-list li { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.note-list li.done a { color: var(--muted); text-decoration: line-through; }

.phase-tag { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); }
.phase-plan { color: #6cf; border-color: #355; }
.phase-do { color: #6f9; border-color: #353; }
.phase-check { color: #fc6; border-color: #553; }
.phase-act { color: #f88; border-color: #533; }

.check-btn { background: none; border: none; color: var(--accent); font-size: 16px; cursor: pointer; padding: 0; }
.link-button.danger { color: #f88; }

.stacked-form { display: flex; flex-direction: column; gap: 14px; margin: 16px 0; }
.stacked-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.stacked-form label.checkbox { flex-direction: row; align-items: center; }
.stacked-form input[type="text"], .stacked-form select, .stacked-form textarea {
    padding: 10px 12px; background: var(--card); border: 1px solid var(--border);
    border-radius: 8px; color: var(--fg); font-size: 14px; font-family: inherit;
}
.stacked-form input:focus, .stacked-form select:focus, .stacked-form textarea:focus { outline: none; border-color: var(--accent); }

/* ============ App layout: left sidebar ============ */
.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    background: rgba(12, 16, 26, 0.96);
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--border);
    z-index: 40;
}
.has-sidebar .app-shell { margin-left: var(--sidebar-w); }

.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
}
.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
}
.sidebar-close:hover { color: var(--fg); }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 12px 20px;
}
.nav-section {
    font-size: 11px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--muted);
    margin: 18px 12px 8px;
}
.nav-section:first-child { margin-top: 4px; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--fg);
    text-decoration: none;
    font-size: 14px;
    border-left: 2px solid transparent;
    transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.05); }
.nav-item.is-active {
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.14), rgba(123, 47, 247, 0.14));
    border-left-color: var(--accent);
    color: var(--accent);
}
.nav-ico { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.nav-label { white-space: nowrap; }

.sidebar-foot {
    border-top: 1px solid var(--border);
    padding: 14px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.sidebar-foot .nav-user {
    font-size: 12px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

/* Hamburger toggle (shown on mobile only) */
.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 40px;
    height: 40px;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
}
.nav-toggle span {
    display: block;
    height: 2px;
    width: 22px;
    background: var(--fg);
    border-radius: 2px;
    transition: transform 0.2s, opacity 0.2s;
}
.logo-mobile { display: none; }
.header-spacer { flex: 1; }
.header-user { display: flex; align-items: center; gap: 16px; }
.header-user a {
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
}
.header-user a:hover { color: var(--accent); }
.header-user .link-button { font-size: 13px; }

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 30;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

/* Tablet / mobile: sidebar becomes an off-canvas drawer */
@media (max-width: 900px) {
    .has-sidebar .app-shell { margin-left: 0; }
    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
    }
    body.sidebar-open .app-sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-overlay { opacity: 1; pointer-events: auto; }
    .sidebar-close { display: block; }
    .has-sidebar .nav-toggle { display: flex; }
    .has-sidebar .logo-mobile { display: inline-block; }
    .has-sidebar .site-header .container { gap: 12px; }
}

/* ============ Global polish ============ */
/* Text selection in the brand color */
::selection { background: rgba(0, 212, 255, 0.30); color: #fff; }

/* Keyboard focus ring (mouse clicks stay clean via :focus-visible) */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.nav-item:focus-visible,
.card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 6px;
}

/* Thin, theme-matched scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.18) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.14);
    border: 2px solid transparent;
    background-clip: padding-box;
    border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.26);
    background-clip: padding-box;
}

/* Smooth lift on interactive cards/buttons */
.card, .home-card, .btn, .btn-pill, .nav-item { will-change: transform; }

/* Trades: filter + 一覧ツールバー / ページネーション */
.trades-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin: 12px 0;
}
.filter-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.trades-bottom-actions { margin-top: 16px; }
.pager {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    margin-top: 16px;
}
.pager-status { font-size: 13px; opacity: 0.7; }

/* 入出金: 期間クイックボタン（年次・月次） */
.quick-period { display: flex; flex-direction: column; gap: 10px; margin: 12px 0 4px; }
.quick-row { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.quick-label {
    flex: 0 0 auto;
    min-width: 3.2em;
    padding-top: 6px;
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
}
.quick-label .quick-sub { font-weight: 400; margin-left: 6px; opacity: 0.8; }

/* 入出金: 期間合計の KPI カード */
.cash-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin: 16px 0 22px;
}
.stat-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 16px 18px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.stat-card.stat-in { border-left: 4px solid #6effb0; }
.stat-card.stat-out { border-left: 4px solid #ff8a8a; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value {
    font-size: 1.7rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
    line-height: 1.2;
}
.stat-unit { font-size: 0.8rem; font-weight: 500; margin-left: 4px; color: var(--muted); }

/* ダッシュボード（TOP） */
.dashboard { padding: 32px 0 64px; }
.dash-head { margin-bottom: 18px; }
.dash-head h1 { margin-bottom: 4px; }
.dashboard h2 {
    display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
    font-size: 18px; margin: 32px 0 12px;
    border-bottom: 1px solid var(--border); padding-bottom: 6px;
}
.head-link { font-size: 13px; font-weight: 400; margin-left: auto; }
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin: 8px 0 8px;
}
.stat-col { display: flex; flex-direction: column; gap: 14px; }
.stat-col .stat-card { flex: 1; }
.stat-value small { font-size: 0.8rem; font-weight: 500; color: var(--muted); margin-left: 2px; }
.stat-sub { font-size: 12px; color: var(--muted); }
.dash-cols {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    align-items: start;
}
.dash-col h2 { margin-top: 24px; }
.dash-col .fin-table td, .dash-col .fin-table th { padding: 6px 10px; font-size: 13px; white-space: nowrap; }
.dash-col .fin-table td.name-cell { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.ellip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: 'SFMono-Regular', Consolas, monospace; font-size: 12px; color: var(--muted); }
.dashboard .cards { margin-top: 8px; }

/* ============ Smartphone tuning ============ */
/* スマホでは左右余白を詰めて表領域を広げ、フォント・余白を圧縮する。
   左ペインはドロワー化済み（max-width:900px）なのでここでは中身を最適化。 */
@media (max-width: 640px) {
    .container { padding: 0 14px; }

    .analysis { padding: 24px 0 48px; }
    .analysis h1 { font-size: 22px; }
    .analysis h2 { font-size: 16px; margin: 24px 0 10px; }
    .dashboard { padding: 24px 0 48px; }

    /* KPI カードはスマホで 2 列に（間延び防止） */
    .stat-grid,
    .cash-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .stat-value { font-size: 1.3rem; }
    .stat-card { padding: 12px 14px; }

    /* 期間バー・期間フォームは縦積みにして各要素を広く使う */
    .period-bar { flex-direction: column; align-items: stretch; gap: 12px; }
    .period-form { width: 100%; }
    .period-form label { flex: 1 1 calc(50% - 5px); }
    .period-form input[type="date"] { width: 100%; }
    .period-form .btn { flex: 1 1 100%; text-align: center; }

    /* 幅広テーブルはフォント・セル余白を圧縮して横スクロール量を抑える */
    .fin-table { font-size: 12px; }
    .fin-table th,
    .fin-table td { padding: 6px 8px; }

    /* CSV アップロードのフィルタフォーム（ドロップゾーン）の余白を圧縮 */
    .filter-form { padding: 12px; }
    .dropzone { padding: 22px 14px; }

    /* 2 カラムのダッシュボードは 1 列に */
    .dash-cols { grid-template-columns: 1fr; gap: 16px; }
}

/* 極小幅（〜380px）では KPI カードを 1 列に戻して数値の折返しを防ぐ */
@media (max-width: 380px) {
    .stat-grid,
    .cash-stats { grid-template-columns: 1fr; }
}

/* Respect reduced-motion */
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* 入出金明細：摘要の説明（凡例） */
.desc-legend { margin-top: 10px; font-size: 13px; }
.desc-legend > summary {
    cursor: pointer; color: var(--muted); width: fit-content;
    list-style: none; user-select: none;
}
.desc-legend > summary::before { content: "▸ "; }
.desc-legend[open] > summary::before { content: "▾ "; }
.desc-legend > summary:hover { color: var(--accent); }
.desc-legend-list {
    margin: 8px 0 0; padding: 12px 14px;
    background: var(--card); border: 1px solid var(--border); border-radius: 8px;
}
.desc-legend-list dt { color: var(--accent); font-weight: 600; margin-top: 8px; }
.desc-legend-list dt:first-child { margin-top: 0; }
.desc-legend-list dd { margin: 2px 0 0; color: var(--muted); line-height: 1.5; }

/* ===== ヘッダーのユーザードロップダウンメニュー ===== */
.user-menu { position: relative; }
.user-menu-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--card);
    color: var(--fg);
    font-size: 13px;
    cursor: pointer;
    list-style: none;
    user-select: none;
    transition: border-color 0.2s, background 0.2s;
}
.user-menu-trigger::-webkit-details-marker { display: none; }
.user-menu-trigger:hover { border-color: var(--accent); }
.user-avatar { font-size: 15px; line-height: 1; }
.user-menu-name { color: var(--fg); font-weight: 600; }
.user-menu-caret { color: var(--muted); font-size: 11px; transition: transform 0.2s; }
.user-menu[open] .user-menu-trigger { border-color: var(--accent); background: rgba(0, 212, 255, 0.08); }
.user-menu[open] .user-menu-caret { transform: rotate(180deg); }

.user-menu-pop {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    background: #141a26;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    padding: 6px;
    z-index: 200;
    animation: userMenuIn 0.14s ease-out;
}
@keyframes userMenuIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.user-menu-head {
    display: flex;
    flex-direction: column;
    padding: 8px 12px 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 6px;
}
.user-menu-hello { font-size: 11px; color: var(--muted); }
.user-menu-who { font-size: 14px; font-weight: 700; color: var(--accent); }
.user-menu-form { margin: 0; }
.user-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    background: none;
    border-radius: 8px;
    color: var(--fg);
    font-size: 14px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.user-menu-item:hover { background: rgba(255, 255, 255, 0.06); color: var(--accent); }
.user-menu-item.danger { color: #ff6b6b; }
.user-menu-item.danger:hover { background: rgba(255, 107, 107, 0.1); color: #ff8787; }
.user-menu-ico { font-size: 15px; line-height: 1; width: 18px; text-align: center; }

/* ===== 期間サマリ（現在の表示期間を分かりやすく） ===== */
.period-summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
    margin: 6px 0 18px;
}
.period-now {
    display: inline-flex;
    align-items: baseline;
    gap: 10px;
    padding: 8px 16px;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.14), rgba(123, 47, 247, 0.14));
    border: 1px solid rgba(0, 212, 255, 0.35);
}
.period-now-ico { font-size: 15px; }
.period-now-cap { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }
.period-now-label { font-size: 16px; font-weight: 800; color: var(--accent); }
.period-now-range { font-size: 12px; color: var(--muted); }
.period-full { font-size: 12px; color: var(--muted); }
.period-full strong { color: var(--fg); font-weight: 600; }
