:root {
  --bg: var(--tg-theme-bg-color, #f5f5f2);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #171916);
  --muted: var(--tg-theme-hint-color, #70756e);
  --accent: var(--tg-theme-button-color, #286443);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--text) 12%, transparent);
  --danger: #c54236;
  --warning: #b36b17;
  --watch: #a08318;
  --safe: #2e7650;
  --radius: 18px;
  --shadow: 0 18px 45px color-mix(in srgb, #000 11%, transparent);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-width: 280px; overflow-x: hidden; }
button, input, select { font: inherit; }
button { color: inherit; }

.app-shell { max-width: 760px; min-height: 100svh; margin: 0 auto; padding: env(safe-area-inset-top) 18px calc(88px + env(safe-area-inset-bottom)); }
.app-header { display: flex; align-items: flex-end; justify-content: space-between; padding: 26px 2px 22px; }
.eyebrow { margin: 0 0 5px; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: .15em; }
h1, h2, h3 { margin: 0; letter-spacing: -.035em; }
h1 { font-size: clamp(31px, 9vw, 45px); line-height: .95; }
h2 { font-size: 29px; }
h3 { font-size: 22px; }
.subtle { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.brand-mark { display: grid; grid-template-columns: repeat(3, 5px); align-items: end; gap: 4px; height: 32px; padding-bottom: 3px; }
.brand-mark span { display: block; width: 5px; border-radius: 6px; background: var(--accent); }
.brand-mark span:nth-child(1) { height: 10px; opacity: .45; }
.brand-mark span:nth-child(2) { height: 19px; opacity: .7; }
.brand-mark span:nth-child(3) { height: 29px; }

.view { display: none; animation: view-in .18s ease-out; }
.view.active { display: block; }
@keyframes view-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.summary-strip { display: grid; grid-template-columns: repeat(4, 1fr); border-block: 1px solid var(--line); margin-bottom: 18px; }
.summary-item { min-width: 0; padding: 15px 4px 14px; text-align: center; }
.summary-item + .summary-item { border-left: 1px solid var(--line); }
.summary-item strong { display: block; font-size: 24px; line-height: 1; font-variant-numeric: tabular-nums; }
.summary-item span { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.summary-item[data-tone="danger"] strong { color: var(--danger); }
.summary-item[data-tone="warning"] strong { color: var(--warning); }
.summary-item[data-tone="watch"] strong { color: var(--watch); }
.summary-item[data-tone="safe"] strong { color: var(--safe); }

.search-field { display: flex; align-items: center; min-height: 50px; gap: 9px; padding: 0 15px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
.search-field span { color: var(--muted); font-size: 24px; transform: rotate(-15deg); }
.search-field input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 16px; }
.filter-row, .shortcut-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 12px 1px 18px; }
.filter-row::-webkit-scrollbar, .shortcut-row::-webkit-scrollbar { display: none; }
.filter-row button, .shortcut-row button { flex: 0 0 auto; min-height: 40px; padding: 0 15px; border: 1px solid var(--line); border-radius: 999px; background: transparent; }
.filter-row button.active, .shortcut-row button.active { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }

.number-list { display: grid; gap: 12px; }
.sim-card { position: relative; overflow: hidden; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 7px 22px color-mix(in srgb, #000 5%, transparent); }
.sim-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--status-color); }
.sim-card[data-status="overdue"] { --status-color: var(--danger); }
.sim-card[data-status="within_7"] { --status-color: var(--warning); }
.sim-card[data-status="within_30"] { --status-color: var(--watch); }
.sim-card[data-status="normal"] { --status-color: var(--safe); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-title { min-width: 0; }
.card-title h3 { overflow-wrap: anywhere; font-size: 21px; }
.card-title p { margin: 6px 0 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.status-label { flex: 0 0 auto; color: var(--status-color); font-size: 12px; font-weight: 750; }
.card-meta { display: grid; grid-template-columns: 1.2fr .8fr; gap: 15px 12px; margin: 22px 0 18px; }
.meta-item span { display: block; color: var(--muted); font-size: 11px; }
.meta-item strong { display: block; margin-top: 4px; font-size: 15px; font-weight: 650; }
.card-actions { display: grid; grid-template-columns: 1fr 1fr 48px; gap: 8px; }
.action-button, .icon-button { min-height: 46px; border: 1px solid var(--line); border-radius: 13px; background: transparent; font-weight: 700; }
.action-button.primary { border-color: color-mix(in srgb, var(--accent) 30%, transparent); color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, transparent); }
.icon-button { width: 48px; font-size: 20px; }

.loading, .empty-state, .error-state { padding: 44px 20px; color: var(--muted); text-align: center; }
.empty-state strong, .error-state strong { display: block; margin-bottom: 7px; color: var(--text); font-size: 17px; }
.retry-button { min-height: 44px; margin-top: 15px; padding: 0 18px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-text); }

.section-heading { padding: 6px 2px 22px; }
.upcoming-group { margin-bottom: 28px; }
.upcoming-group h3 { margin-bottom: 7px; color: var(--muted); font-size: 13px; letter-spacing: .02em; }
.upcoming-row { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 64px; padding: 9px 2px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; }
.upcoming-row strong, .upcoming-row span { display: block; }
.upcoming-row span { margin-top: 4px; color: var(--muted); font-size: 13px; }
.upcoming-row em { color: var(--accent); font-size: 13px; font-style: normal; font-weight: 700; }

.number-form, .settings-form { display: grid; gap: 18px; }
.number-form label, .settings-form label, fieldset { min-width: 0; color: var(--muted); font-size: 13px; font-weight: 650; }
input { width: 100%; min-height: 49px; margin-top: 7px; padding: 0 13px; border: 1px solid var(--line); border-radius: 13px; outline: 0; background: var(--surface); color: var(--text); font-size: 16px; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent); }
.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input-suffix { position: relative; }
.input-suffix input { padding-right: 40px; }
.input-suffix span { position: absolute; right: 13px; bottom: 15px; color: var(--muted); }
fieldset { margin: 0; padding: 0; border: 0; }
legend { margin-bottom: 9px; }
.choice-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.choice-button, .choice-label { display: flex; min-height: 46px; align-items: center; justify-content: center; padding: 8px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); color: var(--text); text-align: center; }
.choice-button.active, .choice-label:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); color: var(--accent); }
.choice-label input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.check-row { display: grid; grid-template-columns: 22px 1fr; gap: 3px 9px; align-items: center; min-height: 56px; margin-top: 8px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.check-row input { width: 20px; min-height: 20px; margin: 0; accent-color: var(--accent); }
.check-row small { grid-column: 2; color: var(--muted); font-weight: 400; }
.advanced-panel { border-block: 1px solid var(--line); padding: 13px 0 18px; }
.advanced-panel summary { min-height: 44px; padding-top: 11px; color: var(--text); font-weight: 700; cursor: pointer; }
.form-heading { display: flex; align-items: center; gap: 12px; }
.form-safe-space { height: 65px; }
.sticky-save { position: fixed; z-index: 8; right: max(18px, calc((100vw - 760px) / 2 + 18px)); bottom: calc(18px + env(safe-area-inset-bottom)); left: max(18px, calc((100vw - 760px) / 2 + 18px)); padding: 8px; border: 1px solid var(--line); border-radius: 17px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(16px); }
.primary-button { width: 100%; min-height: 50px; border: 0; border-radius: 13px; background: var(--accent); color: var(--accent-text); font-weight: 800; }
.primary-button:disabled { opacity: .52; }

.bottom-nav { position: fixed; z-index: 7; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(3, 1fr); max-width: 760px; margin: 0 auto; padding: 7px 12px calc(7px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(18px); }
.bottom-nav button { min-height: 54px; border: 0; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700; }
.bottom-nav button span { display: block; margin-bottom: 2px; font-size: 20px; }
.bottom-nav button.active { color: var(--accent); }
.fab { position: fixed; z-index: 9; right: max(19px, calc((100vw - 760px) / 2 + 19px)); bottom: calc(82px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-text); box-shadow: var(--shadow); font-size: 32px; line-height: 1; }

.modal[hidden] { display: none; }
.modal { position: fixed; z-index: 20; inset: 0; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; width: 100%; border: 0; background: rgba(0,0,0,.42); animation: fade-in .15s ease-out; }
.modal-sheet { position: relative; width: min(100%, 760px); max-height: 86svh; overflow-y: auto; padding: 9px 20px calc(20px + env(safe-area-inset-bottom)); border-radius: 24px 24px 0 0; background: var(--surface); box-shadow: var(--shadow); animation: sheet-in .2s ease-out; }
.modal-handle { width: 38px; height: 4px; margin: 0 auto 18px; border-radius: 5px; background: var(--line); }
.modal-sheet h3 { margin-bottom: 13px; }
.modal-sheet p { color: var(--muted); line-height: 1.55; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.modal-actions button { min-height: 48px; border: 1px solid var(--line); border-radius: 13px; background: transparent; font-weight: 750; }
.modal-actions .confirm { border-color: transparent; background: var(--accent); color: var(--accent-text); }
.modal-actions .danger { border-color: transparent; background: var(--danger); color: #fff; }
.menu-list { display: grid; gap: 8px; }
.menu-list button { min-height: 50px; border: 0; border-radius: 13px; background: color-mix(in srgb, var(--text) 5%, transparent); text-align: left; padding: 0 15px; font-weight: 700; }
.menu-list button.danger-text { color: var(--danger); }

.toast { position: fixed; z-index: 30; top: calc(15px + env(safe-area-inset-top)); left: 50%; max-width: min(90vw, 440px); padding: 11px 16px; border-radius: 999px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, -12px); transition: .2s ease; text-align: center; font-size: 14px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-in { from { transform: translateY(32px); opacity: .7; } }

@media (max-width: 370px) {
  .app-shell { padding-inline: 12px; }
  .summary-item span { font-size: 10px; }
  .two-columns { grid-template-columns: 1fr; }
  .card-actions { grid-template-columns: 1fr 1fr 44px; }
}
@media (min-width: 680px) {
  .number-list { grid-template-columns: 1fr 1fr; }
  .sim-card { min-height: 315px; display: flex; flex-direction: column; }
  .card-actions { margin-top: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
