.advice-link {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    line-height: inherit;
    text-align: left;
    cursor: pointer;
}
.advice-link:focus-visible { outline: 3px solid currentColor; outline-offset: 3px; border-radius: .3rem; }
.advice-more { display: block; margin-top: .3rem; font-size: .82rem; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

html.advice-open { overflow: hidden; }

.advice-dialog {
    width: min(580px, calc(100% - 2rem));
    max-height: min(88vh, 760px);
    max-height: min(88dvh, 760px);
    padding: 0;
    box-sizing: border-box;
    border: 0;
    border-radius: 1rem;
    background: #fff;
    color: #17324d;
    font-family: "Noto Sans Thai", "Leelawadee UI", system-ui, sans-serif;
    box-shadow: 0 20px 50px #0a19234d;
    overflow: hidden;
}
/* The dialog itself scrolls (no flex-shrinking body): WebKit collapses a flex:1 body inside an auto-height dialog. */
.advice-dialog { overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.advice-dialog[open] { display: block; }
.advice-dialog::backdrop { background: #0a1923a6; }

.advice-header {
    position: relative;
    flex: none;
    padding: 1.4rem 4rem 1.2rem 1.4rem;
    background: var(--band, #17324d);
    color: var(--on-band, #fff);
}
.advice-title { margin: 0; font-size: clamp(1.3rem, 4vw, 1.7rem); line-height: 1.3; }
.advice-range { margin: .5rem 0 0; display: inline-block; padding: .25rem .8rem; border: 1px solid currentColor; border-radius: 99px; font-size: .88rem; font-weight: 700; }
.advice-close {
    position: absolute;
    top: .8rem;
    right: .8rem;
    display: grid;
    place-items: center;
    box-sizing: border-box;
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 0;
    margin: 0;
    border: 2px solid currentColor;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 1.6rem;
    line-height: 1;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}
.advice-close:focus-visible, .advice-level:focus-visible, .advice-definitions summary:focus-visible, .advice-source a:focus-visible { outline: 3px solid #00bff3; outline-offset: 2px; }

.advice-body { padding: 1.1rem 1.4rem 1.4rem; }
.advice-status { margin: 0 0 .6rem; color: #52717d; }
.advice-status:empty { display: none; }

.advice-switcher { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .4rem; }
.advice-level {
    display: grid;
    gap: .1rem;
    min-height: 48px;
    padding: .45rem .2rem .35rem;
    border: 1px solid #d9e6ea;
    border-bottom: 5px solid var(--c);
    border-radius: .55rem .55rem .3rem .3rem;
    background: #fff;
    color: #17324d;
    font: inherit;
    font-size: .76rem;
    cursor: pointer;
}
.advice-level[aria-pressed="true"] { background: #f4f8fa; border-color: #17324d; border-bottom-color: var(--c); font-weight: 700; }
.advice-level-now { font-size: .75rem; color: #52717d; }

.advice-summary { margin: 1rem 0; font-size: 1.05rem; line-height: 1.6; font-weight: 700; }
.advice-groups { display: grid; gap: .75rem; }
.advice-group { padding: .9rem 1rem; border: 1px solid #d9e6ea; border-left: 5px solid #17324d; border-radius: .7rem; background: #f8fbfc; }
.advice-group-at_risk { border-left-color: #F26522; }
.advice-group-everyone { border-left-color: #CD0000; }
.advice-group h3 { margin: 0 0 .4rem; font-size: 1rem; }
.advice-group ul { margin: 0; padding-left: 1.2rem; line-height: 1.7; }
.advice-group li + li { margin-top: .25rem; }

.advice-footer { margin-top: 1.1rem; padding-top: .9rem; border-top: 1px solid #d9e6ea; font-size: .82rem; color: #52717d; line-height: 1.65; }
.advice-footer p { margin: .4rem 0 0; }
.advice-definitions summary { cursor: pointer; font-weight: 700; color: #17324d; }
.advice-source a { color: #17324d; }

@media (max-width: 600px) {
    .advice-dialog { width: 100%; max-width: 100%; max-height: 90vh; max-height: 90dvh; margin: auto 0 0; border-radius: 1rem 1rem 0 0; padding-bottom: env(safe-area-inset-bottom); }
    .advice-header { padding: 1.1rem 4rem 1rem 1.1rem; }
    .advice-body { padding: 1rem 1.1rem 1.5rem; }
}
@media (prefers-reduced-motion: no-preference) {
    .advice-dialog[open] { animation: advice-in .18s ease-out; }
    @keyframes advice-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
}
.advice-link:disabled { cursor: default; }
