* {
  box-sizing: border-box;
}

:root {
  --sidebar: #ffffff;
  --sidebar-2: #f8fbff;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --accent-soft: #eff6ff;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #e5eaf2;
  --text: #172033;
  --muted: #64748b;
  --danger: #dc2626;
  --warning: #d97706;
  --success: #16a34a;
  --shadow: 0 18px 42px rgba(15, 23, 42, 0.07);
  --shadow-soft: 0 8px 24px rgba(15, 23, 42, 0.05);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

a {
  color: var(--accent-2);
}

.erp-shell {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  min-height: 100vh;
}

.erp-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: var(--text);
  padding: 18px 12px;
  box-shadow: 8px 0 28px rgba(15, 23, 42, 0.03);
}

.sidebar-scrim {
  display: none;
}

.sidebar-brand {
  position: relative;
  display: grid;
  gap: 5px;
  padding: 8px 10px 18px 56px;
  border-bottom: 1px solid var(--line);
}

.sidebar-brand::before {
  content: "HY";
  position: absolute;
  left: 10px;
  top: 8px;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  color: #ffffff;
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.28);
}

.sidebar-brand strong {
  font-size: 17px;
  line-height: 1.25;
}

.sidebar-brand span {
  color: #94a3b8;
  font-size: 13px;
}

.sidebar-nav {
  display: grid;
  gap: 6px;
  padding-top: 12px;
}

.menu-section {
  border-radius: 8px;
}

.menu-section summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  list-style: none;
  min-height: 38px;
  padding: 8px 11px;
  border-radius: 10px;
  color: #64748b;
  font-size: 14px;
  font-weight: 750;
  letter-spacing: 0;
}

.menu-section summary::-webkit-details-marker {
  display: none;
}

.menu-section summary::after {
  content: "⌄";
  color: #94a3b8;
  font-size: 13px;
  transition: transform 0.16s ease;
}

.menu-section[open] summary {
  background: #f1f5fb;
  color: #1e293b;
}

.menu-section[open] summary::after {
  transform: rotate(180deg);
}

.menu-link {
  display: block;
  margin: 3px 0 3px 16px;
  padding: 8px 10px 8px 15px;
  border-radius: 10px;
  border-left: 2px solid transparent;
  color: #64748b;
  font-size: 14px;
  text-decoration: none;
}

.menu-link:hover,
.menu-link.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--accent-2);
}

.menu-link.active {
  font-weight: 900;
}

.erp-workspace {
  min-width: 0;
}

.erp-topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 54px;
  padding: 9px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 248, 252, 0.88);
  backdrop-filter: blur(14px);
}

.topbar-title {
  color: #172033;
  font-weight: 800;
  font-size: 15px;
}

.topbar-user {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  color: #475569;
  font-size: 13px;
}

.topbar-user a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.sidebar-toggle {
  display: none;
  min-width: 42px;
  padding: 8px 10px;
}

.erp-content {
  width: min(1540px, 100%);
  margin: 0 auto;
  padding: 28px 34px;
}

.container,
.simple-container {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.simple-container {
  padding: 24px 0;
}

.messages {
  margin-bottom: 18px;
  padding: 13px 16px;
  border: 1px solid #bfdbfe;
  border-radius: 14px;
  background: #eff6ff;
  color: #1e40af;
}

.messages p {
  margin: 0;
}

.warning-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-color: #f2c94c;
  background: #fffbeb;
}

.page-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-title h1,
h1 {
  margin: 0;
  color: #0f172a;
  font-size: 26px;
  line-height: 1.2;
}

.page-eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.page-subtitle {
  margin: 8px 0 0;
  color: var(--muted);
}

.dashboard-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  color: #475569;
  font-size: 14px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 12px;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 900;
}

