:root {
  color-scheme: light;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #dbeafe;
  --ink: #172033;
  --muted: #687385;
  --faint: #98a2b3;
  --line: #e7ebf2;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-solid: #ffffff;
  --surface-muted: #f6f8fc;
  --sidebar: rgba(255, 255, 255, 0.76);
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #16a34a;
  --shadow: 0 24px 70px rgba(61, 75, 106, 0.14);
  --radius: 28px;
  --sidebar-width: 248px;
  font-family: "Noto Sans Thai", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --accent: #60a5fa;
  --accent-strong: #3b82f6;
  --accent-soft: rgba(96, 165, 250, 0.17);
  --ink: #f8fafc;
  --muted: #b8c1ce;
  --faint: #8291a4;
  --line: rgba(226, 232, 240, 0.12);
  --surface: rgba(18, 24, 37, 0.84);
  --surface-solid: #111827;
  --surface-muted: #0c1220;
  --sidebar: rgba(13, 18, 30, 0.80);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 14%, rgba(59, 130, 246, 0.18), transparent 34rem),
    radial-gradient(circle at 20% 38%, rgba(244, 114, 182, 0.15), transparent 28rem),
    linear-gradient(110deg, #eef6ff 0%, #f8f9ff 42%, #f3efff 100%);
}

