:root {
  --navy-950: #08233a;
  --navy-900: #12395a;
  --navy-800: #174d72;
  --teal-600: #078b7b;
  --teal-500: #0ba892;
  --teal-100: #dff6f2;
  --red-700: #aa2a35;
  --red-100: #fdebed;
  --amber-700: #9a5a06;
  --amber-100: #fff3d8;
  --green-700: #20704f;
  --green-100: #e2f4eb;
  --ink: #152637;
  --muted: #647484;
  --line: #dbe3e8;
  --surface: #ffffff;
  --canvas: #f3f6f8;
  --shadow: 0 18px 48px rgba(15, 43, 65, 0.12);
  color-scheme: light;
  font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
[hidden] { display: none !important; }

.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;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 10%, rgba(11, 168, 146, 0.28), transparent 34%),
    linear-gradient(145deg, var(--navy-950), var(--navy-800));
}

.login-card {
  width: min(100%, 450px);
  padding: 42px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 30px 80px rgba(2, 18, 31, 0.35);
}

.brand-mark {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 14px;
  margin-bottom: 28px;
  border-radius: 12px;
  color: white;
  background: var(--navy-900);
}
.brand-mark span { font-weight: 800; letter-spacing: 0.08em; }
.brand-mark b { color: #72ddcd; font-size: 0.78rem; }
.login-card h1 { margin: 4px 0 10px; font-size: clamp(2rem, 7vw, 2.7rem); line-height: 1.04; }
.login-copy { margin: 0 0 28px; color: var(--muted); line-height: 1.6; }
.secure-note { margin: 20px 0 0; text-align: center; color: var(--muted); font-size: 0.78rem; }

.eyebrow {
  margin: 0 0 5px;
  color: var(--teal-600);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.stack-form { display: grid; gap: 17px; }
label { display: grid; gap: 7px; color: #344757; font-size: 0.85rem; font-weight: 700; }
label > span { color: var(--red-700); }
label small { color: var(--muted); font-weight: 500; }

input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 11px 13px;
  border: 1px solid #c7d2da;
  border-radius: 10px;
  outline: none;
  color: var(--ink);
  background: #fff;
  transition: border-color 0.16s, box-shadow 0.16s;
}
textarea { min-height: 72px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--teal-500); box-shadow: 0 0 0 3px rgba(11, 168, 146, 0.15); }

.button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 17px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.12s, background 0.12s, box-shadow 0.12s;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button:disabled { cursor: wait; opacity: 0.65; transform: none; }
.button-primary { color: #fff; background: var(--teal-600); box-shadow: 0 7px 18px rgba(7, 139, 123, 0.22); }
.button-primary:hover { background: #067768; }
.button-secondary { color: var(--navy-900); border-color: #bdcbd5; background: #fff; }
.button-light { color: var(--navy-900); background: #fff; }
.button-ghost { color: #dce8ef; border-color: rgba(255, 255, 255, 0.24); background: rgba(255, 255, 255, 0.06); }
.button-scan { color: #fff; background: var(--navy-900); }
.button-small { min-height: 36px; padding: 7px 13px; color: var(--amber-700); border-color: #efc979; background: #fff; }
.button-compact { min-height: 38px; padding: 7px 12px; font-size: 0.82rem; }
.button-full { width: 100%; margin-top: 3px; }
.icon-button {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
  font-size: 1.35rem;
}
.icon-button:hover { color: var(--ink); background: #edf2f5; }

.topbar { position: sticky; z-index: 20; top: 0; color: #fff; background: var(--navy-950); box-shadow: 0 5px 20px rgba(5, 31, 49, 0.16); }
.topbar-inner { width: min(1440px, calc(100% - 40px)); min-height: 70px; margin: auto; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.product-name { display: flex; align-items: center; gap: 12px; }
.product-name strong, .product-name small { display: block; }
.product-name strong { font-size: 0.98rem; }
.product-name small { margin-top: 2px; color: #9fc3d5; font-size: 0.72rem; letter-spacing: 0.06em; }
.product-symbol { width: 39px; height: 39px; display: grid; place-items: center; border-radius: 11px; font-size: 0.76rem; font-weight: 850; background: var(--teal-600); }
.user-actions { display: flex; align-items: center; gap: 9px; }
.current-user { color: #bcd0dc; font-size: 0.82rem; }

.content { width: min(1440px, calc(100% - 40px)); margin: auto; padding: 38px 0 60px; }
.hero-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.hero-row h1 { margin: 0 0 7px; font-size: clamp(1.9rem, 4vw, 2.8rem); letter-spacing: -0.035em; }
.hero-row p:not(.eyebrow) { margin: 0; color: var(--muted); }

.notice { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 13px 16px; margin-bottom: 18px; border: 1px solid; border-radius: 12px; font-size: 0.86rem; }
.notice-warning { color: #704608; border-color: #efd08e; background: var(--amber-100); }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { min-height: 142px; display: flex; flex-direction: column; justify-content: space-between; padding: 20px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 8px 25px rgba(18, 57, 90, 0.055); }
.stat-card span { color: var(--muted); font-size: 0.8rem; font-weight: 750; }
.stat-card strong { margin: 7px 0; color: var(--navy-900); font-size: 2.25rem; line-height: 1; }
.stat-card small { color: #8795a0; }
.stat-card.stat-primary { color: #fff; border-color: var(--navy-900); background: linear-gradient(145deg, var(--navy-900), #1a597f); }
.stat-card.stat-primary span, .stat-card.stat-primary strong, .stat-card.stat-primary small { color: #fff; }
.stat-card.stat-danger strong { color: var(--red-700); }
.stat-card.stat-warning strong { color: var(--amber-700); }

.panel { margin-top: 20px; padding: 22px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); box-shadow: 0 8px 25px rgba(18, 57, 90, 0.05); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.panel-heading h2 { margin: 0; font-size: 1.25rem; }
.panel-heading .muted { margin: 5px 0 0; }
.muted { color: var(--muted); font-size: 0.82rem; }

.alerts-panel { border-left: 4px solid #df9b2d; }
.alert-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.alert-item { min-width: 0; padding: 13px 14px; border: 1px solid #f0d5a4; border-radius: 11px; background: #fffbf2; }
.alert-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.88rem; }
.alert-item span { display: block; margin-top: 5px; color: var(--muted); font-size: 0.75rem; }

.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 4px 9px; border-radius: 999px; font-size: 0.68rem; font-weight: 850; letter-spacing: 0.02em; text-transform: uppercase; }
.badge-found { color: var(--green-700); background: var(--green-100); }
.badge-danger { color: var(--red-700); background: var(--red-100); }
.badge-warning { color: var(--amber-700); background: var(--amber-100); }
.badge-neutral { color: #465766; background: #eaf0f3; }

.filters { display: grid; grid-template-columns: minmax(270px, 1fr) auto minmax(170px, 220px) minmax(170px, 220px); gap: 10px; margin-bottom: 18px; }
.search-box { min-height: 44px; display: flex; align-items: center; gap: 9px; padding-left: 13px; border: 1px solid #c7d2da; border-radius: 10px; background: #fff; }
.search-box:focus-within { border-color: var(--teal-500); box-shadow: 0 0 0 3px rgba(11, 168, 146, 0.15); }
.search-box input { min-height: 42px; padding: 8px 0; border: 0; box-shadow: none; }
.search-box input:focus { box-shadow: none; }
.select-wrap { gap: 0; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; min-width: 960px; border-collapse: collapse; }
th { padding: 12px 13px; color: #607080; background: #edf2f5; font-size: 0.7rem; letter-spacing: 0.055em; text-align: left; text-transform: uppercase; }
td { padding: 13px; border-top: 1px solid #e4eaee; vertical-align: middle; font-size: 0.82rem; }
tbody tr:hover { background: #f8fafb; }
.material-cell { max-width: 310px; }
.material-cell strong, .material-cell small { display: block; }
.material-cell strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.material-cell small { margin-top: 4px; color: var(--muted); }
.number-cell { font-variant-numeric: tabular-nums; }
.stock-number { color: var(--navy-900); font-size: 1rem; font-weight: 850; }
.actions-column { width: 145px; text-align: right; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.row-action { min-height: 32px; padding: 5px 8px; border: 1px solid #cfd9df; border-radius: 8px; color: var(--navy-900); background: #fff; font-size: 0.72rem; font-weight: 750; }
.row-action:hover { border-color: var(--teal-500); }
.mobile-cards { display: none; }

.loading-state, .empty-state { min-height: 190px; align-items: center; justify-content: center; flex-direction: column; gap: 10px; color: var(--muted); text-align: center; }
.loading-state:not([hidden]), .empty-state:not([hidden]) { display: flex; }
.empty-state p { margin: 0; }
.spinner { width: 28px; height: 28px; border: 3px solid #dce5ea; border-top-color: var(--teal-600); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.app-footer { padding: 22px; border-top: 1px solid var(--line); color: var(--muted); background: #fff; font-size: 0.76rem; text-align: center; }

dialog { max-width: none; max-height: none; padding: 0; border: 0; background: transparent; }
dialog::backdrop { background: rgba(5, 25, 39, 0.72); backdrop-filter: blur(3px); }
.modal { width: min(100% - 28px, 610px); }
.modal-wide { width: min(100% - 28px, 940px); }
.modal-card { max-height: calc(100vh - 30px); overflow: auto; padding: 24px; border-radius: 18px; background: #fff; box-shadow: var(--shadow); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.modal-header h2 { margin: 0; font-size: 1.45rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; padding-top: 17px; border-top: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.span-2 { grid-column: span 2; }
.input-action { display: flex; align-items: stretch; gap: 7px; }
.input-action input { min-width: 0; }
.form-error { min-height: 18px; margin: 10px 0 0; color: var(--red-700); font-size: 0.8rem; font-weight: 650; }

.scanner-frame { position: relative; overflow: hidden; aspect-ratio: 4 / 3; border-radius: 13px; background: #08151f; }
.scanner-frame video { width: 100%; height: 100%; object-fit: cover; }
.scan-guide { position: absolute; inset: 25% 9%; border: 3px solid #55ead4; border-radius: 13px; box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.18); }
.scanner-status { min-height: 22px; margin: 12px 0; color: var(--muted); font-size: 0.82rem; text-align: center; }
.manual-code { margin-top: 12px; }

.history-list { display: grid; gap: 12px; }
.history-entry { padding: 14px; border: 1px solid var(--line); border-radius: 11px; background: #f9fbfc; }
.history-entry-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.history-entry-head strong { color: var(--navy-900); font-size: 0.85rem; }
.history-entry-head time { color: var(--muted); font-size: 0.74rem; }
.history-entry p { margin: 7px 0 0; color: var(--muted); font-size: 0.78rem; }
.change-list { display: grid; gap: 5px; margin: 9px 0 0; padding: 0; list-style: none; }
.change-list li { padding: 7px 9px; border-radius: 7px; background: #fff; font-size: 0.75rem; }
.change-list b { color: var(--navy-900); }

.toast { position: fixed; z-index: 100; right: 22px; bottom: 22px; max-width: min(420px, calc(100% - 44px)); padding: 13px 16px; border-radius: 11px; color: #fff; background: var(--navy-950); box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: 0.2s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red-700); }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: minmax(260px, 1fr) auto 1fr; }
  .filters .select-wrap:last-child { grid-column: 3; }
  .alert-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .topbar-inner, .content { width: min(100% - 24px, 100%); }
  .topbar-inner { min-height: 62px; }
  .current-user, #passwordButton { display: none; }
  .product-name strong { font-size: 0.88rem; }
  .content { padding-top: 24px; }
  .hero-row { align-items: stretch; flex-direction: column; }
  .hero-row .button { width: 100%; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-card { min-height: 122px; padding: 15px; }
  .stat-card strong { font-size: 1.85rem; }
  .panel { padding: 15px; border-radius: 14px; }
  .panel-heading-responsive { align-items: flex-start; }
  .filters { grid-template-columns: 1fr auto; }
  .filters .select-wrap { grid-column: auto; }
  .filters .select-wrap:last-child { grid-column: auto; }
  .search-box { min-width: 0; }
  .button-scan { padding-inline: 13px; }
  .table-wrap { display: none; }
  .mobile-cards { display: grid; gap: 11px; }
  .material-card { padding: 15px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
  .material-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
  .material-card h3 { margin: 0; font-size: 0.95rem; }
  .material-card .model { margin: 4px 0 0; color: var(--muted); font-size: 0.76rem; }
  .material-card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 14px 0; }
  .material-card-grid span { display: block; color: var(--muted); font-size: 0.68rem; text-transform: uppercase; }
  .material-card-grid strong { display: block; margin-top: 4px; overflow-wrap: anywhere; font-size: 0.82rem; }
  .material-card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .row-action { min-height: 38px; }
  .alert-list { grid-template-columns: 1fr; }
  .modal-card { padding: 18px; border-radius: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .modal-footer { position: sticky; bottom: -18px; margin-inline: -18px; padding: 14px 18px; background: #fff; }
}

@media (max-width: 480px) {
  .login-shell { padding: 14px; }
  .login-card { padding: 28px 22px; border-radius: 22px; }
  .topbar-inner { width: calc(100% - 20px); }
  .product-symbol { width: 35px; height: 35px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-card { min-height: 114px; }
  .stat-card span { font-size: 0.7rem; }
  .stat-card small { font-size: 0.66rem; }
  .panel-heading-responsive { flex-direction: column; }
  .filters { grid-template-columns: 1fr; }
  .filters > * { grid-column: 1 !important; }
  .button-scan { width: 100%; }
  .notice { align-items: stretch; flex-direction: column; }
  .modal-footer { display: grid; grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