.panel {
  overflow-x: auto;
  margin-bottom: 20px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.panel h2 {
  margin: 0 0 14px;
  color: #172033;
  font-size: 18px;
}

.section-heading,
.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.dashboard-grid,
.stats-grid,
.placeholder-grid,
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.core-metrics {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  margin-bottom: 22px;
}

.metric-card,
.stat-card,
.placeholder-grid p,
.detail-grid p {
  margin: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #ffffff;
}

.metric-card {
  display: grid;
  gap: 6px;
  min-height: 108px;
  border-top: 3px solid #dbeafe;
  box-shadow: var(--shadow-soft);
}

.metric-card.primary {
  border-top-color: var(--accent);
}

.metric-card.success {
  border-top-color: var(--success);
}

.metric-card.warning {
  border-top-color: var(--warning);
}

.metric-card.danger {
  border-top-color: var(--danger);
}

.metric-card span,
.stat-card span {
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
}

.metric-card strong,
.stat-card strong {
  color: #0f172a;
  font-size: 28px;
  line-height: 1.15;
}

.metric-card small {
  color: #64748b;
}

.stats-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.stats-grid.compact .stat-card strong {
  font-size: 22px;
}

.stat-card.warning strong {
  color: var(--warning);
}

.stat-card.muted strong {
  color: var(--muted);
  font-size: 18px;
}

.period-tabs {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid #dbe3ee;
  border-radius: 8px;
  background: #f8fafc;
}

.period-tab {
  min-height: 34px;
  padding: 6px 14px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #475569;
  font-weight: 800;
}

.period-tab.active {
  background: var(--accent);
  color: #ffffff;
}

.period-panel {
  display: none;
}

.period-panel.active {
  display: block;
}

.period-range {
  margin: 0 0 12px;
  color: var(--muted);
}

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

.chart-panel canvas {
  width: 100%;
  max-height: 260px;
}

.reminder-grid,
.activity-grid {
  align-items: start;
}

.clean-dashboard .metric-card {
  background:
    linear-gradient(180deg, rgba(37, 99, 235, 0.035), rgba(255, 255, 255, 0) 42%),
    #ffffff;
}

.clean-panel {
  padding-bottom: 26px;
}

.quick-entry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}

.quick-entry {
  display: grid;
  gap: 6px;
  min-height: 84px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #ffffff;
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow-soft);
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.quick-entry:hover {
  border-color: #bfdbfe;
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.quick-entry strong {
  color: #172033;
  font-size: 16px;
}

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

.quick-links,
.actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.button:hover,
button:hover {
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.14);
  transform: translateY(-1px);
}

.button.secondary {
  border-color: var(--line);
  background: #ffffff;
  color: #334155;
}

.button.small,
.data-table .button.small {
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 13px;
}

.button.success,
button.success {
  background: var(--success);
  color: #ffffff;
}

.button.warning,
button.warning {
  background: var(--warning);
  color: #ffffff;
}

.button.disabled,
button:disabled,
input[type="submit"]:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button.danger,
.button.danger {
  background: var(--danger);
  color: #ffffff;
}

.inline-form {
  display: inline;
}

.record-form,
.search-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.search-form {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fbff;
}

.record-form label,
.search-form label {
  display: grid;
  gap: 6px;
  font-weight: 800;
}

.search-form input,
.record-form input,
.record-form select,
.record-form textarea,
.document-form input,
.document-form select,
.document-form textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #ffffff;
  font: inherit;
}

.record-form textarea,
.document-form textarea {
  min-height: 86px;
  resize: vertical;
}

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

.record-form .full,
.detail-grid .full {
  grid-column: 1 / -1;
}

.record-form small {
  color: var(--muted);
  font-weight: 400;
}

.bulk-action-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 18px;
  padding: 14px 16px;
  border: 1px solid #dbeafe;
  border-radius: 14px;
  background: #f8fbff;
}

.bulk-action-bar strong {
  display: block;
  margin-bottom: 2px;
  color: #172033;
}

.bulk-action-bar span,
.stock-hint {
  color: var(--muted);
  font-size: 13px;
}

.stock-hint {
  padding: 12px 14px;
  border: 1px solid #dbeafe;
  border-radius: 12px;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 800;
}

.checkbox-line {
  display: flex !important;
  flex-direction: row;
  gap: 8px !important;
}

.checkbox-line input {
  width: auto;
}

.required {
  color: var(--danger);
  margin-left: 2px;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  border-radius: 14px;
}

.initial-stock-scroll {
  max-height: 560px;
  border: 1px solid var(--line);
}

.initial-stock-table {
  min-width: 1180px;
}

.initial-stock-table th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.initial-stock-table input,
.initial-stock-table select {
  min-width: 120px;
  padding: 8px 9px;
  font-size: 13px;
}

.initial-stock-table .row-index {
  width: 48px;
  color: var(--muted);
  font-weight: 900;
  text-align: center;
}

.initial-stock-actions {
  margin-top: 14px;
}

.stock-number strong {
  color: #0f172a;
  font-size: 15px;
}

.data-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 10px 9px;
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.data-table th {
  background: #f1f5fb;
  color: #334155;
  font-weight: 800;
  white-space: nowrap;
}

