:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --text: #0f172a;
  --muted: #5b6475;
  --line: #e3e8f2;
  --primary: #0f766e;
  --primary-soft: #dff4f1;
  --warning: #b45309;
  --danger: #b91c1c;
  --success: #047857;
  --sidebar: #111827;
  --sidebar-line: #1f2937;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 10%, #dff4f1 0, transparent 28%),
    radial-gradient(circle at 90% 5%, #e7f0ff 0, transparent 35%),
    var(--bg);
  display: flex;
  overflow: hidden;
}

.app {
  width: 100%;
  display: flex;
  min-height: 100vh;
}

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

.login-view {
  width: 100%;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(460px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 6px;
}

.login-card p {
  color: var(--muted);
  margin-bottom: 14px;
  font-size: 14px;
}

.field.light,
.select.light,
.textarea.light {
  color: #0f172a;
  background: #fff;
  border-color: var(--line);
}

.sidebar {
  width: 288px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: #d1d5db;
  border-right: 1px solid var(--sidebar-line);
  display: flex;
  flex-direction: column;
  z-index: 20;
  transition: transform 0.25s ease;
}

.brand {
  padding: 24px 20px;
  border-bottom: 1px solid var(--sidebar-line);
}

.brand h1 {
  color: #f8fafc;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.2px;
}

.brand p {
  margin-top: 4px;
  font-size: 12px;
  color: #9ca3af;
}

.nav {
  padding: 14px;
  display: grid;
  gap: 8px;
  overflow-y: auto;
}

.nav-btn {
  border: 0;
  background: transparent;
  color: #9ca3af;
  text-align: left;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-btn:hover {
  background: #1f2937;
  color: #e5e7eb;
}

.nav-btn.active {
  background: linear-gradient(135deg, #115e59, #0f766e);
  color: #f0fdfa;
  box-shadow: 0 8px 20px rgba(15, 118, 110, 0.35);
}

.nav-divider {
  height: 1px;
  background: #374151;
  margin: 16px 12px 8px 12px;
}

.nav-btn.nav-btn-danger {
  color: #f87171;
  font-weight: 600;
  margin-top: 8px;
}

.nav-btn.nav-btn-danger:hover {
  background: #7f1d1d;
  color: #fecaca;
}

.auth-panel {
  margin: auto 14px 14px;
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: var(--radius-md);
  padding: 12px;
  display: grid;
  gap: 8px;
}

.auth-panel h2 {
  font-size: 12px;
  color: #e5e7eb;
  font-weight: 700;
  margin-bottom: 2px;
}

.label {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.sep {
  border: 0;
  border-top: 1px solid #1f2937;
  margin: 6px 0;
}

.field,
.select,
.textarea {
  width: 100%;
  border-radius: 9px;
  border: 1px solid #334155;
  padding: 9px 10px;
  font-size: 13px;
  color: #e2e8f0;
  background: #111827;
  outline: none;
}

.textarea {
  min-height: 90px;
  resize: vertical;
}

.field:focus,
.select:focus,
.textarea:focus {
  border-color: #14b8a6;
}

.searchable-select {
  position: relative;
  width: 100%;
}

.searchable-select-native {
  position: absolute !important;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  width: 100%;
  height: 100%;
}

.searchable-select-input {
  padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 13px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.searchable-select.is-open .searchable-select-input {
  border-color: #14b8a6;
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.12);
}

.searchable-select-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 35;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow: auto;
  display: none;
}

.searchable-select.is-open .searchable-select-dropdown {
  display: block;
}

.searchable-select-list {
  padding: 6px;
  display: grid;
  gap: 4px;
}

.searchable-select-option,
.searchable-select-empty {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 9px 10px;
  text-align: left;
  font-size: 13px;
  background: transparent;
  color: var(--text);
}

.searchable-select-option {
  cursor: pointer;
}

.searchable-select-option:hover,
.searchable-select-option.is-selected {
  background: var(--primary-soft);
  color: var(--primary);
}

.searchable-select-option:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.searchable-select-empty {
  color: var(--muted);
}

.btn {
  border: 0;
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  color: #ecfeff;
  background: #0f766e;
}

.btn-subtle {
  color: #334155;
  background: #edf2f7;
}

.main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.menu-toggle {
  display: none;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.title-block h2 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.2px;
}

.title-block p {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

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

.chip {
  border-radius: 999px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  font-size: 12px;
  background: #fff;
  color: #1e293b;
  font-weight: 700;
}

.chip-button {
  cursor: pointer;
}

.health-popover {
  position: absolute;
  right: 18px;
  top: 58px;
  width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 10px;
  z-index: 20;
}

.api-route-popover {
  position: absolute;
  right: 18px;
  top: 58px;
  width: min(460px, calc(100vw - 36px));
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 10px;
  z-index: 20;
}

.health-popover h4 {
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 8px;
}

.api-route-popover h4 {
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 8px;
}

.health-popover-controls {
  margin-bottom: 8px;
}

.api-route-base {
  font-size: 12px;
  color: #334155;
  margin-bottom: 8px;
  padding: 7px 8px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fbff;
  word-break: break-all;
}

.health-popover-body {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: #334155;
  max-height: 220px;
  overflow: auto;
}

.api-route-popover-body {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: #334155;
  max-height: 220px;
  overflow: auto;
}

.health-popover-row {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 7px 8px;
  display: grid;
  gap: 2px;
}

.api-route-popover-row {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 7px 8px;
  display: grid;
  gap: 2px;
}

.health-popover-row strong {
  font-size: 12px;
}

.api-route-popover-row strong {
  font-size: 12px;
}

.content {
  padding: 16px;
  display: grid;
  gap: 16px;
}

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

.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow);
}

.kpi small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.kpi strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
  font-weight: 800;
}

.kpi span {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.card-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.card-head h3 {
  font-size: 14px;
  font-weight: 800;
}

.card-body {
  padding: 12px 14px;
  display: grid;
  gap: 10px;
}

.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.controls .field,
.controls .select,
.controls .textarea {
  color: #0f172a;
  background: #fff;
  border-color: var(--line);
  min-width: 150px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
}

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

th,
td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid #edf2f7;
  font-size: 13px;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fbff;
  color: #475569;
  font-weight: 800;
}

.status {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 800;
  border: 1px solid transparent;
}

.status.pending {
  background: #fff7ed;
  color: var(--warning);
  border-color: #fed7aa;
}

.status.delivered {
  background: #ecfdf5;
  color: var(--success);
  border-color: #a7f3d0;
}

.status.error {
  background: #fef2f2;
  color: var(--danger);
  border-color: #fecaca;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.alert {
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 13px;
  border: 1px solid;
}

.alert.info {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.alert.warn {
  background: #fff7ed;
  color: #9a3412;
  border-color: #fdba74;
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 10;
}

.overlay.show {
  display: block;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(15, 23, 42, 0.55);
  padding: 24px;
}

.modal-overlay.show {
  display: grid;
  place-items: center;
}

#idleModal {
  z-index: 40;
}

.modal {
  width: min(760px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

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

.modal-body {
  padding: 14px;
}

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

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

.loading {
  color: #334155;
  font-weight: 700;
  font-size: 13px;
}

.loading.is-refreshing::after {
  content: " Refreshing...";
  color: var(--primary);
  animation: refreshPulse 1.2s ease-in-out infinite;
}

@keyframes refreshPulse {
  0% { opacity: 0.45; }
  50% { opacity: 1; }
  100% { opacity: 0.45; }
}

.table-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.toast-stack {
  position: fixed;
  right: 14px;
  top: 14px;
  z-index: 60;
  display: grid;
  gap: 8px;
  max-width: min(360px, calc(100vw - 28px));
}

.toast {
  border: 1px solid;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow);
  transform: translateY(0);
  opacity: 1;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.info {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.toast.warn {
  background: #fff7ed;
  color: #9a3412;
  border-color: #fdba74;
}

.toast.hide {
  opacity: 0;
  transform: translateY(6px);
}

@media (max-width: 1200px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 992px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
  }

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

  .menu-toggle {
    display: inline-block;
  }

  .topbar-toggle {
    display: none;
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: var(--primary);
  }
}

@media (max-width: 768px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    padding: 10px 12px;
    flex-wrap: wrap;
  }

  .topbar-left {
    flex: 1;
    min-width: 150px;
  }

  .topbar-actions {
    display: none;
  }

  .topbar-actions.visible {
    display: flex;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--line);
    padding: 12px;
    gap: 8px;
    z-index: 100;
  }

  #appLogoutBtn {
    display: inline-flex !important;
  }

  .topbar-actions.visible .chip,
  .topbar-actions.visible .btn {
    width: 100%;
    text-align: center;
  }

  .topbar-toggle {
    display: flex !important;
  }

  .content {
    padding: 12px;
  }

  .title-block h2 {
    font-size: 18px;
  }

  .controls .field,
  .controls .select,
  .controls .btn,
  .controls .textarea {
    width: 100%;
  }

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

  .modal-overlay {
    padding: 12px;
  }
}

