:root {
  --ink: #14231f;
  --muted: #65736e;
  --line: #dfe6e2;
  --soft: #f3f6f4;
  --paper: #ffffff;
  --green: #0e6b50;
  --green-dark: #0a4e3c;
  --green-soft: #dff3ea;
  --lime: #b8df65;
  --amber: #a56308;
  --amber-soft: #fff1ce;
  --red: #aa3f3f;
  --red-soft: #fde8e5;
  --shadow: 0 18px 50px rgba(16, 42, 36, .08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: #edf1ee; }
body { margin: 0; color: var(--ink); background: linear-gradient(180deg, #f7f9f7 0, #edf1ee 420px); font-family: "DM Sans", sans-serif; font-size: 14px; }
button, input, select { font: inherit; }
a { color: inherit; text-decoration: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.topbar { min-height: 72px; display: flex; align-items: center; gap: 34px; padding: 10px 30px; background: #102a24; color: #fff; position: sticky; top: 0; z-index: 50; box-shadow: 0 8px 24px rgba(5, 27, 21, .16); }
.brand { display: flex; align-items: center; gap: 11px; min-width: 230px; }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: var(--lime); color: #163324; font: 800 14px "Manrope", sans-serif; }
.brand strong, .brand small { display: block; }
.brand strong { font: 700 15px "Manrope", sans-serif; }
.brand small { margin-top: 2px; color: #a9bcb5; font-size: 11px; }
.topnav { display: flex; gap: 7px; flex: 1; }
.topnav a { color: #bed0ca; padding: 10px 12px; border-radius: 9px; font-weight: 600; }
.topnav a:hover { color: #fff; background: rgba(255,255,255,.07); }
.user-menu { display: flex; align-items: center; gap: 9px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: #2e554a; color: #dff3ea; font-weight: 700; }
.avatar.small { width: 31px; height: 31px; flex: 0 0 31px; }
.user-name { font-weight: 600; max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-button { color: #adc0ba; background: none; border: 0; cursor: pointer; padding: 7px; }
.link-button:hover { color: #fff; }

.page-shell { max-width: 1680px; margin: 0 auto; padding: 30px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-heading.compact { align-items: center; }
.page-heading h1 { margin: 4px 0 5px; font: 800 clamp(25px, 3vw, 38px) "Manrope", sans-serif; letter-spacing: -.04em; }
.page-heading p { margin: 0; color: var(--muted); font-size: 15px; }
.eyebrow { color: var(--green); font-size: 10px; font-weight: 800; letter-spacing: .14em; }
.heading-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }
.heading-actions select { min-width: 180px; }
.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; padding: 0 16px; border: 1px solid var(--line); font-weight: 700; cursor: pointer; }
.button.primary { background: var(--green); border-color: var(--green); color: #fff; }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { background: var(--paper); }
.button.secondary:hover { border-color: #a9b9b3; }
.button.wide { width: 100%; }
select, input { border: 1px solid #cfd9d4; border-radius: 9px; background: #fff; color: var(--ink); min-height: 40px; padding: 8px 11px; }
select:focus, input:focus { outline: 3px solid rgba(14,107,80,.14); border-color: var(--green); }

.progress-panel { padding: 20px 22px; background: #163a31; color: #fff; border-radius: 16px; box-shadow: var(--shadow); margin-bottom: 18px; display: grid; grid-template-columns: 190px 1fr auto; gap: 22px; align-items: center; }
.progress-copy strong { font: 800 27px "Manrope", sans-serif; display: block; }
.progress-copy span { color: #b7cbc4; }
.progress-track { height: 10px; background: rgba(255,255,255,.13); border-radius: 999px; overflow: hidden; }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--lime), #d7ef96); }
.progress-meta { display: flex; gap: 18px; color: #c7d7d1; font-size: 12px; white-space: nowrap; }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.metric-card { min-height: 148px; padding: 22px; border-radius: 15px; background: var(--paper); border: 1px solid var(--line); box-shadow: 0 8px 26px rgba(16,42,36,.04); }
.metric-card.featured { background: #e6f4ea; border-color: #cbe7d4; }
.metric-card span, .metric-card small { display: block; color: var(--muted); }
.metric-card strong { display: block; margin: 18px 0 7px; font: 800 clamp(21px, 2vw, 28px) "Manrope", sans-serif; letter-spacing: -.03em; }
.negative { color: var(--red) !important; }
.positive { color: var(--green) !important; }
.dashboard-grid { display: grid; grid-template-columns: .8fr 1.2fr; gap: 18px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 15px; padding: 20px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.panel-header h2 { margin: 4px 0 0; font: 700 18px "Manrope", sans-serif; }
.panel-header a { color: var(--green); font-weight: 700; }
.live-dot { color: var(--green); background: var(--green-soft); border-radius: 999px; padding: 5px 9px; font-size: 11px; font-weight: 700; }
.presence-list, .activity-list { display: grid; }
.presence-row, .activity-row { display: flex; align-items: center; gap: 11px; padding: 11px 0; border-top: 1px solid #edf1ef; }
.presence-row:first-child, .activity-row:first-child { border-top: 0; }
.presence-row div, .activity-row div { min-width: 0; flex: 1; }
.presence-row strong, .presence-row small, .activity-row strong, .activity-row small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.presence-row small, .activity-row small, .presence-row time, .activity-row time { color: var(--muted); font-size: 11px; }
.activity-icon { width: 29px; height: 29px; border-radius: 9px; display: grid; place-items: center; background: var(--soft); color: var(--green); }
.muted { color: var(--muted); }

.mini-stats { display: grid; grid-template-columns: repeat(4, minmax(110px, 1fr)) auto; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin-bottom: 14px; }
.mini-stats > div { background: #fff; padding: 15px 18px; }
.mini-stats span { color: var(--muted); font-size: 11px; display: block; }
.mini-stats strong { display: block; margin-top: 4px; font: 700 18px "Manrope", sans-serif; }
.mini-stats .online-summary { display: flex; align-items: center; gap: 6px; min-width: 120px; }
.mini-stats .online-summary span, .mini-stats .online-summary strong { display: inline; margin: 0; }
.live-pulse { width: 8px; height: 8px; border-radius: 50%; background: #36ad72; box-shadow: 0 0 0 5px rgba(54,173,114,.13); }
.session-status { border-radius: 999px; padding: 7px 11px; font-weight: 700; font-size: 12px; }
.session-status.active { background: var(--green-soft); color: var(--green-dark); }
.session-status.closed { background: var(--red-soft); color: var(--red); }
.session-status.draft { background: var(--amber-soft); color: var(--amber); }

.count-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 13px 13px 0 0; }
.search-form { display: flex; align-items: center; gap: 10px; flex: 1; }
.search-box { flex: 1; max-width: 620px; height: 42px; display: flex; align-items: center; gap: 9px; border: 1px solid #cfd9d4; border-radius: 9px; padding: 0 11px; background: #fff; }
.search-box:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(14,107,80,.12); }
.search-box input { flex: 1; min-width: 0; min-height: 0; border: 0; padding: 0; outline: 0; box-shadow: none; }
.search-box kbd { border: 1px solid var(--line); background: var(--soft); border-radius: 5px; padding: 2px 5px; color: var(--muted); font-size: 10px; }
.filter-select { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.filter-select select { min-width: 130px; }
.toolbar-note { color: var(--muted); font-size: 12px; text-align: right; }

.count-table-wrap, .history-table-wrap { background: #fff; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 13px 13px; box-shadow: var(--shadow); }
.table-scroll { overflow: auto; max-width: 100%; }
.count-table, .history-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.count-table { min-width: 1410px; }
.history-table { min-width: 1120px; }
th { position: sticky; top: 0; z-index: 5; background: #f6f8f7; color: #596861; text-align: left; text-transform: uppercase; letter-spacing: .05em; font-size: 9px; padding: 11px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid #e9eeeb; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfdfc; }
.count-table .row-col { width: 104px; }
.count-table .product-id-col { min-width: 150px; }
.count-table .count-col { width: 145px; }
.number { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td small { color: var(--muted); font-size: 10px; display: block; margin-top: 3px; }
.source-row { color: var(--muted); white-space: nowrap; }
.source-row > small { margin: 0 0 2px; font-size: 8px; font-weight: 800; letter-spacing: .1em; }
.source-row > span { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.history-button { border: 0; background: transparent; color: var(--green); cursor: pointer; margin-left: 4px; opacity: .65; }
.history-button:hover { opacity: 1; }
.code { font-size: 12px; }
.product-id-cell { min-width: 150px; }
.product-id-cell > small { margin: 0 0 2px; color: var(--green); font-size: 9px; font-weight: 800; letter-spacing: .12em; }
.product-id { display: block; color: #082f24; font: 800 21px/1.12 "Manrope", sans-serif; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.catalog-code-cell { min-width: 120px; }
.catalog-code-cell .code { display: block; }
.current-row-badge { margin-top: 6px; width: max-content; border-radius: 5px; padding: 3px 5px; background: #f4b942; color: #3d2b00; font-size: 8px; font-weight: 800; letter-spacing: .05em; }
.count-table tbody tr { transition: box-shadow .15s ease; }
.count-table tbody tr.is-current-row td { background: #fff8dc; border-top-color: #f0cf70; border-bottom-color: #f0cf70; }
.count-table tbody tr.is-current-row td:first-child { box-shadow: inset 5px 0 #e5a514; }
.count-table tbody tr.is-current-row .current-row-badge { display: block; }
.count-table tbody tr.is-current-row .product-id { color: #8a5600; }
.product-cell { width: 31%; min-width: 330px; }
.product-cell > strong { line-height: 1.3; font-size: 12px; }
.muted-value { color: #62716b; }
.cell-input { width: 100%; min-height: 36px; padding: 7px 9px; border-color: transparent; background: #f5f7f6; }
.cell-input:hover { border-color: #ccd7d1; background: #fff; }
.quantity-input { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.count-input-cell { position: relative; }
.save-state { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: 10px; pointer-events: none; }
.save-state.saving::after { content: "…"; color: var(--amber); }
.save-state.saved::after { content: "✓"; color: var(--green); }
.save-state.error::after { content: "!"; color: var(--red); }
.status-pill { font-size: 11px; font-weight: 700; }
.status-pill.pending { background: #f0f2f1; color: #65736e; }
.status-pill.counted { background: var(--green-soft); color: var(--green-dark); }
.status-pill.verify { background: var(--amber-soft); color: var(--amber); }
.presence-badge { display: inline-block; margin-top: 5px; border-radius: 6px; background: #e7f0ff; color: #285a92; padding: 3px 6px; font-size: 10px; }
.activity-cell { min-width: 110px; }
.modified-by { font-size: 11px; font-weight: 600; }
.row-conflict td { animation: conflictFlash 1.5s ease; }
@keyframes conflictFlash { 0%, 60% { background: var(--amber-soft); } 100% { background: transparent; } }
.no-results { padding: 50px; text-align: center; color: var(--muted); }
.no-results strong, .no-results span { display: block; }
.no-results strong { color: var(--ink); font: 700 17px "Manrope", sans-serif; margin-bottom: 5px; }
.pagination { min-height: 54px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 8px 15px; border-top: 1px solid var(--line); color: var(--muted); }
.pagination a { color: var(--green); font-weight: 700; }
.pagination a:last-child { justify-self: end; }
.pagination > span:nth-child(2) { text-align: center; }

.history-table-wrap { border-top: 1px solid var(--line); border-radius: 13px; margin-top: 14px; }
.history-table td:first-child strong, .history-table td:first-child small, .history-table td:nth-child(2) strong, .history-table td:nth-child(2) small { display: block; white-space: nowrap; }
.field-chip { display: inline-block; padding: 5px 8px; border-radius: 7px; background: var(--soft); font-size: 11px; font-weight: 700; white-space: nowrap; }
.change-old { color: var(--red); }
.change-new { color: var(--green); font-weight: 700; }

.history-dialog { width: min(700px, calc(100vw - 30px)); border: 0; border-radius: 16px; padding: 25px; box-shadow: 0 26px 80px rgba(4,31,23,.28); }
.history-dialog::backdrop { background: rgba(7,30,24,.5); backdrop-filter: blur(3px); }
.dialog-close { position: absolute; right: 14px; top: 12px; border: 0; background: transparent; font-size: 25px; color: var(--muted); cursor: pointer; }
.history-dialog h2 { margin: 2px 35px 3px 0; font: 700 19px "Manrope", sans-serif; }
.dialog-subtitle { margin: 0 0 17px; color: var(--muted); }
.dialog-timeline { display: grid; max-height: 55vh; overflow: auto; }
.timeline-row { display: grid; grid-template-columns: 125px 1fr; gap: 15px; padding: 12px 0; border-top: 1px solid var(--line); }
.timeline-row time { color: var(--muted); font-size: 11px; }
.timeline-row strong, .timeline-row small { display: block; }
.timeline-row small { color: var(--muted); margin-top: 4px; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: 390px; transform: translateY(20px); opacity: 0; pointer-events: none; z-index: 100; padding: 12px 16px; border-radius: 10px; background: #102a24; color: #fff; box-shadow: var(--shadow); transition: .2s ease; }
.toast.visible { transform: translateY(0); opacity: 1; }
.toast.error { background: #8e3434; }

.login-wrap { min-height: calc(100vh - 132px); display: grid; grid-template-columns: 1fr .75fr; max-width: 950px; margin: 30px auto; border-radius: 22px; overflow: hidden; background: #fff; box-shadow: var(--shadow); }
.login-panel { padding: clamp(35px, 6vw, 75px); }
.login-panel h1 { margin: 8px 0; font: 800 34px "Manrope", sans-serif; letter-spacing: -.04em; }
.login-panel > p { color: var(--muted); line-height: 1.6; }
.login-form { display: grid; gap: 7px; margin-top: 30px; }
.login-form label { margin-top: 9px; font-weight: 700; font-size: 12px; }
.login-form .button { margin-top: 16px; }
.login-aside { padding: 48px; background: #13372e; color: #fff; display: flex; flex-direction: column; justify-content: flex-end; }
.aside-number { color: var(--lime); font: 800 62px "Manrope", sans-serif; letter-spacing: -.06em; }
.login-aside strong { font: 700 23px/1.2 "Manrope", sans-serif; }
.login-aside p { color: #b7cbc4; line-height: 1.6; }
.form-error, .message { padding: 10px 12px; border-radius: 8px; background: var(--red-soft); color: var(--red); }
.messages { margin-bottom: 15px; }
.empty-state { padding: 100px 20px; text-align: center; }
.empty-state h1 { font: 800 30px "Manrope", sans-serif; }
.empty-state p { color: var(--muted); }
.empty-icon { width: 70px; height: 70px; margin: auto; display: grid; place-items: center; border-radius: 20px; background: var(--green-soft); color: var(--green); font-size: 28px; }

@media (max-width: 1000px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .progress-panel { grid-template-columns: 150px 1fr; }
  .progress-meta { grid-column: 1 / -1; justify-content: flex-end; }
  .topnav { display: none; }
  .mini-stats { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 700px) {
  .topbar { min-height: 62px; padding: 9px 14px; }
  .brand { min-width: 0; flex: 1; }
  .brand small, .user-name { display: none; }
  .page-shell { padding: 18px 12px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .heading-actions { justify-content: flex-start; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 125px; }
  .progress-panel { grid-template-columns: 1fr; gap: 12px; }
  .progress-meta { grid-column: auto; justify-content: flex-start; }
  .mini-stats { grid-template-columns: repeat(2, 1fr); }
  .mini-stats .online-summary { min-width: 0; }
  .count-toolbar, .search-form { align-items: stretch; flex-direction: column; }
  .search-box { width: 100%; }
  .filter-select { justify-content: space-between; }
  .toolbar-note { text-align: left; }
  .login-wrap { grid-template-columns: 1fr; margin: 0; min-height: calc(100vh - 98px); }
  .login-aside { padding: 28px; }
  .aside-number { font-size: 42px; }
}
