:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef4f7;
  --ink: #17202a;
  --muted: #65717d;
  --line: #dfe6ec;
  --teal: #20b8a9;
  --teal-dark: #0c847a;
  --coral: #ff6b5c;
  --violet: #7357ff;
  --sun: #f4b942;
  --blue: #276ef1;
  --green: #249f68;
  --danger: #cf3341;
  --shadow: 0 18px 45px rgba(26, 37, 53, 0.12);
  --radius: 8px;
  --topbar: rgba(255, 255, 255, 0.86);
  --panel-bg: rgba(255, 255, 255, 0.92);
  --card-bg: #ffffff;
  --control-bg: #ffffff;
  --soft: #eef4f7;
  --soft-hover: #dfeaf0;
  --media-bg: #e9eff3;
  --footer-bg: #fbfcfd;
  --danger-soft: #f7d8d4;
  --danger-ink: #78251f;
  --dash: #c9d4dc;
  --item-line: #edf2f5;
  --client-active-bg: #e9fbf8;
  --client-active-ink: #17202a;
  --client-active-muted: #48615d;
}

body[data-theme="dark"] {
  --bg: #101417;
  --surface: #171d21;
  --surface-2: #20282d;
  --ink: #eef4f2;
  --muted: #a7b3bc;
  --line: #2d393f;
  --teal: #36d7c8;
  --teal-dark: #53eadf;
  --coral: #ff8a78;
  --violet: #a996ff;
  --sun: #f7c65d;
  --blue: #6ea8ff;
  --green: #43bd86;
  --danger: #ff6f7d;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.38);
  --topbar: rgba(18, 24, 28, 0.9);
  --panel-bg: rgba(24, 31, 36, 0.94);
  --card-bg: #182025;
  --control-bg: #12181c;
  --soft: #222e34;
  --soft-hover: #2b3940;
  --media-bg: #202b31;
  --footer-bg: #141b1f;
  --danger-soft: #4b2222;
  --danger-ink: #ffd1ca;
  --dash: #41515a;
  --item-line: #26343a;
  --client-active-bg: #143f3b;
  --client-active-ink: #f3fffc;
  --client-active-muted: #bdeee8;
}

* {
  box-sizing: border-box;
}

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

html {
  touch-action: manipulation;
}

body {
  margin: 0;
  background:
    linear-gradient(120deg, rgba(32, 184, 169, 0.12), transparent 38%),
    linear-gradient(300deg, rgba(255, 107, 92, 0.11), transparent 34%),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body[data-theme="dark"] {
  background:
    linear-gradient(120deg, rgba(54, 215, 200, 0.11), transparent 38%),
    linear-gradient(300deg, rgba(255, 138, 120, 0.1), transparent 34%),
    var(--bg);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

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

.login-box {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.login-top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 28px;
  background: linear-gradient(135deg, #17202a, #263b4c);
  color: #fff;
}

.logo-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--teal), var(--sun));
  color: #101820;
  font-size: 28px;
  font-weight: 900;
}

.logo-image {
  width: 68px;
  background: transparent;
  padding: 0;
  border: 0;
  box-shadow: none;
}

.logo-image img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.login-title {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

.login-top .logo-image img {
  filter: invert(1);
}

.login-subtitle {
  margin: 6px 0 0;
  color: rgba(255, 255, 255, 0.74);
  font-size: 14px;
}

.pin-panel {
  padding: 24px;
}

.login-users {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 18px;
}

.login-user {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.login-user.active {
  border-color: var(--teal);
  background: #dff8f4;
  color: #064b46;
}

body[data-theme="dark"] .login-user.active {
  background: rgba(54, 215, 200, 0.18);
  color: #c8fff9;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 20px;
}

.pin-dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid #bac6d0;
  background: transparent;
}

.pin-dot.filled {
  border-color: var(--teal-dark);
  background: var(--teal);
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr));
  gap: 10px;
}

.pin-button {
  min-height: 64px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--ink);
  font-size: 23px;
  font-weight: 800;
  cursor: pointer;
}

.pin-button:hover {
  background: var(--soft-hover);
}

.pin-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.pin-button.confirm {
  background: var(--teal);
  color: #06211e;
}

.pin-button.clear {
  background: var(--danger-soft);
  color: var(--danger-ink);
}

.login-error {
  min-height: 22px;
  margin-top: 14px;
  color: var(--danger);
  text-align: center;
  font-weight: 700;
}

