:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --line: #e5e7eb;
  --text: #171717;
  --muted: #737373;
  --orange: #df6b28;
  --dark: #1f1f22;
  --green: #22a565;
  --red: #d83b32;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.login-screen.is-hidden { display: none; }

.login-box {
  width: min(380px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 26px;
  box-shadow: 0 18px 70px rgba(0,0,0,.08);
}

.login-box h1 {
  font-size: 22px;
  margin-bottom: 18px;
}

.login-box input,
.login-box button {
  width: 100%;
  margin-top: 10px;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 24px 18px;
}

.brand {
  color: var(--orange);
  font-weight: 800;
  font-size: 22px;
  margin-bottom: 34px;
}

.nav-btn {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font: inherit;
  font-weight: 700;
  padding: 13px 14px;
  border-radius: 8px;
  cursor: pointer;
}

.nav-btn.is-active {
  background: #fff2e9;
  color: var(--orange);
}

.app { padding: 28px; overflow: auto; }
.topbar, .actions, .toolbar, .stats { display: flex; align-items: center; gap: 12px; }
.topbar { justify-content: space-between; margin-bottom: 18px; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 28px; }

.btn, input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 42px;
  padding: 0 14px;
  font: inherit;
  background: #fff;
}

.btn {
  cursor: pointer;
  font-weight: 800;
}
.btn-dark { background: var(--dark); color: #fff; border-color: var(--dark); }
.btn-orange { background: var(--orange); color: #fff; border-color: var(--orange); }

.stats { margin-bottom: 16px; }
.stat {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 5px solid var(--orange);
  border-radius: 8px;
  padding: 16px 18px;
}
.stat span { display: block; color: var(--muted); font-size: 13px; font-weight: 700; }
.stat strong { display: block; margin-top: 4px; font-size: 28px; }

.toolbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 14px;
}
.toolbar input { flex: 1; min-width: 220px; }
.scan-box {
  flex: 0 0 300px;
  display: grid;
  grid-template-columns: 70px 1fr;
  align-items: center;
  gap: 8px;
  border: 2px solid #d8b38f;
  background: #fff6ed;
  border-radius: 10px;
  padding: 6px 8px;
}
.scan-box span {
  color: var(--orange);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}
.toolbar .barcode-input {
  min-width: 0;
  border-color: #d8b38f;
  background: #fff;
  font-weight: 800;
}
.bulk-select { min-width: 160px; }

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 12px 14px;
  border-bottom: 1px solid #f0f0f0;
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}
th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
tr:hover td { background: #fafafa; }
tr.is-issue td { background: #fff9ef; }
tr.is-issue:hover td { background: #fff3df; }

.thumb {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f2f2f2;
}
.thumb.is-broken,
.design-card img.is-broken {
  object-fit: contain;
  background:
    linear-gradient(135deg, transparent 47%, #d8d8d8 48%, #d8d8d8 52%, transparent 53%),
    linear-gradient(45deg, transparent 47%, #d8d8d8 48%, #d8d8d8 52%, transparent 53%),
    #f2f2f2;
}
.sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.badge { display: inline-flex; padding: 5px 10px; border-radius: 999px; background: #eee; font-size: 12px; font-weight: 800; }
.badge.processing { background: #fff4d6; color: #9a6500; }
.badge.completed { background: #e8f8ef; color: var(--green); }
.badge.cancelled { background: #ffeceb; color: var(--red); }
.status-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.issue-badge {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  background: #ffeceb;
  color: var(--red);
  font-size: 11px;
  font-weight: 900;
}

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.link-btn {
  border: 1px solid var(--line);
  color: var(--text);
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.empty { display: none; padding: 28px; color: var(--muted); font-weight: 700; }
.empty.is-visible { display: block; }

dialog {
  width: min(980px, calc(100vw - 32px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(0,0,0,.2);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.modal { padding: 0; }
.modal header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  font-weight: 900;
}
.modal-content { padding: 20px; display: grid; gap: 16px; }
.modal-shell {
  display: grid;
  grid-template-columns: 1fr 310px;
  gap: 18px;
  align-items: start;
}
.modal-main,
.modal-side {
  display: grid;
  gap: 14px;
}
.modal-side {
  position: sticky;
  top: 0;
  align-self: start;
}
.order-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #fafafa;
}
.action-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.whatsapp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #e8f8ef;
  color: #147a45;
  text-decoration: none;
}
.issue-panel {
  display: grid;
  gap: 4px;
  border: 1px solid #ffd1cb;
  border-left: 5px solid var(--red);
  background: #fff4f2;
  border-radius: 10px;
  padding: 12px;
}
.issue-form {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.design-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.design-card { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.design-card img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
textarea { width: 100%; min-height: 100px; padding: 12px; resize: vertical; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--dark);
  color: #fff;
  padding: 14px 18px;
  border-radius: 8px;
  font-weight: 800;
  box-shadow: 0 16px 50px rgba(0,0,0,.18);
}

@media (max-width: 860px) {
  body { grid-template-columns: 1fr; }
  .sidebar { display: flex; gap: 8px; overflow-x: auto; padding: 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { margin: 0 10px 0 0; display: flex; align-items: center; }
  .nav-btn { white-space: nowrap; width: auto; }
  .app { padding: 16px; }
  .topbar, .toolbar, .actions { align-items: stretch; flex-direction: column; }
  .actions, .toolbar input, .btn, select { width: 100%; }
  .scan-box { flex: auto; width: 100%; }
  .modal-shell { grid-template-columns: 1fr; }
  .modal-side { position: static; }
  .order-summary { grid-template-columns: 1fr; }
  table { min-width: 760px; }
  .table-wrap { overflow-x: auto; }
}