@media (max-width: 576px) {
  .title-block p {
    display: none;
  }

  .chip {
    width: 100%;
    text-align: center;
  }

  .topbar-actions.visible {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
  }
}

/* Invoice Modal Styles */
.invoice-modal {
  width: min(800px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.invoice-modal .modal-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.invoice-modal .modal-body {
  padding: 14px;
}

.invoice-modal .modal-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.invoice-container {
  font-family: Arial, sans-serif;
}

.invoice-header {
  margin-bottom: 20px;
  border-bottom: 2px solid #333;
  padding-bottom: 10px;
}

.invoice-header h2 {
  margin: 0 0 10px 0;
  color: #333;
}

.invoice-header p {
  margin: 5px 0;
  font-size: 14px;
}

.invoice-container h3 {
  margin: 20px 0 10px 0;
  border-bottom: 1px solid #ccc;
  padding-bottom: 5px;
  font-size: 16px;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 13px;
}

.invoice-table th,
.invoice-table td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

.invoice-table th {
  background-color: #f5f5f5;
  font-weight: bold;
}

.invoice-table tfoot td {
  font-weight: bold;
  background-color: #f9f9f9;
}

.invoice-summary {
  margin-top: 20px;
  padding: 15px;
  background-color: #f9f9f9;
  border-radius: 5px;
}

.invoice-summary .summary-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
}

.invoice-summary .balance-due {
  font-size: 1.2em;
  font-weight: bold;
  border-top: 2px solid #333;
  margin-top: 10px;
  padding-top: 10px;
  color: #b91c1c;
}

.invoice-footer {
  margin-top: 30px;
  text-align: center;
  color: #666;
  font-size: 0.9em;
}

/* Order Invoice Modal Styles */
.invoice-party-details {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  padding: 15px;
  background-color: #f9f9f9;
  border-radius: 8px;
}

.invoice-party-details .party-info,
.invoice-party-details .order-info {
  width: 48%;
}

.invoice-party-details h4 {
  margin: 0 0 10px 0;
  font-size: 14px;
}

.invoice-party-details p {
  margin: 3px 0;
  font-size: 13px;
}

.invoice-totals {
  margin-top: 20px;
  padding: 15px;
  background-color: #f9f9f9;
  border-radius: 5px;
  max-width: 300px;
  margin-left: auto;
}

.invoice-totals .total-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
}

