:root {
  color-scheme: light;
  --wine: #174C3C;
  --wine-dark: #10382D;
  --green: #174C3C;
  --green-light: #DCE8DF;
  --orange: #F28C28;
  --ivory: #F5F3ED;
  --white: #FFFFFF;
  --ink: #26332D;
  --muted: #625B57;
  --line: #E8E3DF;
  --success-bg: #EAF2EC;
  --danger-bg: #F5E9EB;
  --shadow: 0 5px 18px rgba(74, 16, 37, .07);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--ivory); color: var(--ink); }
button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
.lab-notice { padding: 12px 16px; border-bottom: 2px solid var(--orange); background: var(--green-light); color: var(--wine-dark); text-align: center; font-size: 13px; font-weight: 700; }
.skip-link { position: fixed; top: -100px; left: 12px; z-index: 20; padding: 12px; border-radius: 10px; background: var(--white); color: var(--wine-dark); }
.skip-link:focus { top: 12px; }
.app-shell { width: min(100%, 720px); min-height: 100vh; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom)); }
.login-screen { min-height: calc(100vh - 32px); display: flex; flex-direction: column; justify-content: center; }
.login-brand, .topbar-brand { display: flex; align-items: center; gap: 11px; }
.login-brand { margin: 10px 3px 26px; }
.login-brand strong, .login-brand small { display: block; }
.login-brand strong { color: var(--wine-dark); letter-spacing: .06em; font-size: 14px; }
.login-brand small { margin-top: 3px; color: var(--muted); font-size: 12px; }
.brand-mark { display: grid; place-items: center; width: 46px; height: 46px; flex: none; border-radius: 15px; background: var(--wine-dark); color: var(--white); font-size: 14px; font-weight: 800; letter-spacing: -.04em; box-shadow: 0 5px 14px rgba(74, 16, 37, .18); }
.brand-mark.small { width: 34px; height: 34px; border-radius: 11px; font-size: 11px; }
.login-card, .panel, .stat-card, .product-card, .sale-card, .valuation-card { border: 1px solid var(--line); border-radius: 20px; background: var(--white); box-shadow: var(--shadow); }
.login-card { padding: 25px 21px 19px; }
.eyebrow { margin: 0 0 7px; color: var(--wine); font-size: 10px; font-weight: 800; letter-spacing: .13em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 7px; color: var(--wine-dark); font-size: clamp(25px, 7vw, 32px); letter-spacing: -.045em; line-height: 1.12; }
h2 { margin: 0; color: var(--wine-dark); font-size: 16px; letter-spacing: -.02em; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.5; }
.login-card > .muted { margin-bottom: 20px; }
label { display: block; margin: 14px 0 7px; color: var(--wine-dark); font-size: 12px; font-weight: 650; }
input, select { width: 100%; min-width: 0; min-height: 48px; border: 1px solid #CFC7C1; border-radius: 12px; background: var(--white); color: var(--ink); padding: 0 13px; font-size: 16px; }
input::placeholder { color: #746C67; }
input:focus-visible, button:focus-visible, summary:focus-visible { outline: 3px solid rgba(196, 90, 22, .42); outline-offset: 2px; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 46px; border: 0; border-radius: 12px; padding: 0 16px; font-size: 13px; font-weight: 700; cursor: pointer; transition: transform .16s ease, background .16s ease; }
.button:active { transform: scale(.985); }
.button-primary { width: 100%; margin-top: 18px; background: var(--wine-dark); color: var(--white); }
.button-primary:hover { background: var(--wine); }
.button-light { border: 1px solid var(--line); background: #FBFAF8; color: var(--wine-dark); }
.button-danger { width: 100%; margin-top: 16px; background: var(--wine); color: var(--white); }
.form-error, .global-error { padding: 11px 13px; border: 1px solid #E3BFC6; border-radius: 12px; background: var(--danger-bg); color: #5C0018; font-size: 13px; line-height: 1.45; }
.form-error { margin: 12px 0 0; }
.device-details { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 15px; }
.device-details summary { color: var(--green); font-size: 12px; font-weight: 700; cursor: pointer; }
.device-details p, .privacy-note { color: var(--muted); font-size: 11px; line-height: 1.5; }
.device-details p { margin: 12px 0 8px; }
.device-details code, .device-panel code { display: block; overflow-wrap: anywhere; padding: 10px; border-radius: 9px; background: var(--ivory); color: var(--wine-dark); font-size: 11px; }
.device-details .button { min-height: 40px; margin-top: 9px; font-size: 12px; }
.privacy-note { margin: 17px 0 0; }
.login-footer { margin: 16px 8px 0; color: var(--muted); text-align: center; font-size: 11px; line-height: 1.5; }
.network-banner { position: sticky; top: max(8px, env(safe-area-inset-top)); z-index: 10; margin: 0 auto 10px; padding: 11px 14px; border: 1px solid #D8C7A8; border-radius: 12px; background: #FFF5E6; color: #4C2C10; font-size: 12px; line-height: 1.45; box-shadow: var(--shadow); }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; margin: -max(16px, env(safe-area-inset-top)) -16px 22px; padding: max(12px, env(safe-area-inset-top)) 18px 11px; border-bottom: 1px solid var(--line); background: rgba(248, 245, 240, .95); backdrop-filter: blur(12px); }
.topbar-brand { color: var(--wine-dark); font-size: 12px; font-weight: 800; letter-spacing: .05em; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.sync-indicator { display: inline-flex; align-items: center; min-height: 28px; padding: 4px 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--white); color: var(--muted); font-size: 10px; font-weight: 800; white-space: nowrap; }
.sync-indicator[data-state="synchronized"] { border-color: #A8C8B2; background: #DCE8DF; color: #10382D; }
.sync-indicator[data-state="syncing"], .sync-indicator[data-state="checking"], .sync-indicator[data-state="pending"] { border-color: #E9B48A; background: #FFF4E8; color: #5C352C; }
.sync-indicator[data-state="offline"] { border-color: #D9CFCA; background: #F3EFEB; color: #5C352C; }
.sync-indicator[data-state="conflict"], .sync-indicator[data-state="rejected"], .sync-indicator[data-state="error"] { border-color: #B67E7D; background: #F5E9EB; color: #420001; }
.icon-button { width: 40px; height: 40px; border: 1px solid #D9CFCA; border-radius: 50%; background: var(--white); color: var(--wine-dark); font-size: 12px; font-weight: 800; }
.screen-heading { margin: 12px 2px 18px; }
.screen-heading h1 { margin-bottom: 5px; }
.screen-heading .muted { margin-bottom: 0; }
.stat-grid { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 15px; }
.stat-card { position: relative; min-height: 132px; padding: 15px 13px; }
.stat-card:first-child { grid-column: 1 / -1; min-height: 146px; background: var(--wine-dark); border-color: var(--wine-dark); color: var(--white); }
.stat-card:first-child .stat-label, .stat-card:first-child small { color: #F5E9EC; }
.stat-icon { display: grid; width: 30px; height: 30px; place-items: center; margin-bottom: 12px; border-radius: 10px; font-size: 16px; font-weight: 800; }
.stat-icon.orange { background: #FFF0E5; color: #823500; }
.stat-icon.green { background: var(--success-bg); color: var(--green); }
.stat-icon.burgundy { background: var(--danger-bg); color: var(--wine); }
.stat-card:first-child .stat-icon { background: rgba(255,255,255,.14); color: #FFD3B5; }
.stat-label, .stat-card strong, .stat-card small { display: block; }
.stat-label { color: var(--muted); font-size: 11px; font-weight: 600; }
.stat-card strong { margin-top: 4px; color: var(--wine-dark); font-size: clamp(21px, 6vw, 27px); letter-spacing: -.04em; }
.stat-card:first-child strong { color: var(--white); font-size: 32px; }
.stat-card small { margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.panel { margin: 14px 0; padding: 17px 15px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-heading .eyebrow { margin-bottom: 4px; }
.text-button { min-height: 40px; border: 0; background: transparent; color: var(--green); font-size: 12px; font-weight: 750; }
.sale-list { display: grid; }
.sale-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; padding: 12px 0; border-top: 1px solid #F0ECE8; }
.sale-row:first-child { border-top: 0; }
.sale-main { min-width: 0; }
.sale-main strong, .sale-main small { display: block; }
.sale-main strong { overflow: hidden; color: var(--ink); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.sale-main small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.sale-total { flex: none; color: var(--green); font-size: 12px; font-weight: 800; }
.quick-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.quick-links button { min-height: 110px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--white); color: var(--wine-dark); text-align: left; box-shadow: var(--shadow); }
.quick-links span, .quick-links b, .quick-links small { display: block; }
.quick-links span { margin-bottom: 10px; color: var(--orange); font-size: 20px; }
.quick-links b { font-size: 12px; }
.quick-links small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.search-form { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.search-form input { min-width: 0; flex: 1; }
.search-form .button { flex: none; min-height: 46px; }
.segmented { display: flex; gap: 5px; padding: 4px; margin-bottom: 15px; border: 1px solid var(--line); border-radius: 13px; background: #F0ECE8; }
.segmented button { flex: 1; min-height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; }
.segmented button.selected { background: var(--white); color: var(--wine-dark); box-shadow: 0 2px 5px rgba(37,37,37,.09); }
.card-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.product-card, .sale-card, .valuation-card { padding: 15px; }
.product-head, .stock-values, .valuation-values { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.product-title { min-width: 0; }
.product-title h2 { overflow-wrap: anywhere; margin: 0; font-size: 14px; }
.product-title p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.product-code { flex: none; padding: 5px 8px; border-radius: 8px; background: #F3EFEB; color: var(--wine-dark); font-size: 10px; font-weight: 750; }
.product-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 13px; }
.pill { display: inline-flex; align-items: center; min-height: 25px; padding: 0 9px; border-radius: 99px; background: #F1ECEB; color: var(--wine-dark); font-size: 10px; font-weight: 650; }
.pill.good { background: var(--success-bg); color: #12402B; }
.pill.low { background: var(--danger-bg); color: #640018; }
.stock-values { align-items: stretch; margin-top: 14px; }
.stock-value { min-width: 0; flex: 1; padding: 10px; border-radius: 11px; background: #F7F4F0; }
.stock-value small, .stock-value strong { display: block; }
.stock-value small { color: var(--muted); font-size: 10px; }
.stock-value strong { margin-top: 5px; color: var(--wine-dark); font-size: 16px; }
.stock-value.total { background: var(--success-bg); }
.stock-value.total strong { color: var(--green); }
.sale-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.sale-card-top strong { color: var(--wine-dark); font-size: 13px; }
.sale-card-top small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.sale-card-total { flex: none; color: var(--green); font-size: 14px; font-weight: 800; text-align: right; }
.sale-lines { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 9px; }
.sale-line { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; color: var(--muted); font-size: 10px; }
.date-filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; align-items: end; gap: 8px; margin-bottom: 15px; }
.date-filters label { min-width: 0; margin: 0; color: var(--muted); font-size: 10px; }
.date-filters input { min-height: 43px; margin-top: 5px; padding: 0 8px; font-size: 13px; }
.date-filters .button { min-height: 43px; padding: 0 12px; }
.summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin: 13px 0; }
.summary-tile { padding: 13px; border: 1px solid var(--line); border-radius: 13px; background: var(--white); }
.summary-tile small, .summary-tile strong { display: block; }
.summary-tile small { color: var(--muted); font-size: 10px; }
.summary-tile strong { margin-top: 6px; color: var(--wine-dark); font-size: 17px; }
.ranking-list { display: grid; gap: 8px; }
.ranking-row { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 11px; background: #F8F5F0; }
.ranking-rank { display: grid; width: 28px; height: 28px; flex: none; place-items: center; border-radius: 9px; background: var(--wine-dark); color: var(--white); font-size: 11px; font-weight: 800; }
.ranking-row span:nth-child(2) { min-width: 0; flex: 1; }
.ranking-row b, .ranking-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-row b { color: var(--ink); font-size: 11px; }
.ranking-row small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.ranking-row strong { flex: none; color: var(--green); font-size: 11px; }
.valuation-summary { padding: 16px; border-radius: 15px; background: var(--green); color: var(--white); }
.valuation-summary small, .valuation-summary strong { display: block; }
.valuation-summary small { color: #E4F0E9; font-size: 11px; }
.valuation-summary strong { margin-top: 5px; font-size: 23px; }
.valuation-card { margin-top: 10px; }
.valuation-values { margin-top: 13px; }
.valuation-value { flex: 1; }
.valuation-value small, .valuation-value strong { display: block; }
.valuation-value small { color: var(--muted); font-size: 10px; }
.valuation-value strong { margin-top: 4px; color: var(--wine-dark); font-size: 13px; }
.profile-card { display: flex; align-items: center; gap: 13px; }
.profile-avatar { display: grid; width: 48px; height: 48px; flex: none; place-items: center; border-radius: 16px; background: var(--wine-dark); color: var(--white); font-size: 14px; font-weight: 800; }
.profile-card strong, .profile-card small { display: block; }
.profile-card strong { color: var(--wine-dark); font-size: 15px; }
.profile-card small { margin-top: 4px; color: var(--muted); font-size: 11px; }
.permission-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.permission-list li { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 12px; }
.permission-list li::before { content: "✓"; color: var(--green); font-weight: 800; }
.admin-form { display: grid; gap: 12px; }
.admin-form label { display: grid; gap: 5px; color: var(--ink); font-size: 12px; font-weight: 650; }
.admin-form input { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 11px; padding: 9px 11px; background: var(--white); color: var(--ink); font: inherit; }
.admin-form input:focus { outline: 3px solid rgba(23,76,60,.16); border-color: var(--green); }
.admin-access-card { overflow-wrap: anywhere; }
.device-panel h2 { margin-bottom: 12px; }
.device-panel .muted { margin: 9px 0 0; font-size: 11px; }
.loading { display: flex; align-items: center; gap: 10px; min-height: 80px; color: var(--muted); font-size: 12px; }
.loading::before { width: 17px; height: 17px; border: 2px solid #D8CDC7; border-top-color: var(--orange); border-radius: 50%; content: ""; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { padding: 23px 16px; border: 1px dashed #D8CDC7; border-radius: 15px; background: rgba(255,255,255,.7); color: var(--muted); text-align: center; font-size: 12px; line-height: 1.5; }
.empty-state strong { display: block; margin-bottom: 4px; color: var(--wine-dark); font-size: 13px; }
.global-error { margin: 0 0 14px; }
.more-button { width: 100%; margin: 13px 0 3px; }
.bottom-nav { position: fixed; right: 0; bottom: 0; left: 0; z-index: 9; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); padding: 8px 7px calc(7px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(255,255,255,.96); backdrop-filter: blur(14px); }
.bottom-nav button { display: grid; min-height: 52px; align-content: center; justify-items: center; gap: 3px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); }
.bottom-nav button span { height: 19px; font-size: 18px; font-weight: 700; line-height: 1; }
.bottom-nav button small { font-size: 9px; font-weight: 650; }
.bottom-nav button.selected { color: var(--wine); }
.sync-notice { margin: 0 0 13px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--white); color: var(--wine-dark); font-size: 12px; font-weight: 700; }
.sync-notice[data-kind="error"], .sync-notice[data-kind="conflict"] { border-color: #B67E7D; background: #F5E9EB; color: #420001; }
.sync-notice[data-kind="success"] { border-color: #A8C8B2; background: #DCE8DF; color: #10382D; }
.sync-notice[data-kind="offline"] { border-color: #E9B48A; background: #FFF4E8; color: #5C352C; }
.sync-stock-card { padding: 12px; border: 1px solid var(--line); border-radius: 13px; background: #fff; }
.sync-stock-card h3 { margin: 0 0 8px; color: var(--wine-dark); font-size: 13px; }
.sync-stock-card p { margin: 4px 0; color: var(--muted); font-size: 11px; }
.sync-stock-card strong { color: var(--ink); }
.sync-op { padding: 12px; border: 1px solid var(--line); border-radius: 13px; background: #fff; }
.sync-op-top { display:flex; justify-content:space-between; gap:10px; align-items:center; }
.sync-op strong { color: var(--wine-dark); font-size: 12px; }
.sync-op small { display:block; margin-top:5px; color:var(--muted); font-size:10px; }
.sync-status { flex:none; max-width:55%; padding:5px 8px; border-radius:99px; background:var(--green-light); color:var(--wine-dark); font-size:10px; font-weight:700; text-align:center; }
.sync-status[data-status="error"], .sync-status[data-status="blocked"], .sync-status[data-status="conflict"] { background:#F5E9EB; color:#420001; }
.sync-status[data-status="pending"], .sync-status[data-status="sending"] { background:#FFF0DF; color:#5C352C; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* Keep native mobile controls legible without focus zoom and usable by touch. */
.icon-button { width: 44px; height: 44px; }
.text-button, .device-details .button, .segmented button { min-height: 44px; }
.admin-form input, .admin-form select { min-height: 48px; font-size: 16px; }
select:focus-visible { outline: 3px solid rgba(196, 90, 22, .42); outline-offset: 2px; }
.topbar-brand, .topbar-actions { min-width: 0; }
@media (max-width: 359px) {
  .topbar { padding-left: 10px; padding-right: 10px; }
  .topbar-brand { gap: 5px; font-size: 10px; }
  .topbar-actions { gap: 5px; }
  .sync-indicator { padding-left: 5px; padding-right: 5px; white-space: normal; }
}

@media (min-width: 600px) {
  .app-shell { padding-right: 24px; padding-left: 24px; }
  .topbar { margin-right: -24px; margin-left: -24px; padding-right: 26px; padding-left: 26px; }
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat-card:first-child { grid-column: auto; }
  .stat-card:first-child strong { font-size: 25px; }
  .bottom-nav { right: max(0px, calc((100vw - 720px) / 2)); left: max(0px, calc((100vw - 720px) / 2)); border-right: 1px solid var(--line); border-left: 1px solid var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

.management-details{margin:1rem 0}.management-field{display:flex;gap:1rem;justify-content:space-between;padding:.4rem 0;border-bottom:1px solid #DCE8DF}.management-field dt{color:#526159}.management-field dd{margin:0;text-align:right;overflow-wrap:anywhere}.conflict-details{white-space:pre-wrap;overflow-wrap:anywhere;font-size:.8rem}.admin-form textarea{min-height:100px;padding:12px;font:inherit;border:1px solid #DCE8DF;border-radius:10px;max-width:100%}

.card-list .panel{min-width:0;overflow-wrap:anywhere}.management-field dt,.management-field dd{min-width:0;flex:1;overflow-wrap:anywhere}
@media(max-width:420px){.date-filters{grid-template-columns:repeat(2,minmax(0,1fr))}.date-filters .button{grid-column:1/-1}}
