* { box-sizing: border-box; }

:root {
    color-scheme: light;
    --bg: #f3f5f8;
    --card: #ffffff;
    --text: #171b22;
    --muted: #687180;
    --line: #dfe4eb;
    --primary: #20252d;
    --primary-hover: #0f1318;
    --soft: #f7f8fa;
    --success: #e9f7ed;
    --danger: #b42318;
    --danger-soft: #fff0ee;
    --shadow: 0 14px 40px rgba(20, 28, 40, 0.08);
}

html { min-height: 100%; }
body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
    line-height: 1.7;
}
a { color: inherit; }

.app-shell {
    min-height: 100svh;
    display: flex;
    flex-direction: column;
}

.site-header {
    background: rgba(255,255,255,.96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}
.header-inner {
    width: min(1040px, calc(100% - 40px));
    min-height: 88px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}
.brand {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
    text-decoration: none;
}
.brand-title {
    font-size: 30px;
    line-height: 1;
    letter-spacing: -0.03em;
    font-weight: 900;
}
.brand-subcopy {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}
.header-action {
    display: inline-flex;
    min-height: 42px;
    padding: 8px 18px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    text-decoration: none;
    font-weight: 800;
}
.header-action:hover { border-color: #aab3c0; }

nav { display: flex; gap: 18px; }
nav a { text-decoration: none; color: var(--muted); }

.container {
    width: min(900px, calc(100% - 32px));
    margin: 38px auto 80px;
}
.container.narrow { width: min(600px, calc(100% - 32px)); }
.card {
    margin-bottom: 24px;
    padding: 28px;
    background: var(--card);
    border: 1px solid rgba(223,228,235,.8);
    border-radius: 18px;
    box-shadow: 0 8px 26px rgba(20,28,40,.05);
}
h1,h2,h3 { line-height: 1.35; }
h1,h2 { margin-top: 0; }

label { display: block; margin-bottom: 20px; font-weight: 800; }
input,textarea,button,.button { font: inherit; }
input,textarea {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 13px 15px;
    border: 1px solid #cfd6df;
    border-radius: 11px;
    background: #fff;
    color: var(--text);
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}
input:focus,textarea:focus {
    border-color: #707b8b;
    box-shadow: 0 0 0 4px rgba(32,37,45,.08);
}
textarea { min-height: 190px; resize: vertical; }
button,.button {
    display: inline-flex;
    width: 100%;
    min-height: 52px;
    padding: 12px 18px;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 11px;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
    font-weight: 900;
    cursor: pointer;
    transition: background .2s, transform .2s;
}
button:hover,.button:hover { background: var(--primary-hover); }
button:active,.button:active { transform: translateY(1px); }

.notice { margin-bottom: 20px; padding: 13px 15px; border-radius: 10px; }
.notice.success { background: var(--success); }
.notice.error { background: var(--danger-soft); color: #7a1b14; }
.muted { color: var(--muted); }

/* Auth */
.auth-main {
    width: min(680px, calc(100% - 32px));
    margin: 46px auto;
    flex: 1 0 auto;
}
.auth-card {
    padding: 38px;
    background: #fff;
    border: 1px solid rgba(223,228,235,.9);
    border-radius: 22px;
    box-shadow: var(--shadow);
}
.auth-card-wide { width: min(760px, calc(100vw - 32px)); margin-left: 50%; transform: translateX(-50%); }
.auth-heading { margin-bottom: 28px; }
.auth-heading .eyebrow {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .12em;
}
.auth-heading h1 {
    margin: 0;
    font-size: 34px;
    letter-spacing: -0.02em;
}
.auth-heading p:last-child { margin: 10px 0 0; color: var(--muted); }
.auth-form > button { margin-top: 4px; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 22px 20px;
}

.form-grid > label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    margin: 0;
}

.form-grid > label input {
    width: 100%;
    min-height: 54px;
    margin-top: 0;
}

.field-label-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-height: 24px;
    line-height: 1.45;
}

.field-hint {
    display: inline;
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}
.auth-actions {
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 12px;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--line);
}
.auth-action-card {
    display: grid;
    grid-template-columns: 38px minmax(0,1fr) auto;
    gap: 12px;
    align-items: center;
    min-width: 0;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: var(--soft);
    text-decoration: none;
    transition: border-color .2s, background .2s, transform .2s;
}
.auth-action-card:hover { border-color: #aeb7c4; background: #fff; transform: translateY(-1px); }
.auth-action-icon {
    display: inline-flex;
    width: 38px;
    height: 38px;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: #fff;
    border: 1px solid var(--line);
    font-weight: 900;
}
.auth-action-body { display: flex; flex-direction: column; min-width: 0; }
.auth-action-body strong { line-height: 1.4; }
.auth-action-body small { margin-top: 3px; color: var(--muted); line-height: 1.45; }
.auth-action-arrow { font-size: 20px; }

.consent-panel {
    margin: 4px 0 22px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: var(--soft);
}
.consent-panel legend { padding: 0 8px; font-weight: 900; }
.consent-row {
    display: grid;
    grid-template-columns: 20px minmax(0,1fr);
    gap: 12px;
    align-items: start;
    margin: 0;
    font-weight: 700;
    cursor: pointer;
}
.consent-row + .consent-row { margin-top: 15px; padding-top: 15px; border-top: 1px solid var(--line); }
.consent-row input { width: 20px; height: 20px; margin: 3px 0 0; padding: 0; }
.consent-row span { min-width: 0; }
.consent-row a { text-decoration: underline; text-underline-offset: 3px; }
.back-link-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-top: 20px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    text-decoration: none;
    font-weight: 800;
}
.back-link-card:hover { border-color: #aeb7c4; }
.text-back-link { display: inline-block; margin-top: 20px; color: var(--muted); }

.site-footer {
    margin-top: auto;
    padding: 26px 0 32px;
    border-top: 1px solid var(--line);
    background: #fff;
}
.footer-inner {
    width: min(1040px, calc(100% - 40px));
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}
.footer-copy { margin: 0; color: var(--muted); font-size: 13px; }
.footer-links { display: flex; gap: 20px; }
.footer-links a { color: var(--muted); font-size: 13px; text-decoration: none; }
.footer-links a:hover { color: var(--text); text-decoration: underline; }

/* Journal */
.entry { padding: 24px 0; border-top: 1px solid var(--line); }
.entry:first-of-type { border-top: 0; }
.entry-head { display:flex; align-items:flex-start; justify-content:space-between; gap:16px; margin-bottom:0; }
.entry-actions { display:flex; align-items:center; flex-wrap:wrap; gap:14px; }
.inline-form { margin:0; }
.button-link { width:auto; min-height:0; padding:0; border:0; border-radius:0; background:transparent; color:var(--text); text-decoration:underline; font-weight:400; }
.button-link:hover { background:transparent; }
.entry-content { margin-top:10px; margin-bottom:22px; white-space:normal; text-align:left; }
.ai-details { margin-top:0; border-radius:12px; background:#f7f8fa; }
.ai-details summary { padding:14px 18px; cursor:pointer; font-weight:800; }
.ai-details[open] summary { border-bottom:1px solid var(--line); }
.ai-box { padding:18px; }
.chips { display:flex; flex-wrap:wrap; gap:8px; }
.chip { display:inline-block; padding:5px 10px; border-radius:999px; background:#e9edf2; font-size:14px; }
.pagination { display:flex; justify-content:center; flex-wrap:wrap; gap:8px; margin-top:28px; }
.page-link { display:inline-flex; min-width:40px; min-height:40px; padding:7px 12px; align-items:center; justify-content:center; border:1px solid var(--line); border-radius:8px; background:#fff; text-decoration:none; }
.page-link.current { border-color:var(--primary); background:var(--primary); color:#fff; }
.danger-form { margin-top:30px; padding-top:22px; border-top:1px solid var(--line); }
button.danger,.button.danger { background:var(--danger); }
.danger-zone { border:1px solid #f2c2bd; }
.account-summary { margin:0; }
.account-summary div { display:grid; grid-template-columns:140px minmax(0,1fr); gap:18px; padding:13px 0; border-top:1px solid var(--line); }
.account-summary div:first-child { border-top:0; }
.account-summary dt { color:var(--muted); font-weight:700; }
.account-summary dd { margin:0; overflow-wrap:anywhere; }

/* Reports */
.report-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:24px; }
.report-generator { display:flex; align-items:flex-end; justify-content:space-between; gap:24px; }
.report-generator h2 { margin-bottom:6px; font-size:20px; }
.report-generator form { flex:0 0 auto; }
.report-label { margin:0 0 6px; color:var(--muted); font-size:14px; font-weight:800; }
.report-button { width:auto; min-width:136px; }
.report-button:disabled { cursor:not-allowed; opacity:.45; }
.report-item { padding:24px 0; border-top:1px solid var(--line); }
.report-item:first-of-type { border-top:0; }
.report-item-head { display:flex; align-items:center; justify-content:space-between; gap:16px; }
.report-count { color:var(--muted); font-size:14px; }
.report-details { margin-top:18px; }
.report-details summary { cursor:pointer; font-weight:700; }
.report-detail-content { margin-top:16px; padding:18px; border-radius:12px; background:#f7f8fa; }
.report-detail-content h3:first-child { margin-top:0; }
.report-detail-content li + li { margin-top:8px; }

/* Legal */
.legal-document { width:min(820px,100%); margin-inline:auto; }
.legal-document h2 { margin-top:34px; font-size:21px; }
.legal-document li + li { margin-top:7px; }
.legal-document a { overflow-wrap:anywhere; }
.legal-date { margin-top:38px; padding-top:20px; border-top:1px solid var(--line); color:var(--muted); font-size:14px; }

@media (max-width: 760px) {
    .header-inner { width:min(100% - 28px,1040px); min-height:76px; }
    .brand-title { font-size:25px; }
    .brand-subcopy { display:none; }
    .header-action { min-height:38px; padding:7px 13px; font-size:14px; }
    .auth-main { margin:24px auto 34px; }
    .auth-card,.auth-card-wide { width:auto; margin:0; transform:none; padding:24px 20px; border-radius:17px; }
    .auth-heading h1 { font-size:29px; }
    .form-grid,.auth-actions,.report-grid { grid-template-columns:1fr; }
    .footer-inner { flex-direction:column; text-align:center; }
    .footer-links { justify-content:center; flex-wrap:wrap; }
    .report-generator { display:block; }
    .report-generator form { margin-top:18px; }
    .report-button { width:100%; }
    .report-item-head { display:block; }
    .report-count { display:block; margin-top:4px; }
}

@media (max-width: 600px) {
    .container { margin-top:22px; }
    .card { padding:20px; }
    .entry-head { display:block; }
    .entry-actions { margin-top:8px; }
    .account-summary div { display:block; }
    .account-summary dd { margin-top:4px; }
    nav { gap:10px; flex-wrap:wrap; justify-content:flex-end; }
}


/* Shared layout */
.app-nav,
.guest-nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 18px;
}

.app-nav a,
.guest-nav a {
    position: relative;
    color: var(--muted);
    text-decoration: none;
    font-weight: 700;
}

.app-nav a:hover,
.guest-nav a:hover,
.app-nav a.active {
    color: var(--text);
}

.app-nav a.active::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -9px;
    height: 2px;
    border-radius: 999px;
    background: var(--primary);
}

.guest-nav .header-action {
    color: var(--text);
}

@media (max-width: 700px) {
    .header-inner {
        min-height: 76px;
        align-items: flex-start;
        padding-block: 15px;
    }

    .brand-title {
        font-size: 25px;
    }

    .brand-subcopy {
        display: none;
    }

    .app-nav,
    .guest-nav {
        justify-content: flex-end;
        gap: 7px 13px;
        font-size: 14px;
    }

    .app-nav a.active::after {
        bottom: -5px;
    }

    .footer-inner {
        flex-direction: column;
        text-align: center;
    }
}


/* Layout hotfix v2 */
.consent-panel .consent-row {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    gap: 12px !important;
    width: 100% !important;
    margin: 0 !important;
    text-align: left !important;
}

.consent-panel .consent-row + .consent-row {
    margin-top: 15px !important;
    padding-top: 15px !important;
    border-top: 1px solid var(--line) !important;
}

.consent-panel .consent-row input[type="checkbox"] {
    display: block !important;
    position: static !important;
    flex: 0 0 20px !important;
    width: 20px !important;
    min-width: 20px !important;
    max-width: 20px !important;
    height: 20px !important;
    margin: 3px 0 0 !important;
    padding: 0 !important;
    transform: none !important;
}

.consent-panel .consent-row > span {
    display: block !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    margin: 0 !important;
    text-align: left !important;
}

.site-header,
.site-footer {
    display: block !important;
}
