:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #171816;
  background: #f7f7f5;
  font-synthesis: none;
  --ink: #171816;
  --muted: #6e716b;
  --line: #e2e3df;
  --surface: #fff;
  --soft: #f0f1ed;
  --accent: #f05a35;
  --accent-soft: #fff0ea;
  --green: #13795b;
  --green-soft: #e9f6f0;
  --amber: #9a6700;
  --amber-soft: #fff6d8;
  --red: #b42318;
  --red-soft: #feeceb;
  --shadow: 0 16px 44px rgb(23 24 22 / 8%);
}

* { box-sizing: border-box; }
html { min-width: 320px; min-height: 100%; }
body { margin: 0; min-height: 100vh; background: var(--soft); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .55; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 12px; outline: 0; background: var(--surface); color: var(--ink);
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(240 90 53 / 12%); }
label { display: grid; gap: 7px; color: #4f524d; font-size: 13px; font-weight: 700; }
h1, h2, h3, p { margin-top: 0; }
.hidden { display: none !important; }
.wide { width: 100%; }
.center { text-align: center; }
.subtle, .microcopy { color: var(--muted); }
.microcopy { margin: 9px 2px 0; font-size: 11px; line-height: 1.5; }
.brand-mark { margin: 0 0 5px; color: var(--accent); font-size: 10px; font-weight: 900; letter-spacing: .16em; }

.login-view { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(circle at 25% 0, #ffd9cc, transparent 34rem), #f7f7f5; }
.login-card { display: grid; gap: 16px; width: min(100%, 390px); padding: 30px; border: 1px solid #fff; border-radius: 24px; background: rgb(255 255 255 / 94%); box-shadow: var(--shadow); }
.login-card h1 { margin: 0; font-size: 30px; letter-spacing: -.04em; }
.login-card .subtle { margin: -7px 0 5px; font-size: 13px; }
.form-message { min-height: 18px; margin: 0; color: var(--red); font-size: 12px; line-height: 1.45; }

.app { width: min(100%, 920px); min-height: 100vh; margin: 0 auto; background: #f7f7f5; }
.topbar { position: sticky; z-index: 20; top: 0; display: flex; align-items: center; justify-content: space-between; min-height: 70px; padding: 12px 20px; border-bottom: 1px solid rgb(226 227 223 / 80%); background: rgb(247 247 245 / 94%); backdrop-filter: blur(14px); }
.topbar strong { font-size: 20px; letter-spacing: -.025em; }
.account-button { display: grid; justify-items: end; gap: 1px; min-width: 92px; padding: 8px 11px; border: 0; border-radius: 12px; background: var(--surface); color: var(--ink); }
.account-button span { font-size: 13px; font-weight: 800; }
.account-button small { color: var(--muted); font-size: 10px; }
.main-content { padding: 20px 20px 110px; }
.view { animation: appear 160ms ease; }
@keyframes appear { from { opacity: 0; transform: translateY(3px); } }

.search-card { padding: 14px; border: 1px solid var(--line); border-radius: 19px; background: var(--surface); box-shadow: 0 10px 30px rgb(23 24 22 / 5%); }
.search-box { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 9px; min-height: 54px; padding: 0 12px; border: 2px solid transparent; border-radius: 14px; background: var(--soft); }
.search-box:focus-within { border-color: var(--accent); background: #fff; }
.search-box > span { color: var(--accent); font-size: 27px; font-weight: 500; }
.search-box input { min-height: 48px; padding: 0; border: 0; border-radius: 0; background: transparent; font-size: 16px; box-shadow: none; }
.text-button { min-height: 32px; padding: 7px 8px; border: 0; border-radius: 8px; background: #e3e4df; color: #555853; font-size: 11px; }
.empty-block { display: grid; justify-items: center; gap: 7px; padding: 76px 20px; color: var(--muted); text-align: center; }
.empty-block strong { color: #454843; font-size: 18px; }
.empty-block span { font-size: 13px; }
.section-label { padding: 18px 4px 10px; color: var(--muted); font-size: 12px; }
.price-results { display: grid; gap: 11px; }
.price-card { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.price-card-head { display: flex; justify-content: space-between; gap: 16px; padding: 15px 15px 12px; }
.price-card h3 { margin: 5px 0 0; font-size: 17px; line-height: 1.35; }
.pill { display: inline-flex; align-items: center; width: fit-content; min-height: 23px; padding: 0 8px; border-radius: 7px; background: var(--accent-soft); color: #b74221; font-size: 10px; font-weight: 900; }
.quote-date { color: var(--muted); font-size: 10px; white-space: nowrap; }
.price-badges { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 15px 14px; }
.price-badge { padding: 7px 9px; border-radius: 9px; background: var(--soft); color: #4f524d; font-size: 11px; }
.price-badge strong { margin-left: 4px; color: var(--green); }
.price-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 15px; border-top: 1px solid var(--line); }
.mode-label { color: var(--muted); font-size: 10px; }

.primary-button, .secondary-button, .danger-outline, .back-button, .small-button { min-height: 43px; padding: 0 16px; border-radius: 12px; font-weight: 800; }
.primary-button { border: 1px solid var(--ink); background: var(--ink); color: #fff; }
.primary-button.accent { border-color: var(--accent); background: var(--accent); }
.secondary-button { border: 1px solid var(--line); background: #fff; color: var(--ink); }
.danger-outline { border: 1px solid #efb8b3; background: #fff; color: var(--red); }
.small-button { min-height: 34px; padding-inline: 11px; border: 0; background: var(--ink); color: #fff; font-size: 11px; }
.back-button { min-height: 38px; margin-bottom: 12px; padding: 0 10px; border: 0; background: transparent; color: #444742; }

.bottom-nav { position: fixed; z-index: 30; right: 0; bottom: 0; left: 0; display: flex; justify-content: center; gap: 4px; padding: 8px max(12px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); border-top: 1px solid var(--line); background: rgb(255 255 255 / 96%); backdrop-filter: blur(16px); }
.bottom-nav button { display: grid; flex: 1; justify-items: center; gap: 1px; max-width: 180px; min-height: 49px; padding: 5px 8px; border: 0; border-radius: 12px; background: transparent; color: #858881; }
.bottom-nav button span { font-size: 20px; line-height: 1; }
.bottom-nav button small { font-size: 10px; font-weight: 700; }
.bottom-nav button.active { background: var(--accent-soft); color: var(--accent); }

.dashboard-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; margin-bottom: 14px; }
.dashboard-card { display: grid; gap: 5px; min-height: 76px; padding: 13px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.dashboard-card span { color: var(--muted); font-size: 10px; }
.dashboard-card strong { font-size: 21px; }
.list-toolbar { display: grid; grid-template-columns: 1fr 140px; gap: 8px; margin-bottom: 12px; }
.device-list { display: grid; gap: 9px; }
.device-card { display: grid; grid-template-columns: 72px 1fr auto; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 15px; background: #fff; text-align: left; }
.device-card img { width: 72px; height: 72px; border-radius: 11px; background: var(--soft); object-fit: cover; }
.device-card-main { min-width: 0; }
.device-card-main strong { display: block; overflow: hidden; margin-bottom: 5px; text-overflow: ellipsis; white-space: nowrap; }
.device-card-main span { display: block; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.status-pill { display: inline-flex; align-items: center; width: fit-content; min-height: 25px; padding: 0 8px; border-radius: 999px; background: var(--soft); color: #555853; font-size: 10px; font-weight: 800; white-space: nowrap; }
.status-pill.attention { background: var(--amber-soft); color: var(--amber); }
.status-pill.good { background: var(--green-soft); color: var(--green); }
.status-pill.danger { background: var(--red-soft); color: var(--red); }

.sheet-backdrop { position: fixed; z-index: 80; inset: 0; display: grid; align-items: end; background: rgb(16 18 15 / 45%); }
.sheet { overflow: auto; width: min(100%, 620px); max-height: 92vh; margin: 0 auto; padding: 8px 20px calc(24px + env(safe-area-inset-bottom)); border-radius: 24px 24px 0 0; background: #fff; box-shadow: 0 -20px 60px rgb(16 18 15 / 20%); }
.compact-sheet { width: min(100%, 480px); }
.sheet-handle { width: 42px; height: 4px; margin: 2px auto 13px; border-radius: 4px; background: #d2d4cf; }
.sheet-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.sheet-header h2 { margin: 5px 0 0; font-size: 21px; line-height: 1.3; }
.close-button { width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--soft); color: #5d605b; font-size: 25px; line-height: 1; }
.sheet > label, .sheet > fieldset, .sheet > .advice-card, .sheet > .notice, .sheet > button { margin-top: 13px; }
.bucket-fieldset { padding: 0; border: 0; }
.bucket-fieldset legend { margin-bottom: 7px; color: #4f524d; font-size: 13px; font-weight: 700; }
.bucket-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.bucket-option { display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 11px; background: #fff; color: #50534e; font-size: 11px; }
.bucket-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: #9e381b; }
.bucket-option input { width: 16px; min-height: 16px; margin: 0; box-shadow: none; }
.bucket-option span { display: grid; gap: 2px; }
.bucket-option strong { font-size: 13px; }
.notice, .advice-card { padding: 12px 13px; border-radius: 12px; font-size: 12px; line-height: 1.55; }
.notice.warning, .advice-card.warning { background: var(--amber-soft); color: #745000; }
.notice.danger, .advice-card.danger { background: var(--red-soft); color: var(--red); }
.advice-card.good { background: var(--green-soft); color: var(--green); }
.advice-card.neutral { background: var(--soft); color: #555853; }
.photo-picker { position: relative; overflow: hidden; min-height: 210px; border: 1px dashed #c7c9c3; border-radius: 15px; background: var(--soft); }
.photo-picker input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-picker img { width: 100%; height: 250px; object-fit: cover; }
.photo-placeholder { display: grid; align-content: center; justify-items: center; min-height: 210px; padding: 25px; color: #555853; text-align: center; }
.photo-placeholder span { margin-top: 5px; color: var(--muted); font-size: 11px; }

.detail-hero { display: grid; grid-template-columns: 170px 1fr; gap: 16px; padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: #fff; }
.detail-hero img { width: 170px; height: 170px; border-radius: 13px; object-fit: cover; background: var(--soft); }
.detail-title h1 { margin: 7px 0; font-size: 25px; line-height: 1.25; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 7px 12px; color: var(--muted); font-size: 11px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 15px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.detail-panel, .settings-card, .panel-form { padding: 17px; border: 1px solid var(--line); border-radius: 17px; background: #fff; }
.detail-panel.full { grid-column: 1 / -1; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-heading p { margin: 0 0 4px; color: var(--accent); font-size: 9px; font-weight: 900; letter-spacing: .15em; }
.section-heading h2, .section-heading h3 { margin: 0; font-size: 17px; }
.form-grid { display: grid; gap: 10px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.quick-form .field-help { margin: -3px 0 2px; color: var(--muted); font-size: 10px; }
.anomaly-options { display: flex; flex-wrap: wrap; gap: 7px; }
.check-chip { position: relative; }
.check-chip input { position: absolute; opacity: 0; }
.check-chip span { display: inline-flex; align-items: center; min-height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: #5b5e59; font-size: 11px; }
.check-chip:has(input:checked) span { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.decision-box { padding: 13px; border-radius: 13px; background: var(--soft); }
.decision-box strong { display: block; margin-bottom: 4px; }
.decision-box p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.market-list { display: grid; gap: 7px; margin-top: 10px; }
.market-row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 9px; border: 1px solid var(--line); border-radius: 10px; }
.market-row input { width: 17px; min-height: 17px; }
.market-row a { overflow: hidden; color: #333631; font-size: 11px; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
.market-row strong { color: var(--green); font-size: 12px; }
.snapshot-list { display: grid; gap: 6px; margin-top: 10px; }
.snapshot-item { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.event-list { display: grid; gap: 8px; }
.event-item { padding-left: 10px; border-left: 2px solid var(--line); color: var(--muted); font-size: 10px; }
.event-item strong { display: block; margin-bottom: 2px; color: #4e514c; font-size: 11px; }

.panel-form { display: grid; gap: 13px; }
.settings-card { margin-top: 12px; }
.user-list { display: grid; gap: 8px; }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px; border-radius: 11px; background: var(--soft); }
.user-row span { display: grid; gap: 2px; font-size: 12px; font-weight: 800; }
.user-row small { color: var(--muted); font-weight: 500; }
.toast { position: fixed; z-index: 120; right: 16px; bottom: 90px; left: 16px; max-width: 450px; margin: auto; padding: 12px 15px; border-radius: 12px; background: #171816; color: #fff; box-shadow: var(--shadow); font-size: 12px; text-align: center; }
.busy-overlay { position: fixed; z-index: 150; inset: 0; display: grid; align-content: center; justify-items: center; gap: 12px; background: rgb(255 255 255 / 76%); color: #31332f; backdrop-filter: blur(4px); }
.busy-overlay span { width: 32px; height: 32px; border: 3px solid #ddd; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .topbar { min-height: 64px; padding: 10px 14px; }
  .topbar strong { font-size: 18px; }
  .main-content { padding: 14px 12px 102px; }
  .dashboard-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .list-toolbar { grid-template-columns: 1fr 118px; }
  .device-card { grid-template-columns: 62px 1fr; }
  .device-card img { width: 62px; height: 62px; }
  .device-card > .status-pill { grid-column: 2; justify-self: start; }
  .sheet { padding-inline: 15px; }
  .detail-hero { grid-template-columns: 104px 1fr; gap: 12px; padding: 12px; }
  .detail-hero img { width: 104px; height: 125px; }
  .detail-title h1 { font-size: 20px; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-panel.full { grid-column: auto; }
  .two-columns { grid-template-columns: 1fr; }
}

@media (max-width: 380px) {
  .bucket-options { grid-template-columns: 1fr; }
  .dashboard-cards { grid-template-columns: 1fr 1fr; }
  .price-card-foot { align-items: flex-end; }
}
