:root {
  --bg: #f7f4ef;
  --bg-soft: #ece5d9;
  --surface: #fffdf9;
  --ink: #231f1a;
  --muted: #655b4f;
  --line: #d4c8b7;
  --primary: #005f4a;
  --primary-2: #004536;
  --accent: #c5522e;
  --danger: #8f2e22;
  --ring: rgba(0, 95, 74, 0.2);
  --ok: #2f7a46;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 8% -2%, #e8dcc7 0%, transparent 34%),
    radial-gradient(circle at 92% 0%, #e3ede9 0%, transparent 28%),
    linear-gradient(165deg, var(--bg), var(--bg-soft));
  min-height: 100vh;
}

.app-shell {
  width: min(1180px, 94vw);
  margin: 1.2rem auto 2rem;
  display: grid;
  gap: 0.9rem;
}

.topbar {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(246, 241, 232, 0.8));
  padding: 0.9rem 1.05rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  box-shadow: 0 10px 26px rgba(24, 22, 18, 0.08);
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.45rem, 2vw + 0.7rem, 2rem);
  letter-spacing: 0.02em;
}

.brand p {
  margin: 0.22rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.session {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.debug-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
  background: #f7f1e6;
}

.debug-toggle input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.62rem;
  background: #f4efe5;
  color: var(--muted);
  font-size: 0.86rem;
}

.panel {
  display: grid;
  gap: 0.8rem;
}

body.aqcms-authenticated #loginPanel {
  display: none !important;
}

body.aqcms-authenticated #appPanel {
  display: grid !important;
}

body.aqcms-hide-debug .submenu-line {
  display: none !important;
}

body.aqcms-hide-debug .status-view {
  display: none !important;
}

.card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  padding: 0.95rem 1rem 1.05rem;
  box-shadow: 0 10px 24px rgba(22, 19, 15, 0.06);
}

.card h2 {
  margin: 0.12rem 0 0.72rem;
  font-size: 1.16rem;
}

.menu-wrap {
  display: grid;
  gap: 0.66rem;
}

.menu-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

.menu,
.submenu {
  display: flex;
  flex-wrap: wrap;
  gap: 0.44rem;
}

button.menu-btn,
button.submenu-btn {
  border: 1px solid #d8ccb8;
  border-radius: 999px;
  padding: 0.4rem 0.82rem;
  color: var(--ink);
  background: linear-gradient(180deg, #fff9f0 0%, #efe3cf 100%);
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset, 0 1px 1px rgba(33, 26, 17, 0.08);
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease, box-shadow 0.14s ease;
}

button.menu-btn:hover,
button.submenu-btn:hover {
  transform: translateY(-1px);
}

button.menu-btn.active,
button.submenu-btn.active {
  border-color: #0b6b54;
  background: linear-gradient(180deg, #2a8b74 0%, #0d6a55 100%);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 1px 3px rgba(0, 0, 0, 0.14);
}

.submenu-line {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--muted);
}

.picker {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.picker label {
  font-size: 0.86rem;
  color: var(--muted);
}

.cards-grid {
  display: grid;
  gap: 0.8rem;
}

.form-grid {
  display: grid;
  gap: 0.65rem;
}

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

label {
  display: grid;
  gap: 0.32rem;
  color: var(--muted);
  font-size: 0.86rem;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.52rem 0.65rem;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--ring);
  border-color: var(--primary);
}

textarea {
  resize: vertical;
}

button {
  border: 1px solid #0b6b54;
  border-radius: 999px;
  background: linear-gradient(180deg, #2a8b74 0%, #0d6a55 100%);
  color: #fff;
  padding: 0.46rem 0.9rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.24) inset, 0 1px 2px rgba(0, 0, 0, 0.14);
  cursor: pointer;
}

button:hover {
  background: linear-gradient(180deg, #32987e 0%, #106f58 100%);
}

button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.14) inset;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  filter: grayscale(0.15);
}

