:root {
  --bg: #f7f2ed;
  --panel: #fffaf3f2;
  --text: #3a1418;
  --muted: #7a4d37;
  --line: #e7d1bd;
  --accent: #f00000;
  --accent-strong: #c40000;
  --danger: #5a0d1d;
  --gold: #c07030;
  --cream: #f6eddc;
  --shadow: 0 14px 34px rgba(240, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Outfit", "Trebuchet MS", sans-serif;
  color: var(--text);
  background: #ffffff;
  position: relative;
  overflow-x: auto;
}

.bg-orb {
  display: none;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
}

h2 {
  font-size: 1.04rem;
}

.mt-lg {
  margin-top: 1.25rem;
}

.page {
  width: min(1220px, calc(100% - 2rem));
  margin: 1.35rem auto 2.4rem;
}

.panel {
  background: var(--panel);
  border: 1px solid #fff;
  box-shadow: var(--shadow);
  border-radius: 18px;
  padding: 1rem;
  animation: fade-up 0.42s ease both;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 700;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
}

.topbar h1 {
  font-size: clamp(1.2rem, 2.7vw, 1.8rem);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.grid {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.history-panel {
  margin-top: 1rem;
}

input,
textarea,
button {
  font: inherit;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 0.56rem 0.72rem;
}

input:focus,
textarea:focus {
  outline: 2px solid #f4b6a8;
  border-color: #d1715b;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.ghost-btn {
  background: #f4ead8;
  color: #5b2a1a;
  border: 1px solid #e4cfae;
}

.ghost-btn:hover {
  background: #efdcbc;
}

.danger-btn {
  background: var(--danger);
  color: #fff;
}

.danger-btn:hover {
  background: #430a16;
}

.badge {
  background: #fce5cf;
  color: #7b3d20;
  padding: 0.3rem 0.66rem;
  border-radius: 999px;
  font-size: 0.84rem;
}

.muted {
  color: var(--muted);
  margin: 0;
  font-size: 0.9rem;
}

.center {
  text-align: center;
}

.hidden {
  display: none !important;
}

.supplier-list {
  margin-top: 0.7rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.supplier-btn {
  background: #fff4ea;
  color: #5f2b18;
  border: 1px solid #efcda9;
  padding: 0.5rem 0.72rem;
}

.supplier-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.search-wrap {
  margin-top: 0.5rem;
  position: relative;
}

.search-wrap input {
  width: 100%;
}

.suggestions {
  margin-top: 0.35rem;
  border-radius: 12px;
  max-height: 220px;
  overflow-y: auto;
  display: grid;
  gap: 0.35rem;
}

.suggestion-btn {
  text-align: left;
  background: #fff;
  color: var(--text);
  border: 1px solid #e8d4be;
}

.suggestion-btn:hover {
  background: #fff1e4;
  color: var(--text);
}

.table-wrap {
  margin-top: 0.6rem;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 0.52rem 0.35rem;
  border-bottom: 1px solid #f0e2d3;
  font-size: 0.9rem;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
}

td input {
  width: 100%;
}

.line-invalid input[data-action="qty"] {
  border-color: #f00000;
  background: #fff0f0;
}

.remove-btn {
  background: var(--danger);
  font-size: 0.79rem;
  padding: 0.35rem 0.56rem;
}

.order-form {
  margin-top: 0.8rem;
  display: grid;
  gap: 0.6rem;
}

.order-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.order-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
}

.order-actions-right {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.preview {
  min-height: 420px;
  border: 1px solid #ead7c5;
  border-radius: 14px;
  padding: 0.72rem;
  background: #fff6f5;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.preview-doc {
  width: min(100%, 560px);
  min-height: auto;
  margin: 0 auto;
  background: #fff;
  border: 1px solid #f2c0bd;
  border-radius: 14px;
  padding: 0.25in 0.24in;
  display: grid;
  gap: 0.14in;
  box-shadow: 0 10px 24px rgba(117, 29, 34, 0.08);
}

.preview-top {
  display: grid;
  grid-template-columns: 1fr auto 92px;
  align-items: center;
  gap: 0.7rem;
}

.preview-ticket {
  background: #ee2524;
  color: #fff;
  border-radius: 14px;
  padding: 0.58rem 0.72rem;
  font-size: 0.78rem;
}

.preview-ticket p {
  margin: 0.16rem 0;
}

.preview-form-title {
  margin: 0;
  text-align: center;
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(1.55rem, 2.4vw, 2rem);
  line-height: 1.02;
  color: #1f1516;
}

.preview-form-logo {
  width: 92px;
  height: 92px;
  object-fit: cover;
  border-radius: 999px;
  border: 1px solid #efb3b3;
}

.preview-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.56rem;
}

.preview-card {
  border: 1px solid #ea8f8f;
  border-radius: 14px;
  padding: 0.62rem 0.72rem;
  background: #fff;
}

.preview-card h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: #561414;
}

.preview-card p {
  margin: 0;
  font-size: 0.86rem;
  color: #553326;
  line-height: 1.4;
}

.preview-table-wrap {
  border: 1px solid #ea8f8f;
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
}

.preview-table th {
  background: #fff3f3;
  color: #4a1717;
  border-bottom: 1px solid #ea8f8f;
  font-size: 0.9rem;
}

.preview-table td {
  border-bottom: 1px solid #f1c9c9;
  font-size: 0.88rem;
  min-height: 30px;
}

.preview-notes-box {
  border: 1px solid #ea8f8f;
  border-radius: 14px;
  padding: 0.62rem 0.72rem;
  background: #fff;
}

.preview-notes-box h4 {
  margin: 0 0 0.25rem;
  color: #5a1414;
  font-size: 0.94rem;
}

.preview-notes-box p {
  margin: 0;
  font-size: 0.87rem;
  color: #402121;
  line-height: 1.45;
}

.history-list {
  margin-top: 0.6rem;
  display: grid;
  gap: 0.55rem;
}

.history-item {
  border: 1px solid #ebdac9;
  border-radius: 12px;
  background: #fff;
  padding: 0.65rem 0.72rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.7rem;
  align-items: center;
}

.history-item p {
  margin: 0.12rem 0;
  font-size: 0.9rem;
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem;
  align-items: center;
}

.action-btn {
  padding: 0.4rem 0.56rem;
  border-radius: 10px;
  font-size: 0.78rem;
}

.export-dropdown {
  position: relative;
}

.export-dropdown summary {
  list-style: none;
}

.export-dropdown summary::-webkit-details-marker {
  display: none;
}

.export-dropdown-menu {
  position: absolute;
  top: calc(100% + 0.3rem);
  right: 0;
  width: 130px;
  display: grid;
  gap: 0.32rem;
  padding: 0.4rem;
  background: #fff;
  border: 1px solid #ead7c5;
  border-radius: 10px;
  box-shadow: 0 10px 20px rgba(40, 25, 20, 0.12);
  z-index: 4;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(19, 10, 10, 0.56);
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-panel {
  width: min(980px, 100%);
  max-height: min(88vh, 840px);
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  border: 1px solid #f0dbd9;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
  padding: 0.92rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
}

.modal-header h2 {
  font-size: 1.04rem;
}

.flash {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  padding: 0.75rem 0.95rem;
  border-radius: 10px;
  background: #3b0d14;
  color: #fff;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.flash.show {
  opacity: 1;
  transform: translateY(0);
}

.flash.error {
  background: #b50f22;
}

.login-screen {
  background:
    radial-gradient(circle at 20% 15%, #a015236b 0%, transparent 45%),
    radial-gradient(circle at 80% 90%, #c0703060 0%, transparent 45%),
    linear-gradient(145deg, #4f0e1c 0%, #7b1221 45%, #3e0b18 100%);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.glass-card {
  width: min(360px, 100%);
  border-radius: 44px;
  padding: 1.9rem 1.5rem 1.3rem;
  background: linear-gradient(145deg, #fff8ef4e 0%, #f7dfc35e 100%);
  border: 1px solid #ffffff4a;
  backdrop-filter: blur(8px);
  box-shadow: 0 24px 80px #3f0f1880;
}

.avatar-wrap {
  display: grid;
  place-items: center;
  margin-bottom: 0.9rem;
}

.avatar-circle {
  width: 90px;
  height: 90px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #ffffff;
  overflow: hidden;
  border: 2px solid #f4dcc3;
}

.avatar-logo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.login-error {
  margin: 0 0 0.8rem;
  background: #ffe1de;
  color: #8f1c20;
  border: 1px solid #f8b5b2;
  border-radius: 10px;
  padding: 0.55rem 0.68rem;
  font-size: 0.85rem;
}

.login-form {
  display: grid;
  gap: 1rem;
}

.line-field {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.58rem;
  border-bottom: 1px solid #fff5e2c2;
  padding-bottom: 0.28rem;
}

.password-field {
  grid-template-columns: auto 1fr auto;
}

.field-icon {
  color: #fff4df;
  opacity: 0.96;
  display: inline-flex;
}

.login-screen .line-field input {
  border: none;
  border-radius: 0;
  background: transparent;
  color: #fff6ec;
  padding: 0.28rem 0;
  font-size: 1rem;
}

.login-screen .line-field input::placeholder {
  color: #fff0d8bf;
}

.login-screen .line-field input:focus {
  outline: none;
  border: none;
}

.toggle-password {
  background: transparent;
  border: none;
  color: #fff4df;
  padding: 0.15rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.toggle-password:hover {
  transform: none;
  background: transparent;
}

.login-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  color: #fff0d8e8;
  font-size: 0.78rem;
}

.remember-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.34rem;
}

.remember-wrap input {
  accent-color: #5a0d1d;
  width: 13px;
  height: 13px;
}

.forgot-text {
  opacity: 0.9;
}

.login-btn {
  width: 100%;
  border-radius: 14px;
  padding: 0.72rem 0.9rem;
  letter-spacing: 0.12em;
  font-weight: 700;
  background: linear-gradient(90deg, #f00000 0%, #5a0d1d 100%);
  box-shadow: 0 12px 30px #3f0f188c;
}

.login-btn:hover {
  background: linear-gradient(90deg, #d50000 0%, #4c0a17 100%);
}

.credential-hint {
  margin: 0.9rem 0 0;
  color: #fff6e5;
  text-align: center;
  font-size: 0.8rem;
}

@keyframes drift {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-16px);
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

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

  .order-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .order-actions-right {
    width: 100%;
    justify-content: flex-end;
  }

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

  .history-actions {
    justify-content: flex-start;
  }

  .preview-cards {
    grid-template-columns: 1fr;
  }

  .preview-top {
    grid-template-columns: 1fr;
    justify-items: flex-start;
  }
}

@media (max-width: 700px) {
  .bg-orb {
    display: none;
  }

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

  .page {
    width: calc(100% - 1rem);
    margin: 0.75rem auto 1.2rem;
  }

  .panel {
    border-radius: 14px;
    padding: 0.8rem;
  }

  .topbar {
    gap: 0.65rem;
  }

  .topbar h1 {
    font-size: 1.12rem;
    line-height: 1.25;
  }

  .topbar-right,
  .topbar-right form {
    width: 100%;
  }

  .topbar-right button {
    width: 100%;
  }

  .supplier-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
  }

  .supplier-btn {
    width: 100%;
    text-align: center;
    padding: 0.62rem 0.56rem;
  }

  .suggestions {
    max-height: 180px;
  }

  .order-actions {
    align-items: stretch;
  }

  .order-actions-right {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
  }

  .order-actions-right button {
    width: 100%;
  }

  .badge {
    align-self: flex-start;
  }

  .preview {
    min-height: 0;
    padding: 0.62rem;
  }

  .preview-doc {
    width: 100%;
    min-height: auto;
    padding: 0.55rem;
  }

  .preview-form-title {
    text-align: left;
    font-size: 1.38rem;
  }

  .preview-form-logo {
    width: 72px;
    height: 72px;
  }

  .order-lines-table thead,
  .preview-table thead {
    display: none;
  }

  .order-lines-table,
  .order-lines-table tbody,
  .order-lines-table tr,
  .order-lines-table td,
  .preview-table,
  .preview-table tbody,
  .preview-table tr,
  .preview-table td {
    display: block;
    width: 100%;
  }

  .order-lines-table tr,
  .preview-table tr {
    border: 1px solid #ebdac9;
    border-radius: 12px;
    background: #fff;
    margin-bottom: 0.58rem;
    padding: 0.56rem 0.62rem;
    box-shadow: 0 2px 10px rgba(70, 25, 20, 0.05);
  }

  .order-lines-table td,
  .preview-table td {
    border: none;
    padding: 0.15rem 0;
    font-size: 0.9rem;
  }

  .order-lines-table td::before,
  .preview-table td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #85503c;
    margin-bottom: 0.1rem;
  }

  .order-lines-table tr.empty-row,
  .preview-table tr.empty-row {
    border: none;
    box-shadow: none;
    padding: 0.12rem 0;
    background: transparent;
  }

  .order-lines-table tr.empty-row td::before,
  .preview-table tr.empty-row td::before {
    content: none;
  }

  .order-lines-table input {
    min-height: 40px;
  }

  .remove-btn {
    width: 100%;
    margin-top: 0.18rem;
  }

  .history-item {
    padding: 0.62rem;
    gap: 0.55rem;
  }

  .history-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.42rem;
  }

  .history-actions .action-btn {
    width: 100%;
    min-height: 38px;
    text-align: center;
  }

  .flash {
    right: 0.5rem;
    left: 0.5rem;
    bottom: 0.75rem;
    width: auto;
    font-size: 0.9rem;
  }

  .login-shell {
    padding: 1rem;
  }

  .glass-card {
    width: min(430px, 100%);
    border-radius: 30px;
    padding: 1.5rem 1.1rem 1.1rem;
  }

  .avatar-circle {
    width: 84px;
    height: 84px;
  }

  .login-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }
}

@media (max-width: 460px) {
  .supplier-list {
    grid-template-columns: 1fr;
  }

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

  .preview-card p {
    font-size: 0.8rem;
  }

  .order-lines-table td::before,
  .preview-table td::before {
    font-size: 0.68rem;
  }
}
