:root {
  color-scheme: light;
  --bg: #fff8e6;
  --surface: #ffffff;
  --surface-strong: #fff1b7;
  --text: #211613;
  --muted: #765d54;
  --line: #f0d8ab;
  --primary: #d8232a;
  --primary-dark: #a9151b;
  --accent: #ffd600;
  --accent-dark: #dba900;
  --danger: #a9151b;
  --shadow: 0 18px 50px rgba(128, 34, 24, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
}

body.login-active {
  overflow: hidden;
}

body.login-active .app-shell {
  filter: blur(2px);
  pointer-events: none;
  user-select: none;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 22px;
  background: rgba(255, 248, 230, 0.94);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(33, 22, 19, 0.38);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  display: grid;
  gap: 16px;
  width: min(100%, 520px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.settings-note {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.settings-status,
.connection-status,
.save-status {
  margin-bottom: 0;
  border-radius: 8px;
  padding: 10px 12px;
  background: #fffdf4;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.connection-status {
  min-height: 42px;
  display: grid;
  align-content: center;
  border: 1px solid var(--line);
  padding: 0 12px;
}

.settings-status:empty {
  display: none;
}

.save-status:empty {
  display: none;
}

.connection-status.success,
.settings-status.success,
.save-status.success {
  background: #fff1b7;
  color: var(--primary-dark);
}

.connection-status.error,
.settings-status.error,
.save-status.error {
  background: #fff1e8;
  color: var(--danger);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-actions .primary-button {
  width: auto;
  margin-top: 0;
}

.invoice-preview-card {
  width: min(920px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
}

.invoice-preview-frame {
  width: 100%;
  height: min(68vh, 720px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

body.login-active .login-screen {
  display: grid;
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(100%, 430px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-logo {
  width: min(280px, 100%);
  height: auto;
  justify-self: center;
  filter: drop-shadow(0 10px 18px rgba(33, 22, 19, 0.12));
}

.login-card h1 {
  font-size: 25px;
}

.login-bismillah {
  margin: 0 0 8px;
  font-size: 16px;
  line-height: 1.5;
  font-weight: 700;
  text-align: center;
  direction: rtl;
}

.login-error {
  min-height: 20px;
  margin-bottom: 0;
  color: var(--danger);
  font-size: 14px;
  font-weight: 700;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #d8232a;
  color: #f8fbf5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-logo {
  width: 58px;
  height: 42px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  padding: 4px;
  box-shadow: 0 6px 18px rgba(33, 22, 19, 0.18);
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: #fff4bd;
  margin-top: 2px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  background: transparent;
  color: #fff8e6;
  text-align: left;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(33, 22, 19, 0.18);
}

.master-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.master-tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
}

.master-tab.active {
  background: var(--surface-strong);
  color: var(--accent-strong);
  border-color: var(--accent);
}

.main {
  min-width: 0;
  padding: 24px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.12;
}

h2 {
  margin-bottom: 4px;
  font-size: 18px;
  line-height: 1.25;
}

.top-actions {
  align-items: center;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.active-user {
  min-height: 42px;
  display: grid;
  align-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.primary-button,
.ghost-button,
.danger-button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 16px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 700;
}

.small-button {
  min-height: 36px;
  padding: 0 12px;
}

.primary-button {
  width: 100%;
  margin-top: 16px;
  background: var(--primary);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary-dark);
}

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

.ghost-button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.danger-button {
  background: #fff1e8;
  border-color: #efb0a7;
  color: var(--danger);
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 26px;
  line-height: 1.1;
}

.dashboard-grid,
.split-layout,
.master-grid,
.backup-reset-grid {
  display: grid;
  gap: 18px;
}

.dashboard-grid {
  grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.8fr);
}

.split-layout {
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  align-items: start;
}

.internal-finance-stack {
  display: grid;
  gap: 18px;
}

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

.backup-reset-grid {
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  align-items: start;
}

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

.full-width-button {
  width: 100%;
  margin-top: 16px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

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

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

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

.order-items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}

.order-items-header h3,
.order-summary h3 {
  margin: 0;
  font-size: 15px;
}

.order-items {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.order-item {
  display: grid;
  grid-template-columns: minmax(150px, 1.3fr) minmax(78px, 0.55fr) minmax(105px, 0.8fr) 42px;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffdf4;
}

.order-item .product-suggestions {
  grid-column: 1 / -1;
  order: 2;
}

.icon-button {
  min-height: 42px;
  border: 1px solid #efb0a7;
  border-radius: 8px;
  background: #fff1e8;
  color: var(--danger);
  cursor: pointer;
  font-weight: 900;
}

.order-summary {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-strong);
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 14px;
  margin-top: 12px;
}

.summary-grid span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary-grid strong {
  text-align: right;
}

.summary-section-title,
.summary-items {
  grid-column: 1 / -1;
}

.summary-section-title {
  margin-top: 6px;
  color: var(--text);
}

.summary-items {
  display: grid;
  gap: 6px;
  margin-bottom: 4px;
  color: var(--text);
  font-size: 14px;
}

.summary-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.summary-item span {
  color: var(--text);
  font-weight: 700;
}

.summary-item strong {
  white-space: nowrap;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus {
  outline: 3px solid rgba(216, 35, 42, 0.18);
  border-color: var(--primary);
}

input[readonly] {
  background: #fff1b7;
  color: var(--primary-dark);
  cursor: not-allowed;
  font-weight: 800;
}

.autocomplete-list {
  grid-column: 1 / -1;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.autocomplete-option {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 8px 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.autocomplete-option:last-child {
  border-bottom: 0;
}

.autocomplete-option:hover,
.autocomplete-option:focus {
  background: var(--surface-strong);
  outline: 0;
}

.autocomplete-option strong,
.autocomplete-option span {
  display: block;
}

.autocomplete-option span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.search-input {
  max-width: 260px;
}

.invoice-filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.action-select {
  min-width: 112px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--primary-dark);
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--surface-strong);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.warning {
  background: #211613;
  color: var(--accent);
}

.bar-chart {
  display: grid;
  gap: 12px;
  min-height: 260px;
}

.bar-row {
  display: grid;
  grid-template-columns: 120px 1fr 92px;
  align-items: center;
  gap: 12px;
}

.bar-track {
  height: 16px;
  border-radius: 999px;
  background: #ffe999;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.follow-up-list {
  display: grid;
  gap: 10px;
}

.follow-up-item {
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-strong);
}

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

.follow-up-item span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1120px) {
  .metric-grid,
  .dashboard-grid,
  .split-layout,
  .master-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split-layout {
    align-items: stretch;
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

  .brand {
    margin-bottom: 14px;
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-item {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
  }

  .main {
    padding: 18px 14px 28px;
  }

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

  .top-actions {
    width: 100%;
    justify-content: stretch;
  }

  .top-actions button {
    flex: 1;
  }

  .connection-status,
  .active-user {
    width: 100%;
  }

  .metric-grid,
  .dashboard-grid,
  .split-layout,
  .master-grid,
  .backup-reset-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

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

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

  .panel-header {
    display: grid;
  }

  .search-input {
    max-width: none;
  }

  .invoice-filters {
    justify-content: stretch;
  }

  .bar-row {
    grid-template-columns: 82px 1fr;
  }

  .bar-row strong {
    grid-column: 1 / -1;
  }
}

@media (max-width: 460px) {
  h1 {
    font-size: 25px;
  }

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

  .panel,
  .metric {
    padding: 14px;
  }
}
