:root {
    --green: #2f6e4f;
    --green-soft: #e5f1ea;
    --orange-soft: #f5ede1;
    --red: #9f4038;
    --shadow: 0 24px 64px rgba(25, 27, 24, 0.1);
}

html { min-height: 100%; }
body { min-height: 100vh; }
button, select { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}
[hidden] { display: none !important; }

.account-nav .nav-inner { width: 100%; }
.text-button {
    appearance: none;
    border: 0;
    color: #383b38;
    cursor: pointer;
    font-size: 0.89rem;
    font-weight: 500;
    padding: 0;
}
.text-button:hover { color: var(--accent); }

main {
    margin: 0 auto;
    padding: 132px 32px 96px;
    width: min(1144px, 100%);
}
.loading-view {
    color: var(--muted);
    display: grid;
    font-family: var(--mono);
    font-size: 0.72rem;
    gap: 14px;
    justify-items: center;
    letter-spacing: 0.05em;
    min-height: 55vh;
    place-content: center;
    text-transform: uppercase;
}
.loading-mark {
    animation: spin 0.8s linear infinite;
    border: 2px solid var(--line);
    border-radius: 50%;
    border-top-color: var(--accent);
    height: 28px;
    width: 28px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.sign-in-view {
    display: grid;
    min-height: calc(100vh - 228px);
    place-items: center;
}
.sign-in-card {
    background: var(--surface);
    border: 1px solid var(--line-dark);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 52px 48px 48px;
    text-align: center;
    width: min(520px, 100%);
}
.eyebrow, .card-label {
    color: var(--accent);
    font-family: var(--mono);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    line-height: 1;
    text-transform: uppercase;
}
.sign-in-card h1 {
    font-size: clamp(2.7rem, 7vw, 4.35rem);
    letter-spacing: -0.06em;
    line-height: 1.02;
    margin: 20px 0 22px;
}
.sign-in-card h1 em {
    color: var(--muted);
    font-style: normal;
    font-weight: 400;
}
.sign-in-copy {
    font-size: 1rem;
    line-height: 1.65;
    margin: 0 auto 30px;
    max-width: 390px;
}
.apple-button {
    background: var(--dark);
    border: 1px solid var(--dark);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-weight: 600;
    min-height: 48px;
    transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
    width: min(300px, 100%);
}
.apple-button:hover {
    background: #393c38;
    border-color: #393c38;
    transform: translateY(-1px);
}
.apple-button:disabled { cursor: wait; opacity: 0.7; }
.apple-glyph {
    display: inline-block;
    font-size: 0.66rem;
    margin-right: 9px;
    transform: translateY(-1px);
}
.privacy-note { font-size: 0.78rem; margin-top: 18px; }

.dashboard { animation: rise 0.35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.page-header {
    align-items: flex-end;
    display: flex;
    justify-content: space-between;
    margin-bottom: 30px;
}
.page-header h1 {
    font-size: clamp(2.5rem, 5vw, 4rem);
    letter-spacing: -0.055em;
    line-height: 1;
    margin-top: 12px;
}
.icon-button {
    background: transparent;
    border: 1px solid var(--line-dark);
    border-radius: 6px;
    color: var(--ink-soft);
    cursor: pointer;
    font-size: 1.05rem;
    height: 40px;
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
    width: 40px;
}
.icon-button:hover {
    background: var(--surface);
    border-color: #b7bbb3;
    color: var(--ink);
}

.notice {
    background: var(--orange-soft);
    border: 1px solid #dac8ad;
    border-radius: 6px;
    color: #6c4b28;
    font-size: 0.88rem;
    margin: -8px 0 20px;
    padding: 11px 14px;
}
.balance-card {
    align-items: center;
    background: var(--dark);
    border: 1px solid var(--dark);
    border-radius: 8px;
    box-shadow: 0 24px 64px rgba(25, 27, 24, 0.13);
    color: #fff;
    display: flex;
    gap: 32px;
    justify-content: space-between;
    min-height: 184px;
    padding: 34px 38px;
}
.balance-card .card-label { color: #aeb5ae; }
.balance-line {
    align-items: center;
    display: flex;
    gap: 12px;
    margin-top: 11px;
}
.balance {
    font-size: clamp(2.7rem, 7vw, 4rem);
    font-variant-numeric: tabular-nums;
    font-weight: 550;
    letter-spacing: -0.055em;
    line-height: 1;
}
.balance-note { color: #aeb5ae; font-size: 0.84rem; margin-top: 12px; }
.status-pill {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 999px;
    color: #dce7e1;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 5px 9px;
}
.balance-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}
.primary-button, .secondary-button, .danger-button, .load-more {
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    min-height: 42px;
    padding: 0 18px;
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}
.primary-button {
    background: #fff;
    border: 1px solid #fff;
    color: var(--ink);
}
.primary-button:hover { background: #edf0ec; border-color: #edf0ec; transform: translateY(-1px); }
.secondary-button {
    background: transparent;
    border: 1px solid var(--line-dark);
    color: var(--ink);
}
.balance-card .secondary-button {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.28);
    color: #fff;
}
.secondary-button:hover { background: var(--surface); border-color: #b7bbb3; }
.balance-card .secondary-button:hover { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.5); }
.danger-button {
    background: rgba(159, 64, 56, 0.06);
    border: 1px solid rgba(159, 64, 56, 0.24);
    color: var(--red);
}
.compact { font-size: 0.82rem; min-height: 36px; padding: 0 14px; }
button:disabled, select:disabled { cursor: wait; opacity: 0.58; }

.metric-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(3, 1fr);
    margin: 18px 0;
}
.metric-card, .panel {
    background: var(--surface);
    border: 1px solid var(--line-dark);
}
.metric-card { border-radius: 8px; padding: 22px 24px; }
.metric-card p {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    margin-bottom: 9px;
    text-transform: uppercase;
}
.metric-card strong {
    font-size: 1.5rem;
    font-variant-numeric: tabular-nums;
    font-weight: 550;
    letter-spacing: -0.025em;
}
.panel { border-radius: 8px; }
.usage-panel { padding: 28px 30px 22px; }
.panel-heading, .panel-title-row {
    align-items: center;
    display: flex;
    gap: 20px;
    justify-content: space-between;
}
.panel-heading h2 {
    font-size: 1.25rem;
    letter-spacing: -0.025em;
    margin-top: 10px;
}
.period-control {
    background: var(--paper-deep);
    border: 1px solid var(--line);
    border-radius: 6px;
    display: inline-flex;
    padding: 3px;
}
.period-control button {
    background: transparent;
    border: 0;
    border-radius: 4px;
    color: var(--muted);
    cursor: pointer;
    font-family: var(--mono);
    font-size: 0.66rem;
    font-weight: 600;
    height: 29px;
    min-width: 46px;
    padding: 0 9px;
}
.period-control button.active {
    background: var(--surface);
    box-shadow: 0 1px 3px rgba(25, 27, 24, 0.1);
    color: var(--ink);
}
.chart {
    align-items: flex-end;
    background: repeating-linear-gradient(to top, transparent 0, transparent 44px, var(--line) 45px);
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: clamp(2px, 0.55vw, 6px);
    height: 180px;
    margin-top: 26px;
}
.chart-bar {
    background: var(--accent);
    border-radius: 2px 2px 0 0;
    flex: 1;
    height: var(--bar-height);
    min-width: 2px;
    opacity: 0.78;
    transition: opacity 0.15s ease, height 0.25s ease;
}
.chart-bar:hover { opacity: 1; }
.chart-bar.zero { background: var(--line-dark); height: 2px; }
.chart-axis {
    color: var(--muted);
    display: flex;
    font-family: var(--mono);
    font-size: 0.64rem;
    justify-content: space-between;
    margin-top: 8px;
}

.breakdown-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(3, 1fr);
    margin: 18px 0;
}
.breakdown-card { display: flex; flex-direction: column; min-width: 0; padding: 22px 22px 20px; }
.breakdown-list { display: grid; gap: 13px; margin-top: 18px; }
.breakdown-item { min-width: 0; }
.breakdown-line {
    align-items: flex-start;
    display: flex;
    font-size: 0.78rem;
    gap: 10px;
    justify-content: space-between;
}
.breakdown-label-group {
    align-items: flex-start;
    display: flex;
    gap: 6px;
    min-width: 0;
}
.breakdown-label {
    color: var(--ink-soft);
    min-width: 0;
    overflow-wrap: anywhere;
}
.breakdown-info {
    align-items: center;
    appearance: none;
    background: transparent;
    border: 1px solid var(--line-dark);
    border-radius: 50%;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    flex: 0 0 auto;
    font-family: Georgia, serif;
    font-size: 0.62rem;
    font-weight: 700;
    height: 16px;
    justify-content: center;
    line-height: 1;
    margin-top: 1px;
    padding: 0;
    width: 16px;
}
.breakdown-info:hover, .breakdown-info[aria-expanded="true"] {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}
.breakdown-info:focus-visible, .breakdown-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.breakdown-line strong {
    flex: 0 0 auto;
    font-size: 0.76rem;
    font-variant-numeric: tabular-nums;
}
.breakdown-track {
    background: var(--paper-deep);
    border-radius: 999px;
    height: 4px;
    margin-top: 6px;
    overflow: hidden;
}
.breakdown-fill { background: var(--accent); border-radius: inherit; height: 100%; width: var(--fill-width); }
.breakdown-explanation {
    color: var(--muted);
    font-size: 0.72rem;
    line-height: 1.5;
    margin-top: 8px;
}
.breakdown-toggle {
    align-items: center;
    appearance: none;
    background: transparent;
    border: 0;
    border-top: 1px solid var(--line);
    color: var(--accent);
    cursor: pointer;
    display: flex;
    font-size: 0.72rem;
    font-weight: 600;
    justify-content: space-between;
    margin-top: 2px;
    padding: 12px 0 0;
    text-align: left;
    width: 100%;
}
.breakdown-toggle::after { content: '↓'; font-size: 0.8rem; }
.breakdown-toggle[aria-expanded="true"]::after { content: '↑'; }
.breakdown-toggle:hover { color: var(--ink); }
.empty-line { color: var(--muted); font-size: 0.8rem; }

.controls-panel, .history-panel { margin-top: 18px; padding: 27px 30px; }
.panel-title-row h2 { font-size: 1.2rem; margin: 0; }
.panel-title-row .card-label + h2 { margin-top: 10px; }
.control-row {
    align-items: center;
    border-top: 1px solid var(--line);
    display: flex;
    gap: 24px;
    justify-content: space-between;
    padding: 22px 0;
}
.panel-title-row + .control-row { margin-top: 14px; }
.control-copy { align-items: center; display: flex; gap: 13px; min-width: 0; }
.control-icon {
    background: var(--accent-soft);
    border-radius: 6px;
    color: var(--accent);
    display: grid;
    flex: 0 0 auto;
    font-size: 0.9rem;
    font-weight: 700;
    height: 34px;
    place-items: center;
    width: 34px;
}
.control-copy h3 { font-size: 0.9rem; font-weight: 600; margin: 0; }
.control-copy p { color: var(--muted); font-size: 0.78rem; line-height: 1.45; margin-top: 4px; }
.control-actions { align-items: center; display: flex; flex: 0 1 auto; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.select-label select {
    appearance: none;
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='m1 1.5 5 5 5-5' fill='none' stroke='%237b817b' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 11px center;
    border: 1px solid var(--line-dark);
    border-radius: 6px;
    color: var(--ink);
    font-size: 0.8rem;
    min-height: 36px;
    padding: 0 32px 0 12px;
}

.history-panel { overflow: hidden; }
.history-table { margin-top: 20px; }
.history-head, .history-row {
    align-items: center;
    display: grid;
    gap: 18px;
    grid-template-columns: minmax(0, 1fr) 130px 110px;
}
.history-head {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 0.64rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    padding: 0 12px 9px;
    text-transform: uppercase;
}
.history-head span:last-child { text-align: right; }
.history-entry { border-top: 1px solid var(--line); }
.history-entry > summary { cursor: pointer; list-style: none; }
.history-entry > summary::-webkit-details-marker { display: none; }
.history-entry > summary:hover { background: rgba(25, 27, 24, 0.025); }
.history-entry[open] > summary { background: rgba(25, 27, 24, 0.035); }
.history-row { font-size: 0.8rem; min-height: 74px; padding: 11px 12px; }
.activity { min-width: 0; padding-left: 17px; position: relative; }
.activity::before {
    color: var(--muted);
    content: '›';
    font-size: 1rem;
    left: 0;
    position: absolute;
    top: -2px;
    transition: transform 0.15s ease;
}
.history-entry[open] .activity::before { transform: rotate(90deg); }
.activity strong {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.activity small {
    color: var(--muted);
    display: block;
    margin-top: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.activity small.usage-metrics { color: var(--ink-soft); font-family: var(--mono); font-size: 0.68rem; }
.history-date { color: var(--muted); }
.history-date span, .history-date small { display: block; }
.history-date small { font-family: var(--mono); font-size: 0.68rem; margin-top: 3px; }
.history-amount { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.history-amount.credit { color: var(--green); }
.history-details {
    background: var(--paper-deep);
    border-top: 1px solid var(--line);
    padding: 18px 28px 20px;
}
.history-detail-grid {
    display: grid;
    font-size: 0.74rem;
    gap: 7px 18px;
    grid-template-columns: 100px minmax(0, 1fr);
    margin: 0;
}
.history-detail-grid dt { color: var(--muted); }
.history-detail-grid dd { color: var(--ink-soft); margin: 0; min-width: 0; overflow-wrap: anywhere; }
.history-detail-grid .diagnostic-value, .history-request code {
    font-family: var(--mono);
    font-size: 0.68rem;
}
.history-request-list { border-top: 1px solid var(--line-dark); margin-top: 17px; padding-top: 15px; }
.history-request-list h3 { font-size: 0.76rem; margin: 0 0 9px; }
.history-request { border-top: 1px solid var(--line); padding: 9px 0; }
.history-request:first-of-type { border-top: 0; }
.history-request > div { align-items: baseline; display: flex; gap: 12px; justify-content: space-between; }
.history-request strong { font-size: 0.72rem; font-weight: 600; }
.history-request span { font-size: 0.72rem; font-variant-numeric: tabular-nums; }
.history-request small, .history-request code { color: var(--muted); display: block; margin-top: 3px; overflow-wrap: anywhere; }
.history-empty { color: var(--muted); font-size: 0.84rem; padding: 34px 12px 18px; text-align: center; }
.load-more {
    background: transparent;
    border: 1px solid var(--line-dark);
    color: var(--ink-soft);
    display: block;
    font-size: 0.78rem;
    margin: 18px auto 0;
}
.load-more:hover { background: var(--paper-deep); border-color: #b7bbb3; }
.ledger-note { color: var(--muted); font-size: 0.72rem; margin-top: 18px; text-align: center; }

.toast {
    background: #f9eeec;
    border: 1px solid #d9b8b3;
    border-radius: 6px;
    bottom: 28px;
    box-shadow: var(--shadow);
    color: #752f29;
    font-size: 0.84rem;
    left: 50%;
    padding: 13px 16px;
    position: fixed;
    transform: translateX(-50%);
    width: min(460px, calc(100% - 32px));
    z-index: 1100;
}
.sr-only {
    border: 0;
    clip: rect(0, 0, 0, 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    white-space: nowrap;
    width: 1px;
}

@media (max-width: 760px) {
    .account-nav .nav-inner { padding: 16px 20px; }
    main { padding: 112px 20px 72px; }
    .sign-in-card { padding: 42px 24px 38px; }
    .balance-card { align-items: flex-start; flex-direction: column; padding: 28px 26px; }
    .balance-actions { justify-content: flex-start; width: 100%; }
    .metric-grid { gap: 9px; grid-template-columns: 1fr; }
    .metric-card { align-items: baseline; display: flex; justify-content: space-between; padding: 17px 20px; }
    .metric-card p { margin: 0; }
    .metric-card strong { font-size: 1.2rem; }
    .breakdown-grid { grid-template-columns: 1fr; }
    .panel-heading { align-items: flex-start; flex-direction: column; }
    .period-control { width: 100%; }
    .period-control button { flex: 1; }
    .usage-panel, .controls-panel, .history-panel { padding: 23px 20px; }
    .control-row { align-items: flex-start; flex-direction: column; }
    .control-actions { justify-content: flex-start; width: 100%; }
    .history-head { display: none; }
    .history-row { gap: 10px; grid-template-columns: minmax(0, 1fr) auto; }
    .history-date { grid-column: 1; grid-row: 2; }
    .history-amount { grid-column: 2; grid-row: 1 / span 2; }
    .history-details { padding: 17px 14px 19px; }
    .history-detail-grid { gap: 7px 12px; grid-template-columns: 84px minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
