:root {
  color-scheme: light;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: #071d35;
  background: #edf6ff;
  --blue: #1f7feb;
  --blue-light: #5baeff;
  --line: #cfe0f1;
  --muted: #5d7693;
  --surface: #ffffff;
  --success: #008f69;
  --danger: #c43e4f;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 1px 1px, rgba(46,139,255,.13) 1px, transparent 1.2px) 0 0 / 24px 24px, #edf6ff; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-header {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  min-height: 76px; padding: 12px clamp(18px,4vw,54px); color: #fff;
  background: linear-gradient(100deg,#1769d2,#2e8bff 55%,#67b7ff); box-shadow: 0 8px 24px rgba(27,104,190,.2);
}
.app-header h1 { margin: 2px 0 0; font-size: 24px; letter-spacing: 0; }
.eyebrow { margin: 0; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; opacity: .86; }
.header-actions { display: flex; gap: 8px; }
.header-button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; border: 1px solid rgba(255,255,255,.62); border-radius: 9px; padding: 8px 14px; color: #fff; background: rgba(255,255,255,.12); font-size: 12px; font-weight: 800; text-decoration: none; }
.header-button:hover { background: rgba(255,255,255,.2); }

.workspace { display: grid; grid-template-columns: minmax(320px, .76fr) minmax(520px, 1.45fr); min-height: calc(100vh - 76px); }
.order-browser { min-width: 0; padding: 24px; border-right: 1px solid var(--line); background: rgba(255,255,255,.82); backdrop-filter: blur(10px); }
.order-detail { min-width: 0; padding: 28px clamp(22px,3vw,48px); }
.toolbar { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 9px; }
.order-views { display: flex; gap: 8px; margin-bottom: 16px; }
.order-view { min-height: 40px; padding: 8px 13px; border: 1px solid var(--line); border-radius: 8px; color: #0a2540; background: #fff; font-size: 12px; font-weight: 800; }
.order-view.active { color: #fff; border-color: #176fe1; background: #176fe1; }
.load-more { width: 100%; margin-top: 12px; }
input, select { min-height: 44px; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color: #071d35; background: #fff; outline: none; }
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(46,139,255,.14); }
.primary-button, .secondary-button { min-height: 44px; padding: 10px 18px; border-radius: 9px; font-size: 12px; font-weight: 800; letter-spacing: .3px; }
.primary-button { border: 0; color: #fff; background: linear-gradient(135deg,#52a8ff,#2e8bff 48%,#176fe1); box-shadow: 0 7px 18px rgba(46,139,255,.2); }
.secondary-button { border: 1px solid var(--line); color: #0a2540; background: #f4f7fa; }
.primary-button:disabled { cursor: not-allowed; opacity: .55; }

.segments { display: grid; grid-template-columns: repeat(3,1fr); margin-top: 14px; padding: 3px; border: 1px solid var(--line); border-radius: 9px; background: #edf3f8; }
.segment { min-height: 38px; border: 0; border-radius: 6px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 750; }
.segment.active { color: #0a5bbd; background: #fff; box-shadow: 0 2px 8px rgba(28,73,115,.12); }
.status-line { min-height: 18px; margin: 16px 2px 10px; color: var(--muted); font-size: 12px; }
.order-list { display: grid; gap: 7px; }
.order-row { width: 100%; padding: 14px; border: 1px solid var(--line); border-radius: 8px; text-align: left; color: #071d35; background: #fff; }
.order-row:hover, .order-row.active { border-color: #6bb4ff; background: #f0f7ff; }
.order-row-top { display: flex; justify-content: space-between; gap: 12px; font-weight: 850; }
.order-row-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; color: var(--muted); font-size: 12px; }

.empty-state { display: grid; place-content: center; min-height: 60vh; text-align: center; color: var(--muted); }
.empty-state strong { margin-bottom: 7px; color: #0a2540; font-size: 22px; }
.detail-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.detail-heading h2 { margin: 3px 0 5px; font-size: 28px; }
.detail-heading p { margin: 0; color: var(--muted); }
.status-badge { display: inline-flex; align-items: center; min-height: 28px; padding: 5px 9px; border-radius: 999px; color: #05634d; background: #dff9ee; font-size: 11px; font-weight: 850; text-transform: uppercase; }
.detail-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 0 38px; margin-top: 24px; }
.detail-section { padding: 18px 0; border-bottom: 1px solid var(--line); }
.detail-section.full { grid-column: 1 / -1; }
.detail-section h3 { margin: 0 0 12px; color: #0c5fbd; font-size: 12px; letter-spacing: .7px; text-transform: uppercase; }
.detail-section p { margin: 5px 0; line-height: 1.55; }
.label { color: var(--muted); font-size: 12px; }
.product-line { display: grid; grid-template-columns: 1fr auto; gap: 14px; padding: 8px 0; border-bottom: 1px dashed #d9e5f0; }
.product-line:last-child { border: 0; }
.email-state { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.state-value { font-weight: 800; }
.state-value.failed { color: var(--danger); }
.state-value.delivered { color: var(--success); }
.retry-button { border: 1px solid #a8c9e9; border-radius: 7px; padding: 7px 10px; color: #0a5bbd; background: #fff; font-size: 11px; font-weight: 800; }
.shipment-form { display: grid; grid-template-columns: 150px minmax(190px,1fr) auto; align-items: end; gap: 10px; }
.field { display: grid; gap: 6px; }
.field span { color: var(--muted); font-size: 12px; font-weight: 700; }
.tracking-preview { margin-top: 12px; color: var(--muted); font-size: 12px; word-break: break-all; }
.tracking-preview a { color: #096bd5; }

.fulfillment-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.fulfillment-label { margin: 0; color: var(--muted); font-size: 12px; }
.fulfillment-copy-button { min-height: 36px; padding: 7px 14px; }
.fulfillment-output {
  margin: 0; padding: 18px; border: 1px solid #d7e2ec; border-radius: 8px;
  overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere;
  color: #17283a; background: #f2f5f7;
  font: 600 13px/1.62 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}
.clipboard-fallback { position: fixed; left: -9999px; top: 0; width: 1px; height: 1px; opacity: 0; }

.support-workspace { grid-template-columns: minmax(340px,.86fr) minmax(520px,1.5fr); }
.support-workspace .segments { grid-template-columns: repeat(4,minmax(0,1fr)); }
.support-list { display: grid; grid-template-columns: minmax(0,1fr); min-width: 0; gap: 7px; }
.support-row { min-width: 0; max-width: 100%; width: 100%; overflow: hidden; padding: 14px; border: 1px solid var(--line); border-radius: 8px; text-align: left; color: #071d35; background: #fff; }
.support-row:hover, .support-row.active { border-color: #6bb4ff; background: #f0f7ff; }
.support-row.unread .support-row-subject { font-weight: 900; }
.support-row-top, .support-row-meta { display: flex; justify-content: space-between; gap: 12px; }
.support-row-top { align-items: baseline; }
.support-row-sender { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 800; }
.support-row-date { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
.support-row-subject { margin-top: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.support-row-preview { margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 12px; line-height: 1.45; text-overflow: ellipsis; white-space: nowrap; }
.support-workspace .detail-heading h2 { overflow-wrap: anywhere; }
.support-heading-actions { display: flex; align-items: center; gap: 10px; }
.support-mute-button { min-height: 34px; padding: 7px 10px; white-space: nowrap; }
.unread-dot { display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 3px rgba(46,139,255,.13); }
.support-meta { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; margin-top: 18px; }
.support-meta dt { color: var(--muted); font-size: 12px; }
.support-meta dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }
.message-body, .reply-body {
  margin: 0; padding: 18px; border: 1px solid #d7e2ec; border-radius: 8px;
  white-space: pre-wrap; overflow-wrap: anywhere; color: #17283a; background: #fff;
  font: 500 14px/1.65 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}
.reply-history { display: grid; gap: 12px; }
.reply-card { padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.78); }
.reply-card-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; color: var(--muted); font-size: 11px; }
.reply-body { padding: 0; border: 0; background: transparent; }
.reply-form { display: grid; gap: 10px; }
.reply-form textarea { width: 100%; min-height: 170px; resize: vertical; border: 1px solid var(--line); border-radius: 8px; padding: 13px; color: #071d35; background: #fff; font: 500 14px/1.55 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; outline: none; }
.reply-form textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(46,139,255,.14); }
.reply-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.reply-recipient { min-width: 0; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

dialog { width: min(520px,calc(100% - 28px)); border: 1px solid var(--line); border-radius: 12px; padding: 0; box-shadow: 0 24px 80px rgba(7,29,53,.28); }
dialog::backdrop { background: rgba(7,29,53,.46); }
.dialog-content { padding: 26px; }
.dialog-content h2 { margin: 0 0 10px; }
.dialog-content p { color: var(--muted); line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 24px; }
.toast { position: fixed; right: 20px; bottom: 20px; max-width: min(420px,calc(100% - 40px)); padding: 13px 16px; border-radius: 8px; color: #fff; background: #071d35; box-shadow: 0 14px 38px rgba(7,29,53,.25); opacity: 0; pointer-events: none; transform: translateY(8px); transition: .18s ease; }
.toast.visible { opacity: 1; transform: none; }

.login-page { display: grid; min-height: 100vh; place-items: center; padding: 22px; }
.login-shell { width: min(100%, 430px); }
.login-panel { padding: clamp(28px,6vw,44px); border: 1px solid var(--line); border-radius: 18px; background: rgba(255,255,255,.94); box-shadow: 0 24px 70px rgba(34,108,188,.18); }
.login-brand { display: inline-block; margin: 0 0 18px; color: #0a65ca; font-size: 12px; font-weight: 850; letter-spacing: .7px; text-transform: uppercase; }
.login-panel h1 { margin: 0; font-size: clamp(28px,7vw,38px); letter-spacing: 0; }
.login-copy { margin: 12px 0 26px; color: var(--muted); line-height: 1.55; }
.login-form { display: grid; gap: 16px; }
.login-button { width: 100%; margin-top: 3px; }
.login-status { min-height: 20px; margin: 0; color: var(--danger); font-size: 12px; line-height: 1.5; }

.access-workspace { min-height: calc(100vh - 76px); padding: clamp(18px,4vw,54px); }
.access-panel { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.94); box-shadow: 0 18px 52px rgba(31,127,235,.12); }
.access-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 24px 26px 8px; }
.access-heading h2 { margin: 0; font-size: 23px; }
.access-heading p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.access-panel > .status-line { margin: 12px 26px; }
.access-table-wrap { overflow-x: auto; }
.access-table { width: 100%; border-collapse: collapse; text-align: left; }
.access-table th, .access-table td { padding: 13px 16px; border-top: 1px solid var(--line); vertical-align: top; font-size: 12px; }
.access-table th { color: var(--muted); background: #f3f8fd; font-size: 10px; letter-spacing: .6px; text-transform: uppercase; }
.access-table td { color: #17283a; }
.access-event { font-weight: 850; }
.access-event.login_success { color: var(--success); }
.access-event.login_failed, .access-event.login_blocked { color: var(--danger); }
.access-agent { min-width: 260px; max-width: 440px; overflow-wrap: anywhere; }
.access-empty { padding: 34px !important; text-align: center; color: var(--muted) !important; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .order-browser { border-right: 0; border-bottom: 1px solid var(--line); }
  .order-detail { padding: 24px; }
}
@media (max-width: 620px) {
  .app-header { min-height: 68px; }
  .app-header { align-items: flex-start; flex-direction: column; gap: 10px; }
  .header-actions { width: 100%; overflow-x: auto; }
  .header-button { flex: 0 0 auto; }
  .workspace { min-height: calc(100vh - 68px); }
  .order-browser, .order-detail { padding: 16px; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-section.full { grid-column: auto; }
  .shipment-form { grid-template-columns: 1fr; }
  .detail-heading { align-items: flex-start; flex-direction: column; gap: 10px; }
  .support-meta { grid-template-columns: 1fr; gap: 3px; }
  .support-meta dd { margin-bottom: 8px; }
  .reply-actions { align-items: stretch; flex-direction: column; }
  .support-heading-actions { align-items: flex-start; flex-wrap: wrap; }
  .access-workspace { min-height: calc(100vh - 68px); padding: 14px; }
  .access-heading { padding: 20px 18px 8px; }
  .access-panel > .status-line { margin-inline: 18px; }
}
