:root {
  color-scheme: dark;
  --bg: #050506;
  --panel: #101112;
  --panel-2: #151619;
  --text: #f3f3f3;
  --muted: #a9a9ad;
  --line: rgba(255, 255, 255, 0.18);
  --line-soft: rgba(255, 255, 255, 0.1);
  --accent: #f1f1f1;
  --danger: #ff5b52;
  --ok: #4ad27a;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.08), transparent 26rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app {
  width: min(1180px, calc(100% - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 9, 10, 0.92);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.topbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--accent);
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.test-badge {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid rgba(240, 185, 90, 0.5);
  border-radius: 8px;
  background: rgba(240, 185, 90, 0.1);
  color: #f4c97a;
  font-weight: 800;
}

.test-exit {
  min-height: 44px;
  white-space: nowrap;
}

.app.test-mode .topbar {
  border-bottom-color: rgba(240, 185, 90, 0.28);
}

input,
select {
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 44px;
  padding: 10px 12px;
  outline: none;
}

.date-control {
  position: relative;
  min-width: 174px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
}

.date-control .date-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.date-control:focus-within,
input:focus,
select:focus,
button:focus-visible {
  border-color: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: 28px;
  padding: 28px;
}

.sales-area {
  min-width: 0;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 20px;
}

.product-button {
  min-height: 320px;
  padding: 18px 16px 20px;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  transition: border-color 0.16s ease, transform 0.16s ease, background 0.16s ease;
}

.product-button:hover {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.03);
}

.product-button:active {
  transform: scale(0.98);
}

.product-image-ring {
  width: min(13.5rem, 100%);
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.01) 72%);
}

.product-image-ring img {
  width: 86%;
  height: 86%;
  object-fit: contain;
  border-radius: 50%;
  filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.42));
}

.product-name {
  min-height: 4.2rem;
  font-size: 2rem;
  line-height: 1.05;
  font-weight: 800;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-divider {
  width: min(160px, 70%);
  height: 1px;
  background: var(--line);
  margin: 14px 0 10px;
  position: relative;
}

.product-divider::after {
  content: "";
  position: absolute;
  inset: -3px auto auto 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}

.product-price {
  color: #d7d7d9;
  font-size: 1.35rem;
  font-weight: 700;
}

.command-row {
  margin-top: 24px;
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 12px;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button,
.icon-button {
  min-height: 50px;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.primary-button {
  color: #0b0b0c;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 800;
}

.secondary-button:hover,
.ghost-button:hover,
.icon-button:hover {
  background: var(--panel-2);
  border-color: rgba(255, 255, 255, 0.34);
}

.danger-button {
  color: #fff;
  border-color: rgba(255, 91, 82, 0.72);
  background: rgba(255, 91, 82, 0.08);
}

.danger-button:hover {
  background: rgba(255, 91, 82, 0.16);
}

.ghost-button {
  color: var(--muted);
}

.icon-button {
  width: 44px;
  min-height: 44px;
  padding: 0;
}

.summary-panel {
  align-self: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: rgba(16, 17, 18, 0.72);
}

.summary-panel h1,
.summary-panel h2,
.modal h2 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.2;
}

.summary-list {
  margin-top: 18px;
  display: grid;
  gap: 0;
  border-top: 1px solid var(--line-soft);
}

.summary-row {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line-soft);
}

.summary-row span:first-child {
  color: var(--muted);
}

.summary-row strong {
  font-size: 1.25rem;
}

.recent {
  margin-top: 24px;
}

.recent h2 {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.operation-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}

.operation-row.voided {
  color: var(--muted);
  text-decoration: line-through;
}

.operation-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(390px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: rgba(16, 17, 18, 0.94);
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}

.login-brand {
  margin-bottom: 6px;
}

label {
  color: var(--muted);
  display: grid;
  gap: 8px;
  font-size: 0.92rem;
}

label input,
label select {
  width: 100%;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
}

.modal {
  width: min(980px, calc(100% - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.68);
}

.modal-shell {
  padding: 18px;
}

.small-modal {
  max-width: 420px;
  display: grid;
  gap: 16px;
}

#writeoffModal,
#exportModal {
  width: min(430px, calc(100% - 24px));
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(260px, 320px);
  gap: 18px;
}

.items-list {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  overflow: hidden;
}

.item-row {
  width: 100%;
  min-height: 62px;
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  cursor: pointer;
}

.item-row:hover,
.item-row.active {
  background: rgba(255, 255, 255, 0.05);
}

.item-row img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  border-radius: 50%;
}

.item-fields {
  display: grid;
  gap: 12px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.check-row input {
  width: 20px;
  min-height: 20px;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-actions .danger-button {
  grid-column: 1 / -1;
}

.export-periods {
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 10px;
}

.export-periods legend {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.export-periods label {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  cursor: pointer;
}

.export-periods input {
  width: 18px;
  min-height: 18px;
}

.export-formats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(80px);
  opacity: 0;
  max-width: min(460px, calc(100% - 24px));
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

[hidden] {
  display: none !important;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .summary-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  body {
    background: var(--bg);
  }

  .app {
    width: 100%;
    min-height: 100vh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .topbar {
    min-height: 62px;
    padding: 10px 12px;
  }

  .brand span:last-child {
    display: none;
  }

  .workspace {
    padding: 16px 12px 20px;
    gap: 16px;
  }

  .product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .product-button {
    min-height: 222px;
    padding: 12px 8px;
  }

  .product-name {
    min-height: 2.8rem;
    font-size: 1.28rem;
  }

  .product-price {
    font-size: 1rem;
  }

  .product-image-ring {
    width: min(9.4rem, 100%);
    margin-bottom: 12px;
  }

  .command-row {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .command-row button {
    min-height: 54px;
    padding: 10px;
    font-size: 0.9rem;
  }

  .summary-panel {
    padding: 16px;
  }

  .summary-list {
    grid-template-columns: repeat(2, 1fr);
    border-left: 1px solid var(--line-soft);
  }

  .summary-row {
    min-height: 74px;
    padding: 8px 10px;
    display: grid;
    align-content: center;
    border-right: 1px solid var(--line-soft);
  }

  .summary-row strong {
    font-size: 1.2rem;
  }

  .editor-layout {
    grid-template-columns: 1fr;
  }

  .modal-shell {
    padding: 14px;
  }

  .form-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 390px) {
  .date-control {
    min-width: 154px;
  }

  .command-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 340px) {
  .product-grid {
    grid-template-columns: 1fr;
  }
}

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