.sleep-diary-tool {
    padding: 88px 0;
    background: var(--bg-soft);
    border-top: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
}

.diary-tool-header {
    max-width: 780px;
    margin: 0 auto 38px;
    text-align: center;
}

.diary-tool-header h2 {
    margin: 10px 0 14px;
    font-size: clamp(2rem, 4vw, 3rem);
}

.diary-privacy-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
    padding: 8px 13px;
    border: 1px solid var(--border-light);
    border-radius: 999px;
    background: var(--bg-white);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 700;
}

.diary-actions .diary-download.secondary {
    border: 1px solid var(--brand-blue);
    background: var(--bg-white);
    color: var(--brand-blue);
}

.diary-actions .diary-download.secondary:hover {
    background: var(--brand-light);
}

.diary-app-grid {
    display: grid;
    grid-template-columns: minmax(0, 0.92fr) minmax(420px, 1.08fr);
    gap: 24px;
    align-items: start;
}

.diary-app-card {
    padding: 28px;
    border: 1px solid var(--border-light);
    border-radius: 22px;
    background: var(--bg-white);
    box-shadow: 0 14px 35px rgba(15, 23, 42, 0.06);
}

.diary-app-card h3 {
    margin-bottom: 6px;
    font-size: 1.45rem;
}

.diary-card-intro {
    margin-bottom: 24px;
    color: var(--text-muted);
    font-size: 0.93rem;
}

.diary-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 17px;
}

.diary-field-full {
    grid-column: 1 / -1;
}

.diary-field label,
.diary-checkbox-label {
    display: block;
    margin-bottom: 7px;
    color: var(--text-heading);
    font-size: 0.88rem;
    font-weight: 750;
}

.diary-field input,
.diary-field select,
.diary-field textarea {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    background: var(--bg-soft);
    color: var(--text-main);
    font: 500 0.96rem/1.35 var(--font-body);
}

.diary-field textarea {
    min-height: 92px;
    resize: vertical;
}

.diary-field input:focus,
.diary-field select:focus,
.diary-field textarea:focus,
.diary-tool-button:focus-visible,
.diary-history-button:focus-visible {
    outline: 3px solid rgba(59, 130, 246, 0.3);
    outline-offset: 2px;
}

.diary-range-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 40px;
    gap: 12px;
    align-items: center;
}

.diary-range-row input {
    min-height: 34px;
    padding: 0;
    accent-color: var(--brand-blue);
}

.diary-range-output {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 10px;
    background: var(--brand-light);
    color: var(--brand-blue);
    font-weight: 800;
}

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

.diary-check {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    min-height: 44px;
    padding: 10px;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    background: var(--bg-soft);
    color: var(--text-main);
    font-size: 0.86rem;
    cursor: pointer;
}

.diary-check input {
    width: 18px;
    height: 18px;
    margin-top: 1px;
    accent-color: var(--brand-blue);
}

.diary-optional {
    grid-column: 1 / -1;
    padding: 15px;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    background: var(--bg-soft);
}

.diary-optional summary {
    color: var(--text-heading);
    font-weight: 750;
    cursor: pointer;
}

.diary-optional-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-top: 17px;
}

.diary-form-actions,
.diary-dashboard-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 22px;
}

.diary-tool-button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 10px 17px;
    border: 1px solid var(--brand-blue);
    border-radius: 999px;
    background: transparent;
    color: var(--brand-blue);
    font: 750 0.88rem/1 var(--font-body);
    cursor: pointer;
}

.diary-tool-button.primary {
    background: var(--brand-blue);
    color: #fff;
}

.diary-tool-button.danger {
    border-color: #dc2626;
    color: #dc2626;
}

.diary-tool-button:hover {
    transform: translateY(-1px);
}

.diary-form-error {
    min-height: 22px;
    margin-top: 13px;
    color: #b91c1c;
    font-size: 0.88rem;
    font-weight: 700;
}

.diary-progress {
    margin-bottom: 24px;
}

.diary-progress-top {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
    color: var(--text-muted);
    font-size: 0.86rem;
    font-weight: 700;
}

.diary-progress-track {
    overflow: hidden;
    height: 9px;
    border-radius: 999px;
    background: var(--border-light);
}

.diary-progress-value {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--brand-blue);
    transition: width 0.3s ease;
}

.diary-empty {
    padding: 42px 20px;
    border: 1px dashed var(--border-light);
    border-radius: 16px;
    text-align: center;
    color: var(--text-muted);
}

.diary-empty strong {
    display: block;
    margin-bottom: 7px;
    color: var(--text-heading);
    font-size: 1.05rem;
}

.diary-dashboard-content[hidden],
.diary-empty[hidden] {
    display: none;
}