.invoice-totals .grand-total {
  font-size: 1.2em;
  font-weight: bold;
  border-top: 2px solid #333;
  margin-top: 10px;
  padding-top: 10px;
  color: #b91c1c;
}

.invoice-notes {
  margin-top: 20px;
  padding: 10px;
  background-color: #fff7ed;
  border-radius: 5px;
}

/* Party Pricing Modal Styles */
.pricing-modal {
  width: min(700px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.pricing-modal .modal-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.pricing-modal .modal-body {
  padding: 14px;
}

.pricing-container {
  font-family: Arial, sans-serif;
}

.pricing-header {
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e2e8f0;
}

.pricing-header h3 {
  margin: 0 0 8px 0;
  color: #1e293b;
  font-size: 18px;
}

.pricing-header p {
  margin: 0;
  color: #64748b;
  font-size: 13px;
}

.pricing-form {
  margin-bottom: 20px;
  padding: 15px;
  background-color: #f8fafc;
  border-radius: 8px;
}

.pricing-list h4 {
  margin: 0 0 12px 0;
  color: #1e293b;
  font-size: 14px;
}

.pricing-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.pricing-table th,
.pricing-table td {
  border: 1px solid #e2e8f0;
  padding: 10px;
  text-align: left;
}

.pricing-table th {
  background-color: #f1f5f9;
  font-weight: bold;
  color: #475569;
}

.pricing-table td {
  color: #334155;
}

.no-pricing {
  padding: 20px;
  text-align: center;
  color: #64748b;
  background-color: #f8fafc;
  border-radius: 8px;
  font-size: 13px;
}

/* Dropdown Styles */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dropdown-arrow {
  font-size: 10px;
  transition: transform 0.2s ease;
}

.dropdown.open .dropdown-arrow {
  transform: rotate(180deg);
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 50;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-width: 200px;
  padding: 6px;
  display: none;
  margin-top: 4px;
}

.dropdown.open .dropdown-menu {
  display: block;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  background: transparent;
  text-align: left;
  font-size: 13px;
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
}

.dropdown-item:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.dropdown-divider {
  height: 1px;
  background: var(--line);
  margin: 6px 0;
}
