:root {
    --mi: #ff6900;
    --mi-dark: #e85d00;
    --ink: #191919;
    --muted: #77746f;
    --line: #ece9e5;
    --paper: #ffffff;
    --canvas: #f6f5f3;
    --success: #22a06b;
    --warning: #d97706;
    --danger: #d64045;
    --shadow: 0 18px 50px rgba(41, 34, 29, .08);
    font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    color: var(--ink);
    background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.mobile-only { display: none; }

.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(420px, 1.35fr) minmax(360px, .65fr); }
.auth-visual {
    position: relative;
    overflow: hidden;
    padding: clamp(46px, 7vw, 100px);
    color: white;
    background:
        radial-gradient(circle at 72% 78%, rgba(255,255,255,.18) 0 7%, transparent 8%),
        radial-gradient(circle at 72% 78%, transparent 0 19%, rgba(255,255,255,.10) 20% 20.5%, transparent 21%),
        linear-gradient(140deg, #ff7b19 0%, #ff6900 45%, #db4f00 100%);
}
.auth-visual::after {
    content: "";
    position: absolute; width: 580px; height: 580px; border: 1px solid rgba(255,255,255,.16);
    border-radius: 48% 52% 45% 55%; right: -170px; bottom: -270px; transform: rotate(24deg);
}
.brand-mark {
    width: 64px; height: 64px; border-radius: 19px; background: white; color: var(--mi);
    display: grid; place-items: center; font-weight: 900; font-size: 30px; letter-spacing: -4px; box-shadow: 0 12px 35px rgba(122,45,0,.22);
}
.brand-mark.small { width: 42px; height: 42px; border-radius: 13px; font-size: 20px; box-shadow: none; }
.eyebrow { margin: 0 0 8px; font-size: 11px; font-weight: 800; letter-spacing: .17em; color: var(--muted); }
.eyebrow.orange { color: var(--mi); }
.auth-visual .eyebrow { margin-top: 80px; color: rgba(255,255,255,.72); }
.auth-visual h1 { margin: 14px 0 24px; font-size: clamp(48px, 6vw, 84px); line-height: 1.04; letter-spacing: -.055em; max-width: 800px; }
.auth-copy { font-size: 17px; line-height: 1.8; max-width: 610px; color: rgba(255,255,255,.78); }
.auth-metrics { position: absolute; left: clamp(46px, 7vw, 100px); bottom: 58px; display: flex; gap: 48px; z-index: 1; }
.auth-metrics div { display: grid; gap: 5px; }
.auth-metrics b { font-size: 22px; }
.auth-metrics span { color: rgba(255,255,255,.7); font-size: 13px; }
.auth-panel { display: grid; place-items: center; background: white; padding: 44px; }
.auth-form { width: min(100%, 390px); }
.auth-form h2 { margin: 8px 0 10px; font-size: 34px; letter-spacing: -.04em; }
.auth-form > p:not(.eyebrow) { margin: 0 0 30px; color: var(--muted); line-height: 1.7; }
.auth-form label, .field { display: grid; gap: 8px; margin: 18px 0; font-size: 13px; font-weight: 650; }
input, select, textarea {
    width: 100%; border: 1px solid var(--line); border-radius: 13px; padding: 13px 14px;
    color: var(--ink); background: #fbfaf9; outline: none; transition: .18s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--mi); box-shadow: 0 0 0 4px rgba(255,105,0,.09); background: white; }
textarea { min-height: 96px; resize: vertical; }
.mobile-brand { display: none; }

.primary, .secondary, .ghost, .danger-button {
    border: 0; border-radius: 13px; padding: 12px 18px; font-weight: 760; transition: .18s ease;
}
.primary { color: white; background: var(--mi); box-shadow: 0 8px 18px rgba(255,105,0,.23); }
.primary:hover { background: var(--mi-dark); transform: translateY(-1px); }
.primary:disabled { opacity: .5; cursor: wait; transform: none; }
.secondary { color: var(--ink); background: #f1efec; }
.secondary:hover { background: #e8e5e1; }
.ghost { color: var(--muted); background: transparent; border: 1px solid var(--line); }
.danger-button { color: white; background: var(--danger); border: 0; box-shadow: 0 8px 18px rgba(214,64,69,.20); }
.danger-button:hover { filter: brightness(.92); transform: translateY(-1px); }
.danger-button:disabled { opacity: .5; cursor: wait; transform: none; }
.wide { width: 100%; margin-top: 8px; padding: 14px; }
.compact { padding: 10px 15px; font-size: 13px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: 248px; z-index: 15;
    display: flex; flex-direction: column; padding: 28px 18px; background: #1e1d1b; color: white;
}
.sidebar-brand { display: flex; align-items: center; gap: 13px; padding: 0 8px 38px; }
.sidebar-brand div { display: grid; }
.sidebar-brand b { font-size: 19px; }
.sidebar-brand small { color: #8d8984; margin-top: 1px; }
.sidebar nav { display: grid; gap: 6px; }
.sidebar nav button, .sidebar nav a {
    display: flex; align-items: center; gap: 13px; width: 100%; border: 0; border-radius: 12px;
    padding: 13px 15px; color: #a8a49f; background: transparent; text-align: left; font-weight: 650; text-decoration: none;
}
.sidebar nav button span, .sidebar nav a span { width: 20px; font-size: 19px; text-align: center; }
.sidebar nav button:hover, .sidebar nav a:hover { color: white; background: rgba(255,255,255,.06); }
.sidebar nav button.active { color: white; background: var(--mi); }
.sidebar-foot { margin-top: auto; padding: 18px 8px 0; border-top: 1px solid #34322f; display: grid; grid-template-columns: 38px 1fr 28px; align-items: center; gap: 10px; }
.user-avatar { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: #35322f; font-weight: 800; }
.sidebar-foot div:nth-child(2) { display: grid; font-size: 13px; }
.sidebar-foot small { color: #77736e; margin-top: 2px; }
.sidebar-foot button { color: #8d8984; background: transparent; border: 0; font-size: 19px; }
main { grid-column: 2; min-width: 0; }
.topbar { height: 102px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 20px 38px; background: rgba(246,245,243,.88); backdrop-filter: blur(16px); position: sticky; top: 0; z-index: 10; border-bottom: 1px solid rgba(231,228,224,.8); }
.topbar h2 { margin: 0; font-size: 25px; letter-spacing: -.035em; }
.top-actions { display: flex; align-items: center; gap: 18px; }
.top-actions > span { font-size: 13px; color: var(--muted); }
.content { padding: 30px 38px 60px; max-width: 1540px; margin: 0 auto; }

.cookie-alert { border-radius: 16px; padding: 14px 18px; margin-bottom: 22px; display: flex; align-items: center; justify-content: space-between; gap: 16px; background: #fff3e8; color: #8b4308; border: 1px solid #ffd7b7; font-size: 13px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat-card { position: relative; overflow: hidden; padding: 22px; min-height: 145px; border-radius: 19px; background: var(--paper); box-shadow: 0 1px 0 var(--line); }
.stat-card.featured { color: white; background: linear-gradient(145deg, #ff7b1c, #f25d00); box-shadow: 0 18px 40px rgba(255,105,0,.22); }
.stat-card.featured::after { content: ""; position: absolute; width: 150px; height: 150px; border: 25px solid rgba(255,255,255,.12); border-radius: 50%; right: -55px; bottom: -72px; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 650; }
.featured .stat-label { color: rgba(255,255,255,.72); }
.stat-value { margin-top: 13px; font-size: 38px; font-weight: 840; letter-spacing: -.04em; }
.stat-foot { margin-top: 7px; color: #aaa5a0; font-size: 12px; }
.featured .stat-foot { color: rgba(255,255,255,.67); }
.dashboard-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; margin-top: 18px; }
.panel { background: white; border: 1px solid var(--line); border-radius: 19px; box-shadow: 0 1px 0 rgba(0,0,0,.015); }
.panel-head { padding: 21px 22px 14px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.panel-head h3 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.panel-head p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.text-button { border: 0; background: transparent; color: var(--mi); font-weight: 700; font-size: 13px; }
.product-stack { padding: 0 14px 16px; display: grid; gap: 4px; }
.product-row { display: grid; grid-template-columns: 48px 1fr auto; gap: 13px; align-items: center; padding: 11px 8px; border-radius: 13px; }
.product-row:hover { background: #faf9f7; }
.product-row img, .product-placeholder { width: 48px; height: 48px; object-fit: contain; border-radius: 12px; background: #f3f1ee; }
.product-placeholder { display: grid; place-items: center; color: #bbb; font-weight: 800; }
.product-row b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-row small { display: block; margin-top: 4px; color: var(--muted); }
.product-count { text-align: right; }
.product-count b { font-size: 18px; }
.timeline { padding: 0 20px 18px; }
.timeline-item { display: grid; grid-template-columns: 10px 1fr auto; gap: 12px; padding: 12px 0; border-top: 1px solid #f1efec; align-items: start; }
.timeline-dot { margin-top: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--mi); box-shadow: 0 0 0 4px rgba(255,105,0,.10); }
.timeline-item b { font-size: 13px; }
.timeline-item p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.timeline-item time { color: #aaa5a0; font-size: 11px; white-space: nowrap; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.search-wrap { flex: 1; max-width: 520px; display: flex; gap: 10px; }
.toolbar select { width: 160px; background: white; }
.device-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.device-card { overflow: hidden; background: white; border: 1px solid var(--line); border-radius: 18px; transition: .18s ease; }
.device-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: transparent; }
.device-visual { position: relative; height: 180px; display: grid; place-items: center; padding: 18px; background: linear-gradient(145deg, #f8f7f5, #eeece8); }
.device-visual img { width: 100%; height: 100%; object-fit: contain; mix-blend-mode: multiply; }
.device-visual .product-placeholder { width: 78px; height: 78px; border-radius: 22px; background: white; }
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 5px 9px; font-size: 11px; font-weight: 760; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.in_store { color: #137a4e; background: #e8f7ef; }
.badge.display { color: #a44b00; background: #fff0e4; }
.badge.saleable { color: #137a4e; background: #e8f7ef; }
.badge.sold { color: #6b6864; background: #eceae7; }
.badge.checked_out { color: #916100; background: #fff4d4; }
.badge.retired { color: #6b6864; background: #eceae7; }
.device-visual .badge { position: absolute; top: 14px; right: 14px; background-color: white; box-shadow: 0 5px 16px rgba(0,0,0,.07); }
.device-body { padding: 17px; }
.device-body h3 { margin: 0 0 7px; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.device-sn { margin: 16px 0 12px; border-radius: 11px; padding: 10px 11px; background: #f7f5f2; font: 650 12px ui-monospace, SFMono-Regular, Consolas, monospace; color: #4c4945; }
.device-foot { display: flex; align-items: center; justify-content: space-between; }
.device-foot span { color: var(--muted); font-size: 12px; }
.device-foot button { padding: 0; border: 0; background: transparent; color: var(--mi); font-weight: 750; font-size: 12px; }
.empty { padding: 64px 24px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 7px; }

.scan-layout { display: grid; grid-template-columns: minmax(320px, .75fr) minmax(380px, 1.25fr); gap: 18px; }
.scan-stage { min-height: 520px; position: relative; overflow: hidden; border-radius: 20px; color: white; padding: 28px; background: #181715; }
.scan-stage::before { content: ""; position: absolute; inset: 0; opacity: .35; background: radial-gradient(circle at center, #504840, transparent 58%); }
.scan-frame { position: relative; margin: 66px auto 34px; width: min(100%, 350px); aspect-ratio: 1.8; border: 1px solid rgba(255,255,255,.25); border-radius: 20px; }
.scan-frame::before, .scan-frame::after { content: ""; position: absolute; inset: -2px; border: 3px solid transparent; border-top-color: var(--mi); border-radius: 20px; }
.scan-frame::after { transform: rotate(180deg); }
.scan-line { position: absolute; left: 8%; right: 8%; top: 50%; height: 2px; background: var(--mi); box-shadow: 0 0 18px var(--mi); animation: scan 2.2s ease-in-out infinite; }
@keyframes scan { 0%,100% { transform: translateY(-64px); opacity:.4 } 50% { transform: translateY(64px); opacity:1 } }
.scan-stage h3, .scan-stage p { position: relative; text-align: center; }
.scan-stage h3 { margin: 0; font-size: 20px; }
.scan-stage p { color: #96918a; line-height: 1.7; font-size: 13px; }
.scan-form { padding: 27px; }
.scan-form h3 { margin: 0 0 4px; }
.scan-form > p { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); padding: 4px; border-radius: 13px; background: #f1efec; gap: 3px; }
.segmented.two { grid-template-columns: repeat(2, 1fr); }
.segmented button { border: 0; padding: 9px 6px; border-radius: 10px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; }
.segmented button.active { background: white; color: var(--mi); box-shadow: 0 3px 10px rgba(0,0,0,.06); }
.code-input { font: 750 19px ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .025em; text-transform: uppercase; }
.hint { margin-top: 8px; font-size: 12px; color: var(--muted); }
.hint.valid { color: var(--success); }
.hint.invalid { color: var(--danger); }

.history-table { width: 100%; border-collapse: collapse; }
.history-table th, .history-table td { padding: 14px 18px; text-align: left; border-bottom: 1px solid #f0eeeb; font-size: 12px; }
.history-table th { color: var(--muted); background: #fbfaf9; font-weight: 700; }
.history-table td b { display: block; font-size: 13px; margin-bottom: 3px; }
.history-table tr:last-child td { border-bottom: 0; }
.action-pill { display: inline-block; border-radius: 8px; padding: 5px 8px; background: #f0eeeb; font-weight: 700; }
.settings-grid { display: grid; grid-template-columns: 1fr .7fr; gap: 18px; }
.settings-card { padding: 25px; }
.settings-card h3 { margin: 0 0 6px; }
.settings-card > p { margin: 0 0 22px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.connection-state { display: flex; align-items: center; gap: 12px; padding: 15px; border-radius: 14px; background: #f6f5f3; }
.connection-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 5px rgba(214,64,69,.10); }
.connection-dot.on { background: var(--success); box-shadow: 0 0 0 5px rgba(34,160,107,.10); }
.connection-state b { display: block; font-size: 13px; }
.connection-state small { color: var(--muted); }
.spec-list { display: grid; gap: 12px; }
.spec-item { display: flex; justify-content: space-between; gap: 20px; padding: 12px 0; border-bottom: 1px solid #f0eeeb; font-size: 13px; }
.spec-item span { color: var(--muted); }
.manage-list { display: grid; gap: 7px; margin-top: 18px; }
.manage-row { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 13px; border: 1px solid var(--line); border-radius: 12px; background: #faf9f7; text-align: left; }
.manage-row span { display: grid; gap: 3px; }
.manage-row b { font-size: 13px; }
.manage-row small { color: var(--muted); }
.manage-row em { color: var(--mi); font-size: 11px; font-style: normal; white-space: nowrap; }
.sync-url { padding: 14px; border-radius: 12px; background: #f5f3f0; color: #4c4843; font: 12px/1.6 ui-monospace, Consolas, monospace; word-break: break-all; user-select: all; }

.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(23,21,19,.55); backdrop-filter: blur(6px); }
.modal-card { position: relative; width: min(720px, 100%); max-height: 90vh; overflow: auto; background: white; border-radius: 22px; box-shadow: 0 30px 80px rgba(0,0,0,.24); padding: 30px; }
.modal-close { position: absolute; right: 17px; top: 15px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: #f0eeeb; font-size: 22px; color: #777; }
.detail-head { display: grid; grid-template-columns: 180px 1fr; gap: 24px; align-items: center; margin-bottom: 20px; }
.detail-head img, .detail-head .product-placeholder { width: 180px; height: 180px; object-fit: contain; border-radius: 18px; background: #f5f3f0; }
.detail-head h2 { margin: 8px 0; font-size: 24px; }
.detail-head p { color: var(--muted); }
.detail-actions { display: flex; gap: 10px; margin-top: 18px; }
.image-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 16px; }
.image-choice { border: 2px solid transparent; border-radius: 14px; padding: 8px; background: #f6f5f3; }
.image-choice:hover { border-color: var(--mi); }
.image-choice img { width: 100%; aspect-ratio: 1; object-fit: contain; mix-blend-mode: multiply; }
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 100; transform: translate(-50%, 24px); opacity: 0; pointer-events: none; padding: 12px 18px; border-radius: 12px; color: white; background: #24211e; box-shadow: 0 14px 36px rgba(0,0,0,.22); font-size: 13px; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }
.spinner { width: 22px; height: 22px; margin: 30px auto; border: 3px solid #eee; border-top-color: var(--mi); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid, .settings-grid { grid-template-columns: 1fr; }
    .device-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
    .mobile-only, .mobile-brand { display: flex; }
    .auth-shell { grid-template-columns: 1fr; background: white; }
    .auth-visual { display: none; }
    .auth-panel { padding: 26px; align-items: start; }
    .mobile-brand { align-items: center; gap: 10px; width: min(100%, 390px); margin: 12px auto 70px; font-weight: 800; }
    .mobile-brand span { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: white; background: var(--mi); }
    .app-shell { display: block; }
    .sidebar { transform: translateX(-102%); transition: .22s ease; box-shadow: 20px 0 50px rgba(0,0,0,.2); }
    .sidebar.open { transform: translateX(0); }
    main { width: 100%; }
    .topbar { height: 88px; padding: 14px 18px; }
    .topbar .eyebrow, .top-actions > span { display: none; }
    .topbar h2 { font-size: 20px; }
    .icon-btn { border: 0; background: transparent; font-size: 22px; padding: 5px; }
    .topbar > div:nth-child(2) { flex: 1; }
    .top-actions .primary { font-size: 0; width: 42px; height: 42px; padding: 0; }
    .top-actions .primary::after { content: "+"; font-size: 23px; }
    .content { padding: 20px 16px 42px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 17px; min-height: 125px; }
    .stat-value { font-size: 32px; }
    .device-grid { grid-template-columns: 1fr; }
    .toolbar { align-items: stretch; flex-direction: column; }
    .search-wrap { max-width: none; flex-direction: column; }
    .toolbar select { width: 100%; }
    .scan-layout { grid-template-columns: 1fr; }
    .scan-stage { min-height: 390px; }
    .scan-form { padding: 20px; }
    .segmented { grid-template-columns: repeat(2, 1fr); }
    .panel.table-panel { overflow-x: auto; }
    .history-table { min-width: 720px; }
    .detail-head { grid-template-columns: 1fr; text-align: center; }
    .detail-head img, .detail-head .product-placeholder { margin: auto; }
    .image-grid { grid-template-columns: repeat(2, 1fr); }
    .modal-card { padding: 25px 18px; }
}