.data-table td:last-child a:not(.button) {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.data-table .inline-form button,
.data-table a {
  white-space: nowrap;
}

.data-table tr:hover td {
  background: #f8fbff;
}

.data-table select,
.data-table input {
  min-width: 130px;
}

.number-cell {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.actions-cell {
  text-align: right !important;
  white-space: nowrap;
}

.empty {
  color: var(--muted);
  text-align: center !important;
  padding: 36px 12px !important;
  background: #fbfdff;
  font-weight: 800;
}

.empty-state {
  display: grid;
  gap: 6px;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px dashed #bfdbfe;
  border-radius: 16px;
  background: #f8fbff;
  color: #475569;
}

.empty-state strong {
  color: #172033;
  font-size: 16px;
}

.empty-state span {
  color: var(--muted);
}

.muted {
  color: var(--muted);
}

.pagination-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #e2e8f0;
  color: #475569;
  font-size: 14px;
}

.pagination-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination-actions .button {
  min-height: 34px;
  padding: 6px 12px;
}

.inline-details summary {
  cursor: pointer;
  color: var(--accent-2);
  font-weight: 800;
}

.inline-details ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 900;
}

.badge.green {
  background: #dcfce7;
  color: #166534;
}

.badge.red {
  background: #fee2e2;
  color: #991b1b;
}

.badge.gray {
  background: #e5e7eb;
  color: #374151;
}

.badge.warning {
  background: #fef3c7;
  color: #92400e;
}

.badge.level {
  background: #dbeafe;
  color: #1d4ed8;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.tag.green {
  background: #dcfce7;
  color: #166534;
}

.tag.red {
  background: #fee2e2;
  color: #991b1b;
}

.tag.gray {
  background: #e5e7eb;
  color: #374151;
}

.tag.orange {
  background: #ffedd5;
  color: #9a3412;
}

.guide-list {
  margin: 0;
  padding-left: 22px;
  color: var(--text);
}

.guide-list li {
  margin: 10px 0;
  line-height: 1.7;
}

.checklist {
  margin: 0;
  padding-left: 22px;
}

.checklist li {
  margin: 6px 0;
}