button.danger {
  border-color: #8f2e22;
  background: linear-gradient(180deg, #b24535 0%, #8f2e22 100%);
}

button.danger:hover {
  background: linear-gradient(180deg, #be4f3f 0%, #9a3427 100%);
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.48rem;
  flex-wrap: wrap;
}

.actions label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.actions label input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.align-end {
  align-items: end;
}

.span-2 {
  grid-column: span 2;
}

.wide-label {
  display: grid;
  gap: 0.33rem;
}

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

.status-view {
  margin: 0;
  border: 1px solid #d9d2c4;
  border-radius: 10px;
  background: #f7f3ea;
  padding: 0.6rem 0.68rem;
  font-family: "IBM Plex Mono", "Consolas", monospace;
  font-size: 0.82rem;
  max-height: 260px;
  overflow: auto;
}

.status-view.compact {
  max-height: 180px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.55rem;
}

.meta-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(145deg, #fff, #f4ece0);
  padding: 0.52rem 0.6rem;
}

.meta-item strong {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.meta-item span {
  display: block;
  margin-top: 0.2rem;
}

.user-list {
  margin: 0 0 0.7rem;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.45rem;
}

.user-list li {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.48rem 0.6rem;
  background: #fcfaf5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
}

.user-list em {
  color: var(--muted);
  font-style: normal;
  font-size: 0.82rem;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 0.48rem 0.45rem;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #f6f0e5;
}

.data-table td:last-child {
  white-space: nowrap;
}

.order-create-wrap {
  margin-top: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.78rem;
  background: #faf5ea;
  display: grid;
  gap: 0.6rem;
}

.order-create-wrap h3 {
  margin: 0;
}

.order-items-list {
  display: grid;
  gap: 0.45rem;
}

.order-item-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0.45rem 0.5rem;
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(110px, 0.9fr) minmax(100px, 0.8fr) minmax(100px, 0.8fr);
  gap: 0.45rem;
  align-items: center;
}

.order-item-meta strong {
  display: block;
}

.order-item-meta span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.order-item-row input[type="number"] {
  width: 100%;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-line input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
}

.orders-cards {
  display: grid;
  gap: 0.65rem;
  margin-top: 0.7rem;
}

.tab-bar {
  display: flex;
  gap: 0.45rem;
  margin-bottom: 0.45rem;
}

.tab-btn {
  border: 1px solid #d8ccb8;
  background: linear-gradient(180deg, #fff9f0 0%, #efe3cf 100%);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.36rem 0.86rem;
  font-size: 0.83rem;
  font-weight: 700;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset, 0 1px 1px rgba(33, 26, 17, 0.08);
  cursor: pointer;
}

.tab-btn.active {
  background: linear-gradient(180deg, #2a8b74 0%, #0d6a55 100%);
  border-color: #0b6b54;
  color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 1px 3px rgba(0, 0, 0, 0.14);
}

.order-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 0.56rem 0.62rem;
  display: grid;
  gap: 0.42rem;
}

.order-card-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(220px, 0.95fr);
  gap: 0.6rem;
  align-items: start;
}

.order-card-left,
.order-card-right {
  display: grid;
  gap: 0.38rem;
  border: 1px solid rgba(120, 103, 78, 0.22);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.82);
  padding: 0.48rem 0.54rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.86) inset;
}

.order-card-right {
  align-content: start;
}

.order-card-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: space-between;
  align-items: center;
}

.order-card-title {
  font-weight: 700;
}