.app {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px clamp(16px, 4vw, 42px);
  background: var(--topbar);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand .logo-mark {
  width: 44px;
  height: 44px;
  font-size: 22px;
}

.brand .logo-image {
  width: 62px;
  height: 46px;
}

body[data-theme="dark"] .brand .logo-image img {
  filter: invert(1);
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.tabs-wrap {
  padding: 16px clamp(16px, 4vw, 42px) 0;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.tab {
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}

.tab.active {
  background: #17202a;
  color: #fff;
  border-color: #17202a;
}

.tab-count {
  display: inline-grid;
  min-width: 26px;
  height: 26px;
  place-items: center;
  margin-left: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  color: inherit;
  font-size: 13px;
}

.main {
  padding: 18px clamp(16px, 4vw, 42px) 42px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(26, 37, 53, 0.07);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2,
.panel-title {
  margin: 0;
  font-size: 18px;
}

.panel-head small,
.muted {
  color: var(--muted);
}

.panel-body {
  padding: 16px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.field label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 800;
}

.input,
.textarea,
.select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--control-bg);
  color: var(--ink);
  outline: none;
}

.textarea {
  min-height: 94px;
  resize: vertical;
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(32, 184, 169, 0.16);
}

.client-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 300px);
  min-height: 280px;
  overflow: auto;
  padding-right: 2px;
}

.client-row {
  width: 100%;
  display: grid;
  gap: 3px;
  min-height: 68px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.client-row strong {
  font-size: 15px;
}

.client-row span {
  color: var(--muted);
  font-size: 13px;
}

.client-row.active {
  border-color: var(--teal);
  background: var(--client-active-bg);
  color: var(--client-active-ink);
  box-shadow: inset 5px 0 0 var(--teal);
}

.client-row.active span {
  color: var(--client-active-muted);
}

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

.selected-client {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(32, 184, 169, 0.16), rgba(244, 185, 66, 0.1));
}

.selected-client strong {
  display: block;
  font-size: 17px;
}

.selected-client span {
  color: var(--muted);
  font-size: 13px;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.product-tile {
  display: grid;
  grid-template-rows: 190px auto;
  min-height: 336px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-bg);
  overflow: hidden;
}

.product-tile.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(32, 184, 169, 0.13);
}

.product-media,
.image-preview,
.product-thumb {
  background: var(--media-bg);
  overflow: hidden;
}

.product-media img,
.image-preview img,
.product-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.product-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: #101820;
  font-size: 44px;
  font-weight: 900;
}

.product-content {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  padding: 14px;
}

.product-name {
  margin: 0;
  min-height: 48px;
  font-size: 18px;
  line-height: 1.25;
}

.product-meta {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.qty-controls {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  gap: 8px;
  align-items: center;
}

.icon-btn,
.qty-btn {
  min-width: 48px;
  min-height: 48px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.qty-btn.plus {
  background: var(--teal);
  color: #06211e;
}

.qty-btn.minus {
  background: var(--danger-soft);
  color: var(--danger-ink);
}

.qty {
  min-height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 24px;
  font-weight: 900;
  background: var(--control-bg);
}

.order-footer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: end;
  padding: 16px;
  border-top: 1px solid var(--line);
  background: var(--footer-bg);
}

.summary-line {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--ink);
  font-weight: 800;
  font-size: 13px;
}

.pill.teal {
  background: #dff8f4;
  color: #064b46;
}

.pill.coral {
  background: #ffe4df;
  color: #83281f;
}

.pill.violet {
  background: #ebe7ff;
  color: #342178;
}

body[data-theme="dark"] .pill.teal {
  background: rgba(54, 215, 200, 0.18);
  color: #c8fff9;
}

body[data-theme="dark"] .pill.coral {
  background: rgba(255, 138, 120, 0.18);
  color: #ffd9d2;
}

body[data-theme="dark"] .pill.violet {
  background: rgba(169, 150, 255, 0.2);
  color: #efeaff;
}