.acceptance-table input,
.acceptance-table select {
  min-width: 150px;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.report-card {
  display: grid;
  gap: 8px;
  min-height: 112px;
  padding: 18px;
  border: 1px solid #d9e2ec;
  border-radius: 8px;
  background: #f8fafc;
  color: #1f2937;
  text-decoration: none;
}

.report-card strong {
  color: #123524;
  font-size: 18px;
}

.report-card span {
  color: var(--muted);
}

.badge-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.auth-panel {
  width: min(460px, 100%);
  margin: 48px auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.auth-panel h1 {
  margin-bottom: 20px;
  font-size: 28px;
}

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

.auth-form label {
  display: grid;
  gap: 6px;
  font-weight: 800;
}

.auth-form input,
.auth-form select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font: inherit;
}

.auth-note {
  color: #4b5563;
  font-size: 14px;
}

.print-document h1 {
  margin-bottom: 22px;
  text-align: center;
  font-size: 30px;
}

.signature-grid p {
  min-height: 72px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sidebar-collapsed .erp-shell {
  grid-template-columns: 72px minmax(0, 1fr);
}

.sidebar-collapsed .erp-sidebar {
  padding-inline: 10px;
}

.sidebar-collapsed .sidebar-brand span,
.sidebar-collapsed .menu-link,
.sidebar-collapsed .menu-section summary {
  font-size: 0;
}

.sidebar-collapsed .sidebar-brand strong::before {
  content: "ERP";
  font-size: 16px;
}

.sidebar-collapsed .sidebar-brand strong {
  font-size: 0;
}

.dashboard-overview {
  border-color: #dbeafe;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

.customer-metrics {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.customer-risk-grid {
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  align-items: start;
}

.customer-billing-table th:nth-child(2),
.customer-billing-table td:nth-child(2) {
  min-width: 160px;
}

.customer-name-strong {
  display: block;
  color: #0f172a;
  font-weight: 900;
  text-decoration: none;
}

.customer-name-strong + small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.money,
.number {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.strong {
  font-weight: 900;
}

.danger-text {
  color: var(--danger);
}

.credit-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.credit-card {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fafc;
}

.credit-card strong {
  font-size: 16px;
}

.credit-card span {
  color: #475569;
  font-size: 13px;
}

.credit-card.active {
  border-color: #93c5fd;
  background: #eff6ff;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.12);
}

.mobile-friendly-form label {
  min-width: 0;
}

.stock-hint,
.help-text {
  color: var(--muted);
}

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

.photo-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
}

.photo-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 10px;
  background: #f1f5f9;
}

.photo-card strong {
  font-size: 15px;
}

.photo-card span,
.photo-card small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.voucher-panel {
  border-color: #bfdbfe;
}

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

.voucher-header strong {
  font-size: 24px;
}

.voucher-header span {
  color: var(--muted);
  font-weight: 800;
}

.copy-textarea {
  width: 100%;
  min-height: 180px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
  color: #1e293b;
  font: inherit;
  resize: vertical;
}

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

  .erp-sidebar {
    position: fixed;
    z-index: 10;
    inset: 0 auto 0 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

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

  .sidebar-toggle {
    display: inline-flex;
  }

  .erp-content {
    padding: 18px;
  }

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

  .dashboard-grid,
  .customer-risk-grid,
  .stats-grid,
  .quick-entry-grid,
  .placeholder-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .page-title,
  .section-heading,
  .erp-topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel,
  .metric-card,
  .stat-card,
  .quick-entry {
    border-radius: 14px;
  }

  .actions,
  .form-actions,
  .quick-links,
  .dashboard-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .button,
  button {
    min-height: 44px;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  .erp-content {
    padding: 14px;
  }

  .panel {
    padding: 18px;
  }

  .page-title h1,
  h1 {
    font-size: 23px;
  }

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

  .data-table {
    min-width: 640px;
  }

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

  .credit-card-grid,
  .photo-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 1024px) {
  .erp-workspace {
    width: 100%;
  }

  .customer-billing-table {
    min-width: 1180px;
  }

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

@media (min-width: 768px) and (max-width: 1023px) {
  .erp-shell {
    grid-template-columns: 1fr;
  }

  .erp-sidebar {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    width: 286px;
    max-width: 84vw;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 18px 0 48px rgba(15, 23, 42, 0.18);
  }

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

  .sidebar-scrim {
    position: fixed;
    z-index: 25;
    inset: 0;
    display: block;
    pointer-events: none;
    background: rgba(15, 23, 42, 0);
    opacity: 0;
    transition: opacity 0.18s ease, background 0.18s ease;
  }

  body.sidebar-open .sidebar-scrim {
    pointer-events: auto;
    background: rgba(15, 23, 42, 0.28);
    opacity: 1;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .erp-content {
    padding: 22px;
  }

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

  .customer-risk-grid,
  .chart-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 767px) {
  body {
    background: #f6f8fc;
    font-size: 14px;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .erp-shell {
    display: block;
    min-height: 100vh;
  }

  .erp-sidebar {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    width: min(84vw, 292px);
    height: 100dvh;
    padding: 16px 12px;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 18px 0 52px rgba(15, 23, 42, 0.2);
  }

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

  .sidebar-scrim {
    position: fixed;
    z-index: 25;
    inset: 0;
    display: block;
    pointer-events: none;
    background: rgba(15, 23, 42, 0);
    opacity: 0;
    transition: opacity 0.18s ease, background 0.18s ease;
  }

  body.sidebar-open .sidebar-scrim {
    pointer-events: auto;
    background: rgba(15, 23, 42, 0.3);
    opacity: 1;
  }

  .sidebar-brand {
    padding-bottom: 16px;
  }

  .menu-section summary {
    min-height: 42px;
    padding: 10px 12px;
    font-size: 15px;
  }

  .menu-link {
    min-height: 38px;
    margin-left: 14px;
    padding: 9px 12px 9px 15px;
    font-size: 14px;
  }

  .erp-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    flex-direction: row;
    align-items: center;
    min-height: 58px;
    padding: 9px 12px;
    background: rgba(246, 248, 252, 0.95);
  }

  .sidebar-toggle {
    display: inline-flex;
    flex: 0 0 auto;
    min-width: 44px;
    min-height: 44px;
    border-radius: 12px;
  }

  .topbar-title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 15px;
  }

  .topbar-user {
    flex: 0 1 auto;
    justify-content: flex-end;
    gap: 5px 8px;
    max-width: 46vw;
    font-size: 11px;
    line-height: 1.25;
  }

  .topbar-user span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .erp-content {
    width: 100%;
    padding: 14px 12px 24px;
  }

  .page-title,
  .page-title.row-between,
  .section-heading,
  .row-between {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .page-title h1,
  h1 {
    font-size: 24px;
  }

  .page-subtitle {
    font-size: 13px;
  }

  .dashboard-actions,
  .actions,
  .form-actions,
  .quick-links {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .actions .button,
  .form-actions .button,
  .form-actions button,
  .quick-links .button,
  .dashboard-actions .button {
    width: 100%;
  }

  .panel {
    overflow: visible;
    margin-bottom: 14px;
    padding: 16px;
    border-radius: 18px;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.05);
  }

  .dashboard-grid,
  .stats-grid,
  .placeholder-grid,
  .detail-grid,
  .core-metrics,
  .customer-risk-grid,
  .chart-grid,
  .activity-grid,
  .quick-entry-grid,
  .report-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .metric-card,
  .stat-card,
  .quick-entry,
  .report-card {
    min-height: auto;
    padding: 15px;
    border-radius: 16px;
  }

  .metric-card strong,
  .stat-card strong {
    font-size: 24px;
  }

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

  .search-form,
  .record-form,
  .mobile-friendly-form {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .search-form {
    padding: 14px;
    border-radius: 16px;
  }

  .search-form input,
  .record-form input,
  .record-form select,
  .record-form textarea,
  .document-form input,
  .document-form select,
  .document-form textarea {
    min-height: 44px;
    border-radius: 12px;
    font-size: 16px;
  }

  .mobile-friendly-form .form-actions.full,
  .record-form.mobile-friendly-form .form-actions {
    position: sticky;
    bottom: 0;
    z-index: 4;
    margin: 4px -16px -16px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    border-radius: 0 0 18px 18px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
  }

  .button,
  button {
    min-height: 44px;
    border-radius: 12px;
    font-size: 14px;
  }

  .button.small,
  .data-table .button.small {
    min-height: 36px;
  }

  .table-scroll {
    overflow: visible;
    border-radius: 0;
  }

  .data-table.responsive-card-table {
    display: block;
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  .data-table.responsive-card-table thead {
    display: none;
  }

  .data-table.responsive-card-table tbody,
  .data-table.responsive-card-table tr,
  .data-table.responsive-card-table td {
    display: block;
    width: 100%;
  }

  .data-table.responsive-card-table tr {
    margin: 0 0 12px;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.045);
  }

  .data-table.responsive-card-table td {
    display: grid;
    grid-template-columns: minmax(82px, 34%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 8px 0;
    border-bottom: 1px solid #eef2f7;
    overflow-wrap: anywhere;
  }

  .data-table.responsive-card-table td:last-child {
    border-bottom: 0;
  }

  .data-table.responsive-card-table td[data-label]::before {
    content: attr(data-label);
    color: #64748b;
    font-size: 12px;
    font-weight: 900;
  }

  .data-table.responsive-card-table td.empty {
    display: block;
    padding: 24px 12px !important;
    border: 1px dashed #bfdbfe;
    border-radius: 16px;
    background: #f8fbff;
    text-align: center !important;
  }

  .data-table.responsive-card-table tr:has(td.empty) {
    padding: 0;
    border: 0;
    box-shadow: none;
    background: transparent;
  }

  .number-cell,
  .money,
  .number,
  .actions-cell {
    text-align: left !important;
  }

  .actions-cell {
    display: flex !important;
    flex-wrap: wrap;
    gap: 8px;
  }

  .data-table td:last-child a:not(.button),
  .data-table.responsive-card-table a:not(.button) {
    min-height: 34px;
    margin: 2px 4px 2px 0;
    border-radius: 10px;
  }

  .customer-name-strong {
    font-size: 16px;
  }

  .badge,
  .tag {
    width: fit-content;
  }

  .empty,
  .empty-state {
    border-radius: 16px;
  }

  .empty-state {
    padding: 18px;
    text-align: left;
  }

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

  .photo-card {
    padding: 10px;
    border-radius: 16px;
  }

  .photo-card img {
    border-radius: 12px;
  }

  .auth-panel {
    width: min(100% - 28px, 460px);
    margin: 34px auto;
    padding: 22px;
    border-radius: 18px;
    box-shadow: var(--shadow-soft);
  }
}

@media (max-width: 430px) {
  .erp-content {
    padding-inline: 10px;
  }

  .topbar-user {
    max-width: 40vw;
    font-size: 10px;
  }

  .topbar-user span:nth-child(2) {
    display: none;
  }

  .page-title h1,
  h1 {
    font-size: 22px;
  }

  .panel {
    padding: 14px;
  }

  .metric-card strong,
  .stat-card strong {
    font-size: 22px;
  }

  .data-table.responsive-card-table td {
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 8px;
  }

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

  .mobile-friendly-form .form-actions.full,
  .record-form.mobile-friendly-form .form-actions {
    margin-inline: -14px;
    padding-inline: 14px;
  }
}

@media print {
  body {
    background: #ffffff;
    color: #111827;
  }

  .erp-sidebar,
  .erp-topbar,
  .messages,
  .print-hide,
  .button,
  button {
    display: none !important;
  }

  .erp-shell,
  .erp-workspace {
    display: block;
  }

  .erp-content,
  .container,
  .simple-container {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .panel {
    margin: 0 0 18px;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .data-table th,
  .data-table td {
    padding: 8px 6px;
    border: 1px solid #d1d5db;
  }
}