.order-card-meta {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.order-items-title {
  color: #4f4538;
  font-size: 0.79rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.order-items-mini {
  margin: 0;
  padding-left: 0.94rem;
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.35;
}

.order-items-mini li + li {
  margin-top: 0.15rem;
}

.order-invoice-wrap {
  display: grid;
  gap: 0.35rem;
}

.order-invoice-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  color: #554b3f;
}

.order-invoice-table th,
.order-invoice-table td {
  padding: 0.26rem 0.22rem;
  border-bottom: 1px solid rgba(124, 107, 83, 0.18);
  text-align: left;
  vertical-align: top;
}

.order-invoice-table th {
  font-size: 0.71rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #776552;
}

.order-invoice-table td.num,
.order-invoice-table th:nth-child(2),
.order-invoice-table th:nth-child(3),
.order-invoice-table th:nth-child(4) {
  text-align: right;
  white-space: nowrap;
}

.order-invoice-table th.line-action,
.order-invoice-table td.line-action {
  text-align: center;
  width: 2rem;
  white-space: nowrap;
}

.line-refresh-btn {
  width: 1.5rem;
  height: 1.5rem;
  min-width: 1.5rem;
  border-radius: 999px;
  padding: 0;
  font-size: 0.8rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.order-invoice-table td.empty {
  text-align: center;
  color: #7b6a58;
  font-style: italic;
}

.order-invoice-summary {
  margin-top: 0.2rem;
  border-top: 1px solid rgba(124, 107, 83, 0.24);
  padding-top: 0.28rem;
  display: grid;
  gap: 0.12rem;
}

.order-invoice-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  color: #6a5b4a;
  font-size: 0.78rem;
}

.order-invoice-summary-row.total {
  margin-top: 0.08rem;
  font-size: 0.84rem;
  color: #3c3126;
  display: grid;
  grid-template-columns: minmax(46px, auto) minmax(120px, 1fr) auto;
  align-items: center;
  gap: 0.45rem;
}

.order-total-label {
  font-weight: 700;
}

.order-total-amount {
  color: #b12222;
  font-size: 0.9rem;
  font-weight: 800;
}

.price-state-slot {
  display: inline-flex;
  align-items: center;
  justify-self: center;
}

.price-state-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.12rem 0.56rem;
  font-size: 0.67rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}

.price-state-badge.unconfirmed {
  color: #8f2e22;
  border-color: #e6a69c;
  background: #fdecea;
}

.price-state-badge.confirmed {
  color: #17652f;
  border-color: #9ed3ad;
  background: #e8f7ec;
}

.price-state-badge.accepted {
  color: #0f5f2a;
  border-color: #82c197;
  background: #dff2e4;
}

button.price-state-badge {
  background: #fdecea;
  box-shadow: none;
  border-width: 1px;
  min-height: 1.48rem;
  padding: 0.12rem 0.56rem;
}

button.price-state-badge:hover {
  transform: none;
  filter: brightness(0.98);
}

button.price-state-badge:active {
  transform: none;
  box-shadow: none;
}

.accept-action-row {
  justify-content: flex-end;
}

.accept-price-btn {
  font-size: 0.72rem;
  padding: 0.24rem 0.68rem;
}

.order-card-focus {
  border-color: #0c7d63;
  box-shadow: 0 0 0 2px rgba(12, 125, 99, 0.16);
}

.order-progress {
  display: grid;
  gap: 0.28rem;
}

.order-progress-label {
  color: var(--muted);
  font-size: 0.82rem;
}

.order-progress-track {
  position: relative;
  width: 100%;
  height: 0.64rem;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #f1e9da;
}

.order-progress-track.editable {
  cursor: pointer;
}

.order-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(90deg, #b66f19 0%, #c47c22 100%);
}

.order-notify-line {
  color: var(--muted);
  font-size: 0.82rem;
}

.order-card.deadline-green {
  background: #f0fbf2;
  border-color: #b9e5c2;
}

.order-card.deadline-yellow {
  background: #fff9e8;
  border-color: #f2de9a;
}

.order-card.deadline-red {
  background: #fff1ef;
  border-color: #efc1ba;
}

@media (max-width: 900px) {
  .two-col {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  .menu-line {
    align-items: start;
    flex-direction: column;
  }

  .session {
    width: 100%;
    justify-content: flex-start;
  }

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

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

  .order-card-right {
    padding-top: 0;
  }

  .order-invoice-summary-row.total {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .price-state-slot {
    justify-self: start;
  }

  .order-total-amount {
    justify-self: start;
  }
}
