:root {
    --app-safe-top: 0px;
    --page-bg: #f7f7f7;
    --surface: #ffffff;
    --text-main: #111111;
    --text-soft: #929292;
    --text-muted: #a7a7a7;
    --gold: #b2955d;
    --gold-soft: rgba(178, 149, 93, 0.16);
    --line: #eeeeee;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--page-bg);
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
    font-size: 14px;
    -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; }
button { border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }

.app-shell {
    width: min(430px, 100%);
    min-height: 100vh;
    margin: 0 auto;
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
    background: var(--page-bg);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: calc(52px + var(--app-safe-top));
    padding-top: var(--app-safe-top);
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) 52px;
    align-items: center;
    background: #f7f8fc;
    border-bottom: 1px solid rgba(15, 23, 42, 0.05);
}

.topbar h1 {
    margin: 0;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0;
}

.top-back {
    height: 52px;
    display: grid;
    place-items: center;
    color: #616161;
}

.top-back svg { width: 22px; height: 22px; }

.settings-main { padding: 14px 12px 24px; }

.account-panel {
    width: 100%;
    min-height: 88px;
    padding: 14px 14px;
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) auto 18px;
    align-items: center;
    gap: 11px;
    border: 1px solid #ededed;
    border-radius: 7px;
    background: var(--surface);
    color: inherit;
    text-align: left;
}

.avatar {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 50%;
    background: #eee8dd;
    color: #8b7444;
    font-size: 19px;
    font-weight: 700;
}

.avatar.has-image {
    background-position: center;
    background-size: cover;
    color: transparent;
}

.account-copy, .row-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.account-copy { gap: 6px; }
.account-copy strong { font-size: 17px; line-height: 1.1; }
.account-copy small, .row-copy small { color: var(--text-soft); font-size: 12px; line-height: 1.3; }
.account-action { color: var(--gold); font-size: 13px; white-space: nowrap; }
.chevron { width: 18px; height: 18px; color: #b8b8b8; flex: 0 0 auto; }

.setting-section { margin-top: 20px; }
.setting-section h2 {
    margin: 0 0 8px;
    padding-left: 4px;
    color: #858585;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0;
}

.setting-group {
    overflow: hidden;
    border: 1px solid #ededed;
    border-radius: 7px;
    background: var(--surface);
}

.setting-row {
    position: relative;
    width: 100%;
    min-height: 58px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 11px;
    background: var(--surface);
    color: inherit;
    text-align: left;
}

.setting-row + .setting-row::before {
    content: "";
    position: absolute;
    top: 0;
    left: 14px;
    right: 0;
    height: 1px;
    background: var(--line);
}

.setting-row:active, .account-panel:active { background: #fafafa; }
.row-copy { flex: 1; gap: 4px; }
.row-copy strong { font-size: 15px; font-weight: 500; line-height: 1.2; }
.row-value { color: var(--text-soft); font-size: 12px; white-space: nowrap; }
.row-icon { width: 20px; height: 20px; color: #aaa; }

.row-leading {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    flex: 0 0 auto;
}

.row-leading svg { width: 19px; height: 19px; }
.records-leading { color: #856f45; background: #f3ede1; }
.cache-leading { color: #747474; background: #f0f0f0; }

.calendar-row { flex-wrap: wrap; }
.calendar-row .row-copy { flex: 0 0 72px; }
.calendar-segment {
    min-width: 188px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    padding: 2px;
    border-radius: 5px;
    background: #f1f1f1;
}

.calendar-segment button {
    height: 30px;
    padding: 0 12px;
    border-radius: 4px;
    background: transparent;
    color: #777;
    font-size: 13px;
}

.calendar-segment button.active {
    background: #fff;
    color: #8b7444;
    font-weight: 600;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
}

.switch {
    width: 42px;
    height: 24px;
    padding: 2px;
    display: flex;
    justify-content: flex-start;
    border-radius: 12px;
    background: #d6d6d6;
    transition: background .18s ease;
    flex: 0 0 auto;
}

.switch i {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
    transition: transform .18s ease;
}

.setting-row[aria-pressed="true"] .switch { background: var(--gold); }
.setting-row[aria-pressed="true"] .switch i { transform: translateX(18px); }
.static-row { cursor: default; }

.bottom-tabs {
    position: fixed;
    left: 50%;
    bottom: 0;
    z-index: 40;
    width: min(430px, 100vw);
    height: 64px;
    transform: translateX(-50%);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: var(--surface);
    border-top: 1px solid #f0f0f0;
    padding-bottom: env(safe-area-inset-bottom);
}

.tab-item {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--text-soft);
    font-size: 12px;
    font-weight: 700;
}

.tab-item svg { width: 20px; height: 20px; }
.tab-item.active { color: var(--gold); }
.tab-item:active { opacity: .72; }

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(82px + env(safe-area-inset-bottom));
    z-index: 120;
    max-width: calc(100vw - 40px);
    padding: 9px 15px;
    transform: translate(-50%, 12px);
    border-radius: 5px;
    background: rgba(17, 17, 17, .86);
    color: #fff;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: .18s ease;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 350px) {
    .settings-main { padding-left: 9px; padding-right: 9px; }
    .account-panel { grid-template-columns: 46px minmax(0, 1fr) auto 14px; gap: 8px; }
    .avatar { width: 46px; height: 46px; }
    .calendar-row .row-copy { flex-basis: 100%; }
    .calendar-segment { width: 100%; }
    .tab-item { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
