/**
 * All My Shipping — professional UI layer
 * Scoped enhancements only. Does NOT rewrite React layout or break Tailwind positioning.
 */

:root {
  --brand-maroon: #AE2129;
  --brand-blue: #161C34;
  --ams-primary: #AE2129;
  --ams-secondary: #161C34;
  --ams-sidebar: #161C34;
  --ams-button: #AE2129;
  --ams-text: #161C34;
  --ams-surface: #ffffff;
  --ams-muted: #646978;
  --ams-border: #E3E5EA;
  --ams-soft: #F5F7FC;
  --crimson: var(--ams-primary);
  --navy: var(--ams-secondary);
  --color-crimson: #AE2129;
  --color-navy: #161C34;
  --color-primary: #161C34;
  --color-background: #F5F5F3;
  --color-card: #ffffff;
  --color-foreground: #161C34;
  --background: #F5F5F3;
  --card: #ffffff;
}

/* Soft page atmosphere */
body {
  background-color: #F5F5F3;
  color: var(--ams-text);
}

/* -------- Enhancement workspace (in-flow, no overlap) -------- */
.ams-workspace {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 16px 20px 28px;
  margin: 0;
  clear: both;
}

.ams-section {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  max-width: 1100px;
  margin: 16px auto 24px;
  box-sizing: border-box;
  background: var(--ams-surface);
  border: 1px solid var(--ams-border);
  border-radius: 22px;
  box-shadow: 0 18px 45px rgba(22, 28, 52, 0.08), 0 5px 14px rgba(22, 28, 52, 0.05);
  padding: 20px 22px;
  color: var(--ams-text);
  font-family: Inter, Manrope, "IBM Plex Sans", Tahoma, system-ui, sans-serif;
}

.ams-section h1,
.ams-section h2,
.ams-section h3 {
  margin: 0 0 6px;
  color: var(--ams-secondary);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.ams-section h1 { font-size: 1.35rem; }
.ams-section h2 { font-size: 1.1rem; }
.ams-section .ams-hint {
  margin: 0 0 16px;
  color: var(--ams-muted);
  font-size: 0.875rem;
  line-height: 1.45;
}

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

.ams-section-header a {
  color: var(--ams-primary);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

/* Professional form grid */
.ams-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
  align-items: start;
}

.ams-form-grid .ams-span-2,
.ams-form-grid .ams-wide { grid-column: 1 / -1; }

.ams-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.ams-field > span,
.ams-section label:not(.ams-check) {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #475569;
  margin: 0;
}

.ams-section input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.ams-section select,
.ams-section textarea,
.ams-modal input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.ams-modal select,
.ams-modal textarea,
.ams-toolbar input {
  width: 100%;
  box-sizing: border-box;
  min-height: 40px;
  border: 1px solid var(--ams-border);
  border-radius: 10px;
  padding: 9px 12px;
  background: #fff;
  color: var(--ams-text);
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ams-section textarea,
.ams-modal textarea {
  min-height: 84px;
  resize: vertical;
}

.ams-section select[multiple] {
  min-height: 110px;
  padding: 8px;
}

.ams-section input:focus,
.ams-section select:focus,
.ams-section textarea:focus,
.ams-modal input:focus,
.ams-modal select:focus,
.ams-modal textarea:focus {
  outline: 0;
  border-color: color-mix(in srgb, var(--ams-primary) 55%, #fff);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ams-primary) 14%, transparent);
}

.ams-check {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem !important;
  font-weight: 600 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  color: var(--ams-text) !important;
  margin-top: 8px;
}

.ams-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--ams-border);
}

.ams-section button,
.ams-modal button,
.ams-toolbar button,
.ams-utility-bar a.ams-chip {
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 700;
  font-size: 0.875rem;
  cursor: pointer;
  background: var(--ams-button);
  color: #fff;
  text-decoration: none;
  line-height: 1.2;
}

.ams-section button.secondary,
.ams-modal button.secondary,
.ams-toolbar button.secondary {
  background: #e8edf3;
  color: #0f172a;
}

.ams-section button:hover,
.ams-modal button:hover,
.ams-toolbar button:hover {
  filter: brightness(0.97);
}

.ams-status {
  font-size: 0.8rem;
  color: var(--ams-muted);
  min-height: 1.1em;
}

.ams-split {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.ams-card {
  background: #fff;
  border: 1px solid var(--ams-border);
  border-radius: 12px;
  padding: 14px;
}

.ams-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.ams-table th,
.ams-table td {
  border-bottom: 1px solid var(--ams-border);
  padding: 10px 8px;
  text-align: start;
  vertical-align: top;
}

.ams-table th {
  color: #475569;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--ams-soft);
}

/* Utility bar removed — language is chosen via #ams-lang-gate, not the header square */

/* Inline row actions next to Open/View */
.ams-row-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-inline-start: 8px;
  vertical-align: middle;
}

.ams-row-btn {
  appearance: none;
  border: 1px solid #dbe1ea;
  background: #fff;
  color: #0f172a;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.2;
}

.ams-row-btn:hover {
  border-color: var(--ams-primary);
  color: var(--ams-primary);
}

.ams-row-btn:not(.secondary) {
  background: var(--ams-button);
  border-color: var(--ams-button);
  color: #fff;
}

.ams-row-btn:not(.secondary):hover {
  filter: brightness(0.96);
  color: #fff;
}

.ams-row-btn.secondary {
  background: #f1f5f9;
}

/* Hide legacy utility bar if cached HTML somehow still mounts it */
#ams-utility-bar { display: none !important; }
#ams-lang-toggle { display: none !important; }
#ams-admin-shortcuts { display: none !important; }
#ams-header-lang,
#ams-header-lang-wrap { display: none !important; }

/* Workspace pages should not cover the sidebar.
   WhatsApp (.ams-wa-root) is hosted in #ams-wa-slot and Freight (.ams-frt-root)
   in #ams-frt-slot — do not force inset:auto, which previously dumped overlays
   at the bottom of the page. */
.ams-workspace:not(.ams-wa-root):not(.ams-frt-root) {
  position: relative !important;
  inset: auto !important;
  z-index: 1 !important;
  max-width: 100%;
}
.ams-wa-root.ams-workspace,
.ams-frt-root.ams-workspace {
  position: relative !important;
  z-index: 1 !important;
  max-width: 100%;
}

.ams-section {
  position: relative !important;
  z-index: 1 !important;
}

/* Inline toolbar for quote/invoice actions — not floating over content */
.ams-toolbar {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  width: 100%;
  max-width: 1100px;
  margin: 12px auto 8px;
  padding: 12px 14px;
  box-sizing: border-box;
  background: #fff;
  border: 1px solid var(--ams-border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
}

.ams-toolbar input {
  flex: 1 1 220px;
  min-width: 180px;
}

/* Modal centered overlay — only when editing */
.ams-modal {
  position: fixed;
  inset: 0;
  z-index: 10050;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.ams-modal .box {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  width: min(860px, 96vw);
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
}

.ams-items {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  margin-top: 8px;
}

.ams-items th,
.ams-items td {
  border: 1px solid var(--ams-border);
  padding: 6px;
}

/* Theme / welcome drawer — closed by default, no permanent overlap */
#ams-brand-tools-toggle {
  position: fixed;
  inset-inline-end: 16px;
  bottom: 16px;
  z-index: 40;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: var(--ams-secondary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.2);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
}

#ams-brand-drawer {
  position: fixed;
  inset-inline-end: 16px;
  bottom: 64px;
  z-index: 41;
  width: min(400px, calc(100vw - 28px));
  max-height: min(72vh, 640px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--ams-border);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.2);
  padding: 14px;
  display: none;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
}