.payment-toggle,
.shipping-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.shipping-toggle {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.segment {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control-bg);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.segment input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.segment:has(input:checked) {
  border-color: var(--violet);
  background: #ebe7ff;
  color: #302064;
}

body[data-theme="dark"] .segment:has(input:checked) {
  background: rgba(169, 150, 255, 0.22);
  color: #f0ecff;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 8px;
  background: #17202a;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  filter: brightness(0.96);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.btn.primary {
  background: var(--teal);
  color: #06211e;
}

.btn.secondary {
  background: var(--soft);
  color: var(--ink);
}

.btn.warning {
  background: var(--sun);
  color: #392607;
}

.btn.danger {
  background: var(--danger-soft);
  color: var(--danger-ink);
}

.btn.green {
  background: var(--green);
}

.danger-icon {
  background: var(--danger-soft);
  color: var(--danger-ink);
}

.empty-state {
  min-height: 260px;
  display: grid;
  place-items: center;
  padding: 26px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--dash);
  border-radius: 8px;
  background: var(--panel-bg);
}

.orders-list {
  display: grid;
  gap: 12px;
}

.order-card {
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(26, 37, 53, 0.06);
  overflow: hidden;
}

.order-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.order-card-head h3 {
  margin: 0 0 5px;
  font-size: 18px;
}

.order-date {
  color: var(--muted);
  font-size: 13px;
}

.order-items {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
}

.order-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 9px 0;
  border-bottom: 1px solid var(--item-line);
}

.order-item:last-child {
  border-bottom: 0;
}

.order-item-main {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.order-item-main span {
  display: block;
  font-weight: 900;
}

.order-item-main small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.order-item-thumb,
.production-thumb {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: var(--media-bg);
  overflow: hidden;
}

.order-item-thumb img,
.production-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.order-item-thumb .product-placeholder,
.production-thumb .product-placeholder {
  font-size: 18px;
}

.order-item strong {
  white-space: nowrap;
}

.order-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--footer-bg);
  border-top: 1px solid var(--line);
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  gap: 16px;
  align-items: start;
}

.production-list {
  display: grid;
  gap: 10px;
}

.production-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-bg);
}

.production-main {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.production-thumb {
  width: 64px;
  height: 64px;
}

.production-row h3 {
  margin: 0;
  font-size: 17px;
}

.production-row p {
  margin: 4px 0 0;
  color: var(--muted);
}

.production-row strong {
  font-size: 22px;
  white-space: nowrap;
}

.range-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
}

.stats-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-bg);
}

.stats-card h3 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 15px;
}

.stats-card strong {
  display: block;
  font-size: 28px;
  line-height: 1.15;
}

.stats-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-weight: 800;
}

.admin-full {
  grid-column: 1 / -1;
}

.settings-block {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.settings-block:first-child {
  padding-top: 0;
}

.settings-block:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.settings-block h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

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

.form-grid .wide {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.image-preview {
  width: 100%;
  aspect-ratio: 16 / 10;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.admin-list {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.admin-row {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 70px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-bg);
}

.product-thumb {
  width: 72px;
  height: 66px;
  border-radius: 8px;
}

.admin-row-title {
  font-weight: 900;
}

.admin-row-sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.user-pin-change {
  display: grid;
  grid-template-columns: minmax(120px, 150px) auto auto;
  gap: 6px;
  align-items: center;
}

.pin-change-input {
  min-height: 48px;
}

.import-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--footer-bg);
  margin: 12px 0;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(380px, calc(100vw - 36px));
  padding: 14px 16px;
  border-radius: 8px;
  background: #17202a;
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 800;
}

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

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .client-list {
    max-height: 360px;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions,
  .top-actions .btn {
    width: 100%;
  }

  .top-actions .btn {
    justify-content: center;
  }

  .main,
  .tabs-wrap {
    padding-left: 12px;
    padding-right: 12px;
  }

  .brand h1 {
    font-size: 20px;
  }

  .product-grid {
    grid-template-columns: 1fr;
  }

  .order-footer {
    grid-template-columns: 1fr;
  }

  .order-footer .btn {
    width: 100%;
  }

  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .range-toggle {
    justify-content: stretch;
  }

  .range-toggle .segment {
    flex: 1;
    justify-content: center;
  }

  .order-item {
    grid-template-columns: 1fr;
  }

  .order-item strong {
    justify-self: start;
  }

  .production-row {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .admin-row {
    grid-template-columns: 50px 1fr;
  }

  .row-actions {
    grid-column: 1 / -1;
  }

  .user-pin-change {
    grid-column: 1 / -1;
    grid-template-columns: 1fr;
  }

  .row-actions .btn,
  .row-actions .icon-btn,
  .user-pin-change .icon-btn {
    flex: 1;
    width: 100%;
  }
}