.diary-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.diary-stat {
    padding: 14px;
    border: 1px solid var(--border-light);
    border-radius: 14px;
    background: var(--bg-soft);
}

.diary-stat-value {
    display: block;
    color: var(--brand-blue);
    font-size: 1.35rem;
    font-weight: 800;
}

.diary-stat-label {
    display: block;
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 0.76rem;
    line-height: 1.3;
}

.diary-chart-wrap {
    margin-top: 24px;
}

.diary-chart-title {
    margin-bottom: 5px;
    color: var(--text-heading);
    font-weight: 800;
}

.diary-chart-legend {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    color: var(--text-muted);
    font-size: 0.78rem;
}

.diary-chart-legend span::before {
    content: "";
    display: inline-block;
    width: 9px;
    height: 9px;
    margin-right: 6px;
    border-radius: 3px;
    background: var(--brand-blue);
}

.diary-chart-legend span:last-child::before {
    background: #f59e0b;
}

.diary-chart {
    display: grid;
    grid-template-columns: repeat(7, minmax(34px, 1fr));
    gap: 8px;
    min-height: 210px;
    padding: 18px 8px 0;
    border-bottom: 1px solid var(--border-light);
    align-items: end;
}

.diary-chart-day {
    display: grid;
    grid-template-rows: 160px auto;
    gap: 8px;
    text-align: center;
}

.diary-chart-bars {
    display: flex;
    align-items: end;
    justify-content: center;
    gap: 4px;
    height: 160px;
}

.diary-chart-bar {
    width: min(18px, 42%);
    min-height: 3px;
    border-radius: 5px 5px 0 0;
    background: var(--brand-blue);
}

.diary-chart-bar.quality {
    background: #f59e0b;
}

.diary-chart-label {
    color: var(--text-muted);
    font-size: 0.7rem;
}

.diary-observations {
    margin-top: 26px;
    padding: 20px;
    border-radius: 16px;
    background: var(--brand-light);
}

.diary-observations h4 {
    margin-bottom: 10px;
    color: var(--brand-blue);
}

.diary-observations ul {
    display: grid;
    gap: 8px;
    padding-left: 19px;
    list-style: disc;
}

.diary-observations li {
    color: var(--text-main);
    font-size: 0.88rem;
}

.diary-history {
    display: grid;
    gap: 9px;
    margin-top: 24px;
}

.diary-history-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 13px 0;
    border-bottom: 1px solid var(--border-light);
}

.diary-history-item strong {
    display: block;
    color: var(--text-heading);
}

.diary-history-meta {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.diary-history-actions {
    display: flex;
    gap: 6px;
}

.diary-history-button {
    min-height: 36px;
    padding: 7px 10px;
    border: 1px solid var(--border-light);
    border-radius: 999px;
    background: var(--bg-white);
    color: var(--brand-blue);
    font: 700 0.76rem/1 var(--font-body);
    cursor: pointer;
}

.diary-tool-footnote {
    margin-top: 20px;
    color: var(--text-muted);
    font-size: 0.8rem;
    line-height: 1.5;
}

[data-theme="dark"] .diary-app-card,
[data-theme="dark"] .diary-privacy-badge,
[data-theme="dark"] .diary-history-button {
    background: var(--bg-white);
}

@media (max-width: 980px) {
    .diary-app-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 650px) {
    .sleep-diary-tool {
        padding: 64px 0;
    }

    .diary-app-card {
        padding: 21px 16px;
    }

    .diary-form-grid,
    .diary-optional-grid,
    .diary-checks {
        grid-template-columns: 1fr;
    }

    .diary-stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .diary-chart {
        gap: 3px;
        padding-inline: 0;
    }

    .diary-chart-label {
        font-size: 0.62rem;
    }

    .diary-dashboard-actions .diary-tool-button {
        flex: 1 1 45%;
    }
}

@media print {
    body > header,
    body > footer,
    .mobile-menu-overlay,
    main > section:not(.sleep-diary-tool),
    .diary-tool-form-card,
    .diary-dashboard-actions,
    #sleeple-consent-banner,
    #sleeple-consent-manage {
        display: none !important;
    }

    .sleep-diary-tool {
        padding: 0;
        border: 0;
        background: #fff;
    }

    .sleep-diary-tool .container {
        width: 100%;
        max-width: none;
    }

    .diary-tool-header {
        margin-bottom: 16px;
    }

    .diary-app-grid {
        display: block;
    }

    .diary-app-card {
        padding: 0;
        border: 0;
        box-shadow: none;
    }

    .diary-stat,
    .diary-observations {
        break-inside: avoid;
    }
}