#ams-brand-drawer.open { display: block; }

/* Chatbot — public only, stays clear of admin */
#ams-chat-toggle {
  z-index: 45 !important;
}
#ams-chat-chooser {
  z-index: 46 !important;
}
body.ams-public button[data-ams-hidden-chat-fab],
body.ams-public a[data-ams-hidden-chat-fab] {
  display: none !important;
}

html.ams-ar,
html[dir="rtl"] .ams-section,
html[dir="rtl"] .ams-toolbar,
html[dir="rtl"] .ams-workspace {
  font-family: Tahoma, "Segoe UI", sans-serif;
}

html[dir="rtl"] .ams-section label:not(.ams-check),
html[dir="rtl"] .ams-table th,
html[dir="rtl"] .ams-table td {
  text-align: right;
}

.ams-workspace:not(.ams-wa-root) input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.ams-workspace:not(.ams-wa-root) select,
.ams-workspace:not(.ams-wa-root) textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 40px;
  border: 1px solid var(--ams-border);
  border-radius: 10px;
  padding: 9px 12px;
  background: #fff;
  color: var(--ams-text);
  font: inherit;
}

.ams-workspace:not(.ams-wa-root) label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #475569;
  margin: 10px 0 6px;
}

.ams-workspace label.ams-field > span { margin: 0; }
.ams-workspace label.ams-field { margin: 0; }
.ams-workspace .ams-card label { margin-top: 0; }

.ams-audience-only {
  border: 0;
  margin: 0;
  padding: 0;
}

.ams-audience-only legend {
  margin-bottom: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #475569;
}

.ams-audience-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ams-audience-checks label.ams-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 8px 11px;
  border: 1px solid var(--ams-border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  text-transform: none;
}

.ams-workspace h1 {
  margin: 0;
  font-size: 1.4rem;
  color: var(--ams-secondary);
}

.ams-workspace > .ams-card,
.ams-workspace .ams-card {
  background: #fff;
  border: 1px solid var(--ams-border);
  border-radius: 12px;
  padding: 16px;
}

@media (max-width: 900px) {
  header [title="PDF Export / Print"],
  header [title="CSV / Excel Export"],
  header [title="Email Sharing"] {
    display: none !important;
  }
  #ams-utility-bar { position: relative; }
  #ams-brand-tools-toggle { bottom: 12px; inset-inline-end: 12px; }
  #ams-software-update-panel > div:nth-child(2) {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  #ams-software-update-panel {
    margin: 12px !important;
    max-width: calc(100vw - 24px);
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