html[data-theme="dark"] body {
  background:
    radial-gradient(circle at 8% 16%, rgba(37, 99, 235, 0.20), transparent 34rem),
    radial-gradient(circle at 24% 42%, rgba(168, 85, 247, 0.13), transparent 28rem),
    linear-gradient(115deg, #060913 0%, #0b1020 56%, #111827 100%);
}

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

button {
  cursor: pointer;
}

.is-hidden {
  display: none !important;
}

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

.boot-card {
  min-width: min(360px, 100%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.boot-card img {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  object-fit: cover;
}

.boot-card strong,
.boot-card span {
  display: block;
}

.boot-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 460px) minmax(420px, 1fr);
  align-items: center;
  gap: 48px;
  padding: clamp(24px, 5vw, 72px);
}

.login-panel,
.login-preview,
.metric-card,
.panel,
.filter-card,
.placeholder-card {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

html[data-theme="dark"] .login-panel,
html[data-theme="dark"] .login-preview,
html[data-theme="dark"] .metric-card,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .filter-card,
html[data-theme="dark"] .placeholder-card {
  border-color: rgba(255, 255, 255, 0.08);
}

.login-panel {
  border-radius: var(--radius);
  padding: 34px;
}

.login-brand,
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.login-brand img,
.sidebar-brand img {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  object-fit: cover;
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.18);
}

.login-brand strong,
.sidebar-brand strong {
  display: block;
  font-size: 16px;
  line-height: 1.2;
}

.login-brand span,
.sidebar-brand span {
  color: var(--muted);
  font-size: 13px;
}

.login-copy {
  padding: 40px 0 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.login-copy h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.05;
  letter-spacing: 0;
}

.login-copy p:last-child {
  margin: 16px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.login-form input,
.date-input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid var(--line);
  border-radius: 16px;
  outline: none;
}

html[data-theme="dark"] .login-form input,
html[data-theme="dark"] .date-input {
  background: rgba(15, 23, 42, 0.74);
}

.login-form input:focus,
.date-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.primary-button,
.action-button {
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 20px;
  color: #ffffff;
  background: linear-gradient(135deg, #0ea5e9, #2563eb 58%, #4f46e5);
  border: 0;
  border-radius: 16px;
  box-shadow: 0 16px 30px rgba(37, 99, 235, 0.30);
  font-weight: 800;
}

.action-button.dark {
  background: #172033;
  box-shadow: none;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.form-message {
  min-height: 24px;
  margin: 0;
  color: var(--danger);
  font-weight: 700;
}

.login-preview {
  min-height: 520px;
  border-radius: 34px;
  padding: 42px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: center;
  gap: 18px;
}

.preview-card {
  min-height: 138px;
  padding: 24px;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 24px;
}

.preview-card.wide {
  grid-column: span 2;
}

.preview-card span {
  color: var(--muted);
  font-weight: 700;
}

.preview-card strong {
  display: block;
  margin-top: 18px;
  font-size: 48px;
  line-height: 1;
}

.preview-table {
  grid-column: span 2;
  padding: 18px;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 24px;
  display: grid;
  gap: 12px;
}

.preview-table div {
  height: 26px;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--surface-muted), var(--accent-soft));
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: var(--sidebar);
  border-right: 1px solid rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(24px);
  overflow-y: auto;
}

html[data-theme="dark"] .sidebar {
  border-right-color: rgba(255, 255, 255, 0.08);
}

.sidebar-tools {
  position: absolute;
  top: 22px;
  right: 16px;
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  color: var(--ink);
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 24px rgba(71, 85, 105, 0.09);
}

.sidebar-nav {
  display: grid;
  gap: 12px;
  margin-top: 44px;
  padding-bottom: 24px;
}

.nav-group {
  display: grid;
  gap: 6px;
}

.nav-group p {
  margin: 12px 6px 6px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 800;
}

.nav-item {
  width: 100%;
  min-height: 40px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 12px;
  padding: 0 12px;
  text-align: left;
  font-weight: 800;
  font-size: 14px;
}

.nav-item i {
  text-align: center;
  color: currentColor;
}

.nav-item:hover,
.nav-item.is-active {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
}

html[data-theme="dark"] .nav-item:hover,
html[data-theme="dark"] .nav-item.is-active {
  background: rgba(255, 255, 255, 0.08);
}

.nav-item.is-active {
  color: #ffffff;
  background: linear-gradient(135deg, #0ea5e9, #2563eb 58%, #4f46e5);
  box-shadow: 0 14px 28px rgba(37, 99, 235, 0.22);
}

.nav-item.danger {
  color: var(--danger);
}

.page-shell {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  height: 82px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 clamp(22px, 4vw, 56px);
  background: rgba(255, 255, 255, 0.70);
  border-bottom: 1px solid rgba(226, 232, 240, 0.60);
  backdrop-filter: blur(22px);
}

html[data-theme="dark"] .topbar {
  background: rgba(10, 15, 26, 0.74);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.topbar h1,
.topbar p {
  margin: 0;
}

.topbar h1 {
  font-size: 22px;
  line-height: 1.2;
}

.topbar p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.topbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.connection-pill {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  color: var(--success);
  background: rgba(22, 163, 74, 0.12);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.connection-pill.offline {
  color: var(--warning);
  background: rgba(245, 158, 11, 0.14);
}

.user-chip {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.user-chip span {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: #172033;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 900;
}

.user-chip strong,
.user-chip small {
  display: block;
  line-height: 1.15;
}

.user-chip small {
  color: var(--muted);
}

.content {
  padding: 34px clamp(22px, 4vw, 56px) 56px;
}

.filter-card {
  width: min(100%, 1340px);
  margin: 0 auto 30px;
  border-radius: var(--radius);
  padding: 28px;
}

.filter-row {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto auto;
  gap: 12px;
  align-items: end;
}

.date-label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

.tabs {
  width: min(100%, 1340px);
  margin: 0 auto 34px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.tab {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.80);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-weight: 800;
}

.tab.is-active {
  color: #ffffff;
  background: linear-gradient(135deg, #0ea5e9, #2563eb 58%, #4f46e5);
  border-color: transparent;
}

.tab b {
  min-width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0 8px;
  color: inherit;
  background: rgba(255, 255, 255, 0.24);
  border-radius: 999px;
}

.grid {
  width: min(100%, 1340px);
  margin: 0 auto;
  display: grid;
  gap: 26px;
}

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

.metric-card {
  min-height: 138px;
  border-radius: 24px;
  padding: 22px;
}

.metric-card i {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: #172033;
  border-radius: 14px;
  font-size: 19px;
}

.metric-card span {
  display: block;
  margin-top: 18px;
  color: var(--muted);
  font-weight: 800;
}

.metric-card strong {
  display: block;
  margin-top: 4px;
  font-size: 38px;
  line-height: 1;
}

.panel {
  border-radius: var(--radius);
  padding: 28px;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.panel-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: #172033;
  border-radius: 16px;
  font-size: 20px;
}

.panel-header h2,
.panel-header p {
  margin: 0;
}

.panel-header h2 {
  font-size: 24px;
  line-height: 1.25;
}

.panel-header p {
  color: var(--muted);
}

.panel-header .action-button {
  margin-left: auto;
  min-height: 42px;
  border-radius: 14px;
  font-size: 14px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  margin-top: 24px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th,
td {
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 13px;
}

td {
  font-weight: 700;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.note-cell {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--success);
  background: rgba(22, 163, 74, 0.12);
  font-size: 12px;
  font-weight: 900;
}

.badge.muted {
  color: var(--muted);
  background: var(--surface-muted);
}

.stock-page,
.post-pattern-layout {
  width: min(100%, 1340px);
  margin: 0 auto;
}

.stock-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.stock-page-header h2,
.stock-page-header p {
  margin: 0;
}

.stock-page-header h2 {
  font-size: 30px;
  line-height: 1.2;
}

.stock-page-header p {
  max-width: 760px;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.7;
}

.stock-summary {
  min-width: 138px;
  padding: 16px;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 18px;
  text-align: right;
}

.stock-summary strong,
.stock-summary span {
  display: block;
}

.stock-summary strong {
  font-size: 32px;
  line-height: 1;
}

.stock-summary span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.stock-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 12px;
  margin-bottom: 16px;
}

.ready-stock-note {
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  color: var(--success);
  background: rgba(22, 163, 74, 0.12);
  border: 1px solid rgba(22, 163, 74, 0.18);
  border-radius: 16px;
  font-weight: 900;
  white-space: nowrap;
}

.stock-search,
.select-control {
  min-width: 0;
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 14px;
}

.stock-search input,
.select-control select {
  min-width: 0;
  width: 100%;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  font-weight: 800;
}

.select-control {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
}

.select-control.wide {
  grid-template-columns: 1fr;
  align-items: start;
  padding: 12px 14px;
}

.select-control span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.stock-status-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 24px;
}

.status-tab {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 0 14px;
  color: var(--muted);
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-weight: 900;
}

.status-tab.is-active {
  color: #ffffff;
  background: linear-gradient(135deg, #0284c7, #2563eb 60%, #4f46e5);
  border-color: transparent;
}

.status-tab b {
  min-width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0 8px;
  background: rgba(148, 163, 184, 0.16);
  border-radius: 999px;
}

.status-tab.is-active b {
  background: rgba(255, 255, 255, 0.24);
}

.stock-list-panel {
  padding-bottom: 24px;
}

.stock-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  margin-top: 24px;
}

.stock-table {
  min-width: 1120px;
}

.stock-row {
  cursor: pointer;
}

.stock-row:hover td {
  background: rgba(37, 99, 235, 0.05);
}

.product-cell {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 260px;
}

.product-cell.no-thumb {
  min-width: 300px;
}

.product-thumb {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  object-fit: cover;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.product-thumb.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.product-main {
  min-width: 0;
}

.product-main strong,
.product-main span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-main strong {
  max-width: 320px;
}

.product-main span {
  max-width: 360px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  color: #334155;
  background: #e2e8f0;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.status-inStock {
  color: #166534;
  background: rgba(34, 197, 94, 0.14);
}

.status-awaitingPrice,
.status-chatDraft {
  color: #92400e;
  background: rgba(245, 158, 11, 0.18);
}

.status-sold,
.status-lockedInSaleCase {
  color: #991b1b;
  background: rgba(239, 68, 68, 0.14);
}

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

.small-button,
.secondary-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink);
  background: var(--surface-solid);
  border: 1px solid var(--line);
  font-weight: 900;
  text-decoration: none;
}

.small-button {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 12px;
  font-size: 13px;
}

.secondary-button {
  min-height: 52px;
  padding: 0 18px;
  border-radius: 16px;
}

.text-button {
  min-height: 36px;
  padding: 0 10px;
  color: var(--accent-strong);
  background: transparent;
  border: 0;
}

.empty-state {
  min-height: 180px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}

.empty-state i {
  font-size: 26px;
}

.empty-state strong {
  color: var(--ink);
}

.detail-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 42, 0.32);
}

.product-modal {
  position: fixed;
  inset: 50% auto auto 50%;
  z-index: 41;
  width: min(760px, calc(100vw - 28px));
  max-height: min(900px, calc(100vh - 28px));
  overflow-y: auto;
  padding: 24px;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 28px 86px rgba(15, 23, 42, 0.28);
  transform: translate(-50%, -50%);
}

.product-drawer {
  position: fixed;
  inset: 14px 14px 14px auto;
  z-index: 41;
  width: min(560px, calc(100vw - 28px));
  overflow-y: auto;
  padding: 24px;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 28px 86px rgba(15, 23, 42, 0.28);
}

.modal-title-actions {
  display: flex;
  gap: 8px;
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.drawer-header h2,
.drawer-header span {
  margin: 0;
}

.drawer-header h2 {
  font-size: 25px;
  line-height: 1.25;
}

.drawer-header span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-weight: 800;
}

.product-gallery {
  display: grid;
  gap: 12px;
}

.image-section {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.image-section h3,
.modal-section-title {
  margin: 0;
  color: var(--muted);
  font-size: 18px;
  font-weight: 900;
}

.modal-section-title {
  margin-top: 24px;
}

.image-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(220px, 1fr);
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.image-tile {
  position: relative;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  background: var(--surface-muted);
  border: 0;
  border-radius: 18px;
}

.image-tile img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.image-tile span {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1;
  padding: 5px 10px;
  color: #ffffff;
  background: rgba(15, 23, 42, 0.72);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.product-gallery > img,
.gallery-empty {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.gallery-empty.slim {
  min-height: 126px;
  aspect-ratio: auto;
}

.product-gallery > img {
  object-fit: cover;
}

.gallery-empty {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--muted);
}

.gallery-empty i {
  font-size: 32px;
}

.gallery-thumbs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.gallery-thumbs button {
  padding: 0;
  overflow: hidden;
  background: transparent;
  border: 2px solid transparent;
  border-radius: 12px;
}

.gallery-thumbs button.is-active {
  border-color: var(--accent);
}

.gallery-thumbs img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

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

.detail-list {
  overflow: hidden;
  margin-top: 10px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 20px;
}

.detail-row {
  display: grid;
  grid-template-columns: minmax(130px, 0.55fr) minmax(0, 1fr);
  gap: 16px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}

.detail-row:last-child {
  border-bottom: 0;
}

.detail-row span {
  color: var(--ink);
  font-weight: 800;
}

.detail-row strong {
  min-width: 0;
  color: var(--muted);
  text-align: right;
  overflow-wrap: anywhere;
}

.link-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  padding: 14px 16px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.link-card a {
  min-width: 0;
  color: var(--accent-strong);
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}

.detail-item {
  min-width: 0;
  padding: 14px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.detail-item span,
.detail-item strong {
  display: block;
}

.detail-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.detail-item strong {
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.drawer-note,
.post-preview {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.drawer-note h3,
.drawer-note p,
.post-preview h3 {
  margin: 0;
}

.drawer-note p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.post-preview > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.post-preview pre,
.pattern-preview {
  max-height: 360px;
  margin: 0;
  overflow: auto;
  padding: 16px;
  color: var(--ink);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: inherit;
  line-height: 1.65;
}

.post-pattern-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(360px, 1.1fr);
  gap: 24px;
}

.pattern-textarea {
  width: 100%;
  min-height: 560px;
  margin-top: 22px;
  padding: 16px;
  color: var(--ink);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 16px;
  outline: 0;
  resize: vertical;
  line-height: 1.65;
}

.token-help {
  display: grid;
  gap: 6px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.token-help strong {
  color: var(--ink);
}

.empty-text {
  margin: 18px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.home-grid {
  width: min(100%, 1340px);
  height: calc(100dvh - 172px);
  margin: 0 auto;
  display: grid;
  min-height: 0;
  overflow: hidden;
}

.home-hero,
.chat-shell {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.home-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 22px;
  align-items: center;
  padding: 28px;
}

.home-hero h2,
.home-hero p {
  margin: 0;
}

.home-hero h2 {
  font-size: 30px;
  line-height: 1.2;
}

.home-hero p:last-child {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.7;
}

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

.home-stat {
  min-width: 110px;
  padding: 14px;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.home-stat i,
.home-stat span,
.home-stat strong {
  display: block;
}

.home-stat i {
  color: var(--accent);
}

.home-stat span {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.home-stat strong {
  margin-top: 3px;
  font-size: 26px;
  line-height: 1;
}

.chat-shell {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  overflow: hidden;
}

.chat-room-list {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.42);
}

.chat-section-header,
.chat-panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.chat-section-header h2,
.chat-section-header p,
.chat-panel-header h2,
.chat-panel-header span {
  margin: 0;
}

.chat-section-header p,
.chat-panel-header span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.chat-section-header > span {
  align-self: flex-start;
  min-width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: var(--accent);
  border-radius: 999px;
  font-weight: 900;
}

.chat-rooms {
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding: 10px;
}

.chat-room-row {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 16px;
  text-align: left;
}

.chat-room-row:hover,
.chat-room-row.is-active {
  background: var(--surface-solid);
}

.chat-room-row img,
.chat-room-row > span {
  width: 42px;
  height: 42px;
  border-radius: 14px;
}

.chat-room-row img {
  object-fit: cover;
}

.chat-room-row > span {
  display: grid;
  place-items: center;
  color: #ffffff;
  background: #172033;
  font-size: 12px;
  font-weight: 900;
}

.chat-room-row strong,
.chat-room-row small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-room-row small,
.chat-room-row time {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.chat-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--surface-solid);
}

.chat-messages {
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  display: flex;
}

.chat-message.is-mine {
  justify-content: flex-end;
}

.chat-message > div {
  max-width: min(78%, 520px);
  padding: 12px 14px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.chat-message.is-mine > div {
  color: #ffffff;
  background: var(--accent);
  border-color: transparent;
}

.chat-message strong,
.chat-message p,
.chat-message time {
  display: block;
  margin: 0;
}

.chat-message p {
  margin-top: 4px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-message time {
  margin-top: 6px;
  color: inherit;
  opacity: 0.72;
  font-size: 11px;
  font-weight: 800;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 16px;
  border-top: 1px solid var(--line);
}

.chat-form input {
  min-width: 0;
  min-height: 52px;
  padding: 0 16px;
  color: var(--ink);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 16px;
  outline: 0;
}

.chat-empty {
  height: 100%;
}

.empty-state.compact {
  min-height: 140px;
}

.edit-modal {
  width: min(980px, calc(100vw - 28px));
}

.edit-form {
  display: grid;
  gap: 18px;
}

.edit-section {
  display: grid;
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.edit-section h3 {
  margin: 0;
  font-size: 18px;
}

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

.edit-field {
  min-width: 0;
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.edit-field.full {
  grid-column: 1 / -1;
}

.edit-field input,
.edit-field select,
.edit-field textarea {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: 0;
  font-weight: 800;
}

.edit-field textarea {
  padding: 12px;
  resize: vertical;
  line-height: 1.55;
}

.image-manager {
  display: grid;
  gap: 12px;
}

.image-manager-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}

.image-manager-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.file-control {
  min-height: 54px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px dashed rgba(37, 99, 235, 0.34);
  border-radius: 16px;
  font-weight: 900;
}

.file-control input {
  display: none;
}

.edit-actions {
  position: sticky;
  bottom: -24px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 0 0;
  background: linear-gradient(180deg, transparent, var(--surface-solid) 22%);
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.72);
}

.image-lightbox img {
  max-width: min(100%, 980px);
  max-height: 92vh;
  object-fit: contain;
  border-radius: 18px;
}

.placeholder-card {
  width: min(100%, 980px);
  margin: 26px auto 0;
  border-radius: var(--radius);
  padding: 34px;
}

.placeholder-card h2,
.placeholder-card p {
  margin: 0;
}

.placeholder-card h2 {
  font-size: 30px;
}

.placeholder-card p {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.8;
}

.placeholder-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 28px;
}

.placeholder-list div {
  padding: 18px;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.placeholder-list strong {
  display: block;
  margin-bottom: 6px;
}

.placeholder-list span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 44px));
  padding: 14px 16px;
  color: #ffffff;
  background: #172033;
  border-radius: 16px;
  box-shadow: 0 18px 38px rgba(15, 23, 42, 0.22);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

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

.menu-button {
  display: none;
}

body.sidebar-compact {
  --sidebar-width: 104px;
}

body.sidebar-compact .sidebar {
  padding-inline: 18px;
}

body.sidebar-compact .sidebar-brand div,
body.sidebar-compact .sidebar-tools #theme-button,
body.sidebar-compact .nav-item span,
body.sidebar-compact .nav-group p {
  display: none;
}

body.sidebar-compact .sidebar-tools {
  position: static;
  margin-top: 24px;
}

body.sidebar-compact .sidebar-nav {
  margin-top: 24px;
}

body.sidebar-compact .nav-item {
  grid-template-columns: 1fr;
  justify-items: center;
  padding-inline: 0;
}

@media (max-width: 1180px) {
  .login-screen {
    grid-template-columns: 1fr;
  }

  .login-preview {
    display: none;
  }

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

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

  .chat-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(170px, 34%) minmax(0, 1fr);
  }

  .chat-room-list {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-rooms {
    max-height: none;
  }

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

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

  .pattern-textarea {
    min-height: 380px;
  }
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(320px, 86vw);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .menu-button {
    display: inline-grid;
  }

  .topbar-user {
    display: none;
  }

  .content {
    padding-top: 24px;
  }

  .home-grid {
    height: calc(100dvh - 156px);
  }

  .stock-page-header,
  .stock-toolbar {
    grid-template-columns: 1fr;
  }

  .stock-page-header {
    display: grid;
  }

  .stock-summary {
    width: 100%;
    text-align: left;
  }

  .product-drawer,
  .product-modal {
    inset: 8px;
    width: auto;
    max-height: calc(100vh - 16px);
    padding: 18px;
    border-radius: 20px;
    transform: none;
  }
}

@media (max-width: 680px) {
  .login-screen {
    padding: 18px;
  }

  .login-panel {
    padding: 24px;
  }

  .topbar {
    height: auto;
    min-height: 76px;
    padding: 14px 16px;
  }

  .filter-card,
  .panel,
  .placeholder-card {
    border-radius: 20px;
    padding: 20px;
  }

  .filter-row,
  .metric-grid,
  .placeholder-list,
  .home-stats,
  .edit-grid {
    grid-template-columns: 1fr;
  }

  .home-grid {
    height: calc(100dvh - 156px);
  }

  .chat-shell {
    grid-template-rows: minmax(150px, 32%) minmax(0, 1fr);
  }

  .chat-section-header,
  .chat-panel-header {
    padding: 14px;
  }

  .chat-rooms,
  .chat-messages {
    padding: 10px;
  }

  .chat-form {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 10px;
  }

  .chat-form input {
    min-height: 46px;
  }

  .chat-form .primary-button {
    min-height: 46px;
    padding-inline: 14px;
  }

  .tabs {
    gap: 8px;
  }

  .tab {
    min-height: 40px;
    padding-inline: 12px;
    font-size: 13px;
  }

  .panel-header {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .panel-header .action-button {
    width: 100%;
    margin-left: 0;
  }

  .stock-page-header h2 {
    font-size: 26px;
  }

  .stock-status-tabs {
    gap: 8px;
  }

  .status-tab {
    min-height: 38px;
    padding-inline: 11px;
    font-size: 13px;
  }

  .drawer-header h2 {
    font-size: 22px;
  }

  .drawer-actions,
  .drawer-actions .primary-button,
  .drawer-actions .secondary-button {
    width: 100%;
  }

  .detail-grid,
  .gallery-thumbs {
    grid-template-columns: 1fr 1fr;
  }

  .detail-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .detail-row strong {
    text-align: left;
  }

  .image-strip {
    grid-auto-columns: minmax(180px, 82%);
  }

  .chat-message > div {
    max-width: 92%;
  }

  .edit-actions {
    display: grid;
  }

  .post-preview > div {
    align-items: flex-start;
  }
}

/* Chat case workspace v2 */
.case-chat-shell {
  grid-template-columns: minmax(390px, 430px) minmax(0, 1fr);
  background: rgba(255, 255, 255, 0.88);
}

.case-room-list {
  grid-template-rows: auto minmax(0, 1fr);
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.92), rgba(241, 245, 249, 0.72));
}

.chat-list-toolbar {
  display: grid;
  gap: 14px;
  padding: 22px 20px 16px;
  border-bottom: 1px solid var(--line);
}

.chat-list-title-row,
.chat-list-meta-row,
.case-card-title-row,
.case-card-side,
.case-status {
  display: flex;
  align-items: center;
}

.chat-list-title-row {
  justify-content: space-between;
  gap: 16px;
}

.chat-list-title-row h2,
.chat-list-title-row p {
  margin: 0;
}

.chat-list-title-row h2 {
  font-size: 30px;
  line-height: 1.1;
}

.chat-list-title-row p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.chat-list-title-row > span {
  min-width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  border-radius: 999px;
  font-weight: 950;
  box-shadow: 0 14px 26px rgba(37, 99, 235, 0.24);
}

.chat-search {
  min-height: 48px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  color: var(--muted);
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.chat-search input {
  min-width: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  font-weight: 800;
}

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

.chat-type-tabs button {
  min-height: 40px;
  flex: 0 0 auto;
  padding: 0 14px;
  color: var(--muted);
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-weight: 900;
  white-space: nowrap;
}

.chat-type-tabs button.is-active {
  color: #ffffff;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  border-color: transparent;
}

.chat-list-meta-row {
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.chat-date-filter {
  min-height: 38px;
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 999px;
}

.chat-date-filter select {
  color: inherit;
  background: transparent;
  border: 0;
  outline: 0;
  font-weight: 900;
}

.case-room-cards {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 14px;
}

.case-room-card.chat-room-row {
  min-height: 104px;
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) 100px;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 20px;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.05);
}

.case-room-card.chat-room-row:hover,
.case-room-card.chat-room-row.is-active {
  background: #ffffff;
  border-color: rgba(37, 99, 235, 0.28);
  box-shadow: 0 18px 40px rgba(37, 99, 235, 0.12);
}

.case-card-badge-wrap {
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 6px;
}

.case-card-badge-wrap small {
  width: 64px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-badge {
  min-width: 58px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0 10px;
  color: #ffffff;
  background: #4f46e5;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 950;
}

.case-badge-sell {
  background: #16a34a;
}

.case-badge-repair {
  background: #7c3aed;
}

.case-badge-trade {
  background: #8b5cf6;
}

.case-badge-pawn {
  background: #f59e0b;
}

.case-card-main {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.case-card-title-row {
  min-width: 0;
  gap: 9px;
}

.case-card-title-row strong {
  min-width: 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-card-avatar,
.case-card-initials,
.case-header-avatar,
.message-avatar {
  flex: 0 0 auto;
  object-fit: cover;
  background: #111827;
}

.case-card-avatar,
.case-card-initials {
  width: 34px;
  height: 34px;
  border-radius: 12px;
}

.case-card-initials,
.case-header-avatar.fallback,
.message-avatar.fallback {
  display: grid;
  place-items: center;
  color: #ffffff;
  font-size: 11px;
  font-weight: 950;
}

.case-card-subline,
.case-card-preview {
  min-width: 0;
  color: var(--muted);
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-card-subline,
.case-card-preview,
.case-card-side time {
  font-size: 12px;
}

.case-card-side {
  min-width: 0;
  flex-direction: column;
  align-items: flex-end;
  gap: 9px;
}

.case-card-side time {
  color: var(--muted);
  font-weight: 900;
}

.case-status {
  gap: 5px;
  color: var(--warning);
  font-size: 12px;
  font-weight: 950;
  white-space: nowrap;
}

.case-status i {
  width: 7px;
  height: 7px;
  display: inline-block;
  background: currentColor;
  border-radius: 999px;
}

.case-status-completed {
  color: var(--success);
}

.case-status-cancelled {
  color: var(--danger);
}

.case-chat-panel {
  background: #f8fafc;
}

.case-chat-header.chat-panel-header {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center;
  padding: 18px 22px;
  background: rgba(255, 255, 255, 0.92);
}

.chat-close-button {
  display: none;
}

.case-header-avatar {
  width: 46px;
  height: 46px;
  border-radius: 16px;
}

.case-chat-header h2 {
  max-width: 780px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-message-list.chat-messages {
  padding: 24px 28px;
  gap: 14px;
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.92), rgba(239, 246, 255, 0.62));
}

.case-message.chat-message {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  gap: 10px;
  align-items: end;
}

.case-message.chat-message.is-mine {
  justify-content: normal;
}

.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
}

.case-message-bubble {
  width: fit-content;
  max-width: min(620px, 76%);
  padding: 13px 15px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid rgba(226, 232, 240, 0.92);
  border-radius: 18px 18px 18px 6px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06);
}

.case-message.is-mine .case-message-bubble {
  justify-self: end;
  color: #ffffff;
  background: linear-gradient(135deg, #047857, #059669);
  border-color: transparent;
  border-radius: 18px 18px 6px 18px;
  box-shadow: 0 16px 34px rgba(5, 150, 105, 0.20);
}

.case-message-bubble strong {
  color: var(--accent-strong);
  font-size: 12px;
}

.case-message.is-mine .case-message-bubble strong {
  color: rgba(255, 255, 255, 0.86);
}

.case-message-bubble p {
  margin-top: 7px;
  font-size: 15px;
  line-height: 1.62;
}

.case-message-bubble time {
  text-align: right;
}

.message-image-grid {
  display: grid;
  gap: 5px;
  overflow: hidden;
  margin-top: 10px;
  border-radius: 14px;
}

.message-image-grid.count-1 {
  grid-template-columns: minmax(210px, 360px);
}

.message-image-grid.count-2,
.message-image-grid.count-3,
.message-image-grid.count-4 {
  grid-template-columns: repeat(2, minmax(120px, 1fr));
}

.message-image-tile {
  position: relative;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  background: rgba(15, 23, 42, 0.06);
  border: 0;
}

.message-image-tile img {
  width: 100%;
  aspect-ratio: 1;
  display: block;
  object-fit: cover;
}

.message-image-grid.count-1 .message-image-tile img {
  aspect-ratio: 4 / 3;
}

.message-image-tile span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: rgba(15, 23, 42, 0.48);
  font-size: 30px;
  font-weight: 950;
}

.message-file-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.message-file-list a {
  color: inherit;
  font-weight: 900;
  text-decoration: none;
}

.payment-slip-card {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 14px;
  color: #dcfce7;
  background: rgba(6, 95, 70, 0.92);
  border: 1px solid rgba(16, 185, 129, 0.28);
  border-radius: 16px;
}

.payment-slip-card strong {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #bbf7d0;
}

.payment-slip-card dl {
  display: grid;
  gap: 7px;
  margin: 0;
}

.payment-slip-card div {
  display: grid;
  grid-template-columns: 94px minmax(0, 1fr);
  gap: 10px;
}

.payment-slip-card dt,
.payment-slip-card dd {
  margin: 0;
}

.payment-slip-card dt {
  opacity: 0.72;
}

.payment-slip-card dd {
  overflow-wrap: anywhere;
  font-weight: 850;
}

.case-chat-form.chat-form {
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.94);
}

.composer-icon-button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 16px;
  font-size: 20px;
}

.case-chat-form .composer-preview {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.case-chat-form .composer-preview button {
  color: var(--danger);
  background: transparent;
  border: 0;
  font-weight: 950;
}

.lightbox-close {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 51;
}

html[data-theme="dark"] .case-chat-shell,
html[data-theme="dark"] .case-room-list,
html[data-theme="dark"] .case-chat-header.chat-panel-header,
html[data-theme="dark"] .case-chat-form.chat-form {
  background: rgba(14, 19, 31, 0.94);
}

html[data-theme="dark"] .case-chat-panel,
html[data-theme="dark"] .case-message-list.chat-messages {
  background: #060a12;
}

html[data-theme="dark"] .case-room-card.chat-room-row,
html[data-theme="dark"] .case-message-bubble {
  background: rgba(24, 29, 41, 0.96);
  border-color: rgba(255, 255, 255, 0.08);
}

@media (max-width: 1180px) {
  .case-chat-shell.chat-shell {
    grid-template-columns: minmax(340px, 390px) minmax(0, 1fr);
    grid-template-rows: none;
  }

  .case-room-list {
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .case-room-card.chat-room-row {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .case-card-side {
    grid-column: 2;
    align-items: flex-start;
    flex-direction: row;
    justify-content: space-between;
  }
}

@media (max-width: 760px) {
  .chat-case-workspace.home-grid {
    width: 100%;
    height: calc(100dvh - 156px);
  }

  .case-chat-shell.chat-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
    border-radius: 22px;
  }

  .case-room-list {
    border-right: 0;
  }

  .case-chat-panel {
    display: none;
  }

  .chat-case-workspace.is-chat-open .case-room-list {
    display: none;
  }

  .chat-case-workspace.is-chat-open .case-chat-panel {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: grid;
    border-radius: 0;
  }

  .chat-close-button {
    display: grid;
  }

  .case-chat-header.chat-panel-header {
    grid-template-columns: auto auto minmax(0, 1fr);
    gap: 10px;
    min-height: 86px;
    padding: max(14px, env(safe-area-inset-top)) 14px 12px;
  }

  .case-chat-header .case-status {
    display: none;
  }

  .case-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 14px;
  }

  .case-chat-header h2 {
    font-size: 17px;
  }

  .case-message-list.chat-messages {
    padding: 16px 14px;
  }

  .case-message.chat-message {
    grid-template-columns: 30px minmax(0, 1fr) 30px;
    gap: 8px;
  }

  .message-avatar {
    width: 30px;
    height: 30px;
  }

  .case-message-bubble {
    max-width: 82vw;
  }

  .case-chat-form.chat-form {
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: 10px 10px max(10px, env(safe-area-inset-bottom));
  }

  .composer-icon-button,
  .case-chat-form .primary-button {
    width: 46px;
    min-width: 46px;
    height: 46px;
    min-height: 46px;
    padding: 0;
    border-radius: 16px;
  }

  .case-chat-form .primary-button {
    font-size: 0;
  }

  .case-chat-form .primary-button i {
    font-size: 18px;
  }

  .case-room-cards {
    padding: 12px;
  }

  .case-room-card.chat-room-row {
    grid-template-columns: 70px minmax(0, 1fr);
    min-height: 112px;
  }

  .case-card-side {
    grid-column: 2;
  }
}

@media (max-width: 520px) {
  .chat-list-toolbar {
    padding: 18px 14px 12px;
  }

  .chat-list-title-row h2 {
    font-size: 28px;
  }

  .case-room-card.chat-room-row {
    grid-template-columns: 64px minmax(0, 1fr);
    padding: 10px;
  }

  .case-card-badge-wrap small {
    width: 58px;
  }

  .case-badge {
    min-width: 54px;
  }

  .case-card-side {
    gap: 8px;
  }

  .message-image-grid.count-1 {
    grid-template-columns: minmax(190px, 1fr);
  }

  .payment-slip-card div {
    grid-template-columns: 1fr;
    gap: 3px;
  }
}

/* Balance pass: sidebar, topbar, and chat density */
body.is-home-route #back-button {
  display: none;
}

.sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-brand {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.sidebar-brand span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.sidebar-tools {
  position: static;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.sidebar-tools .icon-button {
  width: 100%;
  height: 42px;
  border-radius: 14px;
  box-shadow: 0 12px 24px rgba(71, 85, 105, 0.08);
}

.sidebar-nav {
  min-height: 0;
  overflow-y: auto;
  margin-top: 20px;
  padding-right: 2px;
}

body.sidebar-compact {
  --sidebar-width: 92px;
}

body.sidebar-compact .sidebar {
  align-items: center;
  padding: 20px 14px;
}

body.sidebar-compact .sidebar-brand {
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 0;
}

body.sidebar-compact .sidebar-brand img {
  width: 54px;
  height: 54px;
  border-radius: 18px;
}

body.sidebar-compact .sidebar-tools {
  width: 100%;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 24px;
}

body.sidebar-compact .sidebar-tools #theme-button {
  display: inline-grid;
}

body.sidebar-compact .sidebar-tools .icon-button {
  width: 54px;
  height: 54px;
  margin-inline: auto;
  border-radius: 18px;
}

body.sidebar-compact .sidebar-nav {
  width: 100%;
  margin-top: 24px;
  padding-right: 0;
}

body.sidebar-compact .nav-group {
  gap: 12px;
}

body.sidebar-compact .nav-item {
  width: 54px;
  min-height: 54px;
  margin-inline: auto;
  border-radius: 18px;
  font-size: 17px;
}

body.sidebar-compact .nav-item.is-active {
  box-shadow: 0 16px 30px rgba(37, 99, 235, 0.22);
}

body.is-home-route .content {
  padding: 28px clamp(20px, 2.6vw, 42px) 40px;
}

body.is-home-route .home-grid {
  width: min(100%, 1500px);
  height: calc(100dvh - 150px);
}

.case-chat-shell {
  grid-template-columns: minmax(390px, 410px) minmax(0, 1fr);
}

.chat-list-toolbar {
  padding: 20px 18px 14px;
}

.chat-list-title-row h2 {
  font-size: 28px;
}

.chat-type-tabs button {
  min-height: 38px;
  padding-inline: 13px;
}

.case-room-cards {
  gap: 9px;
  padding: 12px;
}

.case-room-card.chat-room-row {
  min-height: 94px;
  grid-template-columns: 66px minmax(0, 1fr) 86px;
  padding: 12px 14px;
  border-radius: 18px;
}

.case-card-title-row {
  gap: 0;
}

.case-card-title-row strong {
  font-size: 16px;
}

.case-card-subline,
.case-card-preview {
  font-size: 12px;
  line-height: 1.35;
}

.case-card-side {
  gap: 7px;
}

.case-badge {
  min-width: 56px;
  height: 34px;
  border-radius: 15px;
}

.case-chat-header.chat-panel-header {
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 86px;
  padding: 16px 22px;
}

.case-chat-header .chat-close-button {
  display: none;
}

.case-chat-header h2 {
  max-width: 720px;
  font-size: 22px;
}

.case-message-list.chat-messages {
  padding: 22px 26px;
}

.case-message.chat-message {
  width: min(100%, 790px);
  margin-inline: auto;
}

.case-message-bubble {
  max-width: min(560px, 78%);
}

.payment-slip-card {
  background: rgba(6, 95, 70, 0.86);
}

.case-chat-form.chat-form {
  padding: 12px 16px;
}

@media (max-width: 1180px) {
  .case-chat-shell.chat-shell {
    grid-template-columns: minmax(340px, 380px) minmax(0, 1fr);
  }
}

@media (max-width: 900px) {
  body.is-home-route #back-button {
    display: none;
  }

  body.is-home-route .content {
    padding-top: 24px;
  }

  .sidebar {
    overflow-y: auto;
  }
}

@media (max-width: 760px) {
  body.is-home-route #back-button {
    display: none;
  }

  body.is-home-route .home-grid {
    height: calc(100dvh - 156px);
  }

  .case-chat-header.chat-panel-header {
    grid-template-columns: auto minmax(0, 1fr);
    min-height: 82px;
  }

  .case-chat-header .chat-close-button {
    display: grid;
  }

  .case-room-card.chat-room-row {
    grid-template-columns: 64px minmax(0, 1fr);
  }
}

/* Chat polish fixes: tighter mobile cards and deterministic message sides */
.chat-case-workspace .chat-list-toolbar {
  padding: 18px;
}

.chat-list-title-row {
  display: none;
}

.case-message.chat-message {
  width: 100%;
  max-width: none;
  margin-inline: 0;
  grid-template-columns: 38px minmax(0, 1fr) 38px;
}

.case-message:not(.is-mine) .message-avatar {
  grid-column: 1;
}

.case-message:not(.is-mine) .case-message-bubble {
  grid-column: 2;
  justify-self: start;
}

.case-message.is-mine .case-message-bubble {
  grid-column: 2;
  justify-self: end;
}

.case-message.is-mine .message-avatar {
  grid-column: 3;
}

.case-message-bubble {
  min-width: min(190px, 100%);
  max-width: min(620px, 72%);
  overflow-wrap: break-word;
}

.case-message-bubble strong,
.case-message-bubble p {
  overflow-wrap: anywhere;
  word-break: normal;
}

.case-message-bubble p {
  white-space: pre-wrap;
}

.case-message-bubble time {
  display: block;
}

.message-image-grid {
  max-width: min(420px, 100%);
}

.message-image-grid.is-scrollable {
  grid-auto-flow: column;
  grid-auto-columns: minmax(150px, 48%);
  grid-template-columns: none;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-inline: contain;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.message-image-grid.is-scrollable .message-image-tile {
  scroll-snap-align: start;
}

@media (max-width: 900px) {
  body.is-home-route .content {
    padding: 18px 14px 0;
  }
}

@media (max-width: 760px) {
  body.is-home-route .topbar {
    min-height: 92px;
  }

  body.is-home-route .content {
    padding: 14px 10px 0;
  }

  body.is-home-route .home-grid,
  .chat-case-workspace.home-grid {
    height: calc(100dvh - 106px);
  }

  .case-chat-shell.chat-shell {
    height: 100%;
  }

  .case-room-list {
    min-height: 0;
  }

  .chat-list-toolbar {
    gap: 12px;
    padding: 16px 14px 10px;
  }

  .chat-search {
    min-height: 44px;
    border-radius: 14px;
  }

  .chat-type-tabs {
    gap: 8px;
    padding-bottom: 4px;
  }

  .chat-type-tabs button {
    min-height: 38px;
    padding-inline: 14px;
    font-size: 15px;
  }

  .chat-list-meta-row {
    font-size: 13px;
  }

  .case-room-cards {
    gap: 10px;
    overflow-y: auto;
    padding: 10px;
  }

  .case-room-card.chat-room-row {
    min-height: 96px;
    grid-template-columns: 64px minmax(0, 1fr) 74px;
    gap: 10px;
    padding: 11px 12px;
    align-items: center;
  }

  .case-card-main {
    grid-column: 2;
  }

  .case-card-side {
    grid-column: 3;
    min-width: 64px;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    gap: 8px;
  }

  .case-status {
    font-size: 12px;
  }

  .case-card-side time {
    font-size: 12px;
  }

  .case-card-title-row strong {
    font-size: 16px;
  }

  .case-card-subline,
  .case-card-preview {
    font-size: 12px;
  }

  .case-badge {
    min-width: 56px;
    height: 34px;
  }

  .case-card-badge-wrap small {
    width: 60px;
  }

  .chat-case-workspace.is-chat-open .case-chat-panel {
    height: 100dvh;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .case-chat-header.chat-panel-header {
    grid-template-columns: auto minmax(0, 1fr);
    min-height: 76px;
    padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  }

  .case-message-list.chat-messages {
    padding: 14px 10px;
  }

  .case-message.chat-message {
    grid-template-columns: 30px minmax(0, 1fr) 30px;
    gap: 8px;
  }

  .case-message-bubble {
    min-width: 0;
    max-width: min(76vw, 360px);
    padding: 11px 13px;
  }

  .case-chat-form.chat-form {
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 520px) {
  .case-room-card.chat-room-row {
    grid-template-columns: 60px minmax(0, 1fr) 62px;
    padding-inline: 10px;
  }

  .case-card-side {
    min-width: 58px;
  }

  .case-card-title-row strong {
    font-size: 15px;
  }
}

/* Full workspace pass for the chat route */
body.is-home-route {
  overflow: hidden;
}

body.is-home-route .page-shell {
  height: var(--app-vh, 100dvh);
  display: grid;
  grid-template-rows: 82px minmax(0, 1fr);
  overflow: hidden;
}

body.is-home-route .topbar {
  position: relative;
}

body.is-home-route .content {
  min-height: 0;
  height: 100%;
  display: grid;
  overflow: hidden;
  padding: 0;
}

body.is-home-route .home-grid.chat-case-workspace {
  width: 100%;
  max-width: none;
  height: 100%;
  margin: 0;
}

body.is-home-route .case-chat-shell.chat-shell {
  width: 100%;
  height: 100%;
  min-height: 0;
  grid-template-columns: minmax(380px, 420px) minmax(0, 1fr);
  background: rgba(248, 250, 252, 0.78);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
}

body.is-home-route .case-room-list,
body.is-home-route .case-chat-panel {
  min-height: 0;
  overflow: hidden;
}

body.is-home-route .case-room-list {
  background: rgba(248, 250, 252, 0.86);
  border-right: 1px solid var(--line);
}

body.is-home-route .case-chat-panel {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: rgba(248, 250, 252, 0.96);
}

body.is-home-route .case-room-cards,
body.is-home-route .case-message-list.chat-messages {
  min-height: 0;
  overflow-y: auto;
}

body.is-home-route .case-message-list.chat-messages {
  scroll-padding-bottom: 92px;
}

body.is-home-route .case-chat-form.chat-form {
  position: relative;
  z-index: 2;
  border-top: 1px solid var(--line);
  box-shadow: 0 -12px 28px rgba(15, 23, 42, 0.05);
}

html[data-theme="dark"] body.is-home-route .case-chat-shell.chat-shell,
html[data-theme="dark"] body.is-home-route .case-room-list,
html[data-theme="dark"] body.is-home-route .case-chat-panel {
  background: #0b1020;
}

@media (max-width: 1180px) {
  body.is-home-route .case-chat-shell.chat-shell {
    grid-template-columns: minmax(340px, 390px) minmax(0, 1fr);
  }
}

@media (max-width: 900px) {
  body.is-home-route .page-shell {
    grid-template-rows: 92px minmax(0, 1fr);
  }

  body.is-home-route .topbar {
    min-height: 92px;
    height: 92px;
  }

  body.is-home-route .case-chat-shell.chat-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
  }

  body.is-home-route .case-room-list {
    border-right: 0;
  }

  body.is-home-route .chat-list-toolbar {
    padding: 16px 14px 10px;
  }

  body.is-home-route .case-room-cards {
    padding: 10px 10px max(10px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 760px) {
  body.is-home-route:not(.chat-detail-open) .case-chat-panel {
    display: none;
  }

  body.is-home-route:not(.chat-detail-open) .case-room-list {
    display: grid;
  }

  body.is-home-route .content,
  body.is-home-route .home-grid.chat-case-workspace,
  body.is-home-route .case-chat-shell.chat-shell {
    width: 100%;
  }

  body.is-home-route .case-chat-shell.chat-shell {
    border-radius: 0;
  }

  body.is-home-route.chat-detail-open .topbar,
  body.is-home-route.chat-detail-open .sidebar {
    display: none;
  }

  body.is-home-route.chat-detail-open .page-shell,
  body.is-home-route.chat-detail-open .content,
  body.is-home-route.chat-detail-open .home-grid.chat-case-workspace,
  body.is-home-route.chat-detail-open .case-chat-shell.chat-shell {
    height: var(--app-vh, 100dvh);
    min-height: 0;
  }

  body.is-home-route.chat-detail-open .page-shell {
    display: block;
  }

  body.is-home-route.chat-detail-open .chat-case-workspace.is-chat-open .case-chat-panel {
    position: fixed;
    inset: 0;
    z-index: 80;
    width: 100vw;
    height: var(--app-vh, 100dvh);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    border-radius: 0;
  }

  body.is-home-route.chat-detail-open .chat-case-workspace.is-chat-open .case-room-list {
    display: none;
  }

  body.is-home-route.chat-detail-open .case-chat-header.chat-panel-header {
    min-height: 72px;
    padding: calc(env(safe-area-inset-top) + 8px) 12px 10px;
    background: rgba(255, 255, 255, 0.98);
  }

  body.is-home-route.chat-detail-open .case-chat-header .chat-close-button {
    display: grid;
  }

  body.is-home-route.chat-detail-open .case-message-list.chat-messages {
    padding: 12px 10px;
  }

  body.is-home-route.chat-detail-open .case-chat-form.chat-form {
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.98);
  }

  .message-image-grid.is-scrollable {
    grid-auto-columns: minmax(132px, 62vw);
    max-width: 76vw;
  }

  html[data-theme="dark"] body.is-home-route.chat-detail-open .case-chat-header.chat-panel-header,
  html[data-theme="dark"] body.is-home-route.chat-detail-open .case-chat-form.chat-form {
    background: #0b1020;
  }
}
