:root {
  --ag-orange:      #fd7200;
  --ag-orange-pale: #fff3e6;
  --ag-bg:          #f3f4f6;
  --ag-surface:     #ffffff;
  --ag-border:      #e5e7eb;
  --ag-text:        #111827;
  --ag-muted:       #6b7280;
  --ag-nav-bg:      #1f2937;
  --ag-nav-text:    #f9fafb;
  --ag-radius:      10px;
  --ag-shadow:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body.agent-body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ag-text);
  background: var(--ag-bg);
  -webkit-font-smoothing: antialiased;
}

.agent-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.5rem;
  height: 56px;
  background: var(--ag-nav-bg);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 rgba(255,255,255,.06);
}

.agent-nav__logo {
  font-weight: 700;
  font-size: 1rem;
  color: var(--ag-orange);
  text-decoration: none;
  letter-spacing: -.02em;
  flex-shrink: 0;
}

.agent-nav__links {
  display: flex;
  gap: .25rem;
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
}

.agent-nav__links a {
  display: inline-block;
  padding: .35rem .8rem;
  border-radius: 6px;
  font-size: .875rem;
  font-weight: 500;
  color: var(--ag-nav-text);
  text-decoration: none;
  transition: background .15s;
}

.agent-nav__links a:hover,
.agent-nav__links a[aria-current="page"] {
  background: rgba(255,255,255,.1);
}

.agent-nav__logout {
  font-size: .8rem;
  font-weight: 500;
  color: var(--ag-muted);
  text-decoration: none;
  padding: .35rem .75rem;
  border-radius: 6px;
  transition: background .15s, color .15s;
  margin-left: auto;
  white-space: nowrap;
}

.agent-nav__logout:hover {
  background: rgba(255,255,255,.08);
  color: #f9fafb;
}

.agent-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
}

.agent-flash {
  padding: .875rem 1.125rem;
  border-radius: var(--ag-radius);
  margin-bottom: 1.25rem;
  font-size: .9rem;
  font-weight: 500;
}

.agent-flash--success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

.agent-flash--error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.agent-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .6rem 1.2rem;
  border: none;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}

.agent-btn:active { transform: scale(.98); }
.agent-btn:disabled { opacity: .5; cursor: not-allowed; }

.agent-btn--primary  { background: var(--ag-orange); color: #fff; }
.agent-btn--secondary { background: #e5e7eb; color: var(--ag-text); }
.agent-btn--success  { background: #10b981; color: #fff; }
.agent-btn--danger   { background: #ef4444; color: #fff; }
.agent-btn--xs       { padding: .25rem .6rem; font-size: .78rem; border-radius: 5px; }
.agent-btn--lg       { padding: .85rem 1.75rem; font-size: 1rem; border-radius: 10px; }

.agent-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 56px);
  padding: 1rem;
}

.agent-login__card {
  background: var(--ag-surface);
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
}

.agent-login__title {
  margin: 0 0 1.75rem;
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  color: var(--ag-text);
}

.agent-login__form .agent-btn {
  width: 100%;
  margin-top: .5rem;
  padding: .75rem;
  font-size: 1rem;
}

.agent-field {
  margin-bottom: 1rem;
}

.agent-field label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: .35rem;
  color: var(--ag-text);
}

.agent-field input,
.agent-field textarea,
.agent-field select {
  width: 100%;
  padding: .6rem .85rem;
  border: 1.5px solid var(--ag-border);
  border-radius: 8px;
  font-size: .9rem;
  font-family: inherit;
  background: #fff;
  color: var(--ag-text);
  transition: border-color .15s;
}

.agent-field input:focus,
.agent-field textarea:focus,
.agent-field select:focus {
  outline: none;
  border-color: var(--ag-orange);
}

.agent-page-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.agent-page-header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.agent-back {
  font-size: .85rem;
  font-weight: 600;
  color: var(--ag-muted);
  text-decoration: none;
  padding: .3rem .65rem;
  border-radius: 6px;
  transition: background .15s;
  white-space: nowrap;
}

.agent-back:hover { background: var(--ag-border); }

.agent-dashboard__header h1 {
  margin: 0 0 1.5rem;
  font-size: 1.35rem;
  font-weight: 700;
}

.agent-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.agent-stat-card {
  background: var(--ag-surface);
  border-radius: var(--ag-radius);
  box-shadow: var(--ag-shadow);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
}

.agent-stat-card__value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--ag-orange);
  line-height: 1;
}

.agent-stat-card__label {
  font-size: .8rem;
  color: var(--ag-muted);
  font-weight: 500;
}

.agent-section {
  background: var(--ag-surface);
  border-radius: var(--ag-radius);
  box-shadow: var(--ag-shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}

.agent-section h2 {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 700;
}

.agent-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

.agent-table th {
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ag-muted);
  padding: .5rem .75rem;
  border-bottom: 2px solid var(--ag-border);
}

.agent-table td {
  padding: .75rem;
  border-bottom: 1px solid var(--ag-border);
  color: var(--ag-text);
}

.agent-table tbody tr:last-child td { border-bottom: none; }

.agent-table tbody tr:hover td { background: #f9fafb; }

.agent-table__mono {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: .8rem;
  color: var(--ag-muted);
}

.agent-badge {
  display: inline-flex;
  align-items: center;
  padding: .15rem .55rem;
  border-radius: 100px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  white-space: nowrap;
  background: #e5e7eb;
  color: var(--ag-muted);
}

.agent-badge--lg {
  font-size: .8rem;
  padding: .25rem .75rem;
}

.agent-badge--onboarding       { background: #dbeafe; color: #1e40af; }
.agent-badge--pending_payment  { background: #fef3c7; color: #92400e; }
.agent-badge--paid             { background: #d1fae5; color: #065f46; }
.agent-badge--form_in_progress { background: #ede9fe; color: #5b21b6; }
.agent-badge--form_validated   { background: #d1fae5; color: #065f46; }
.agent-badge--docs_in_progress { background: #fef3c7; color: #92400e; }
.agent-badge--docs_validated   { background: #d1fae5; color: #065f46; }
.agent-badge--pieces_in_progress { background: #fef3c7; color: #92400e; }
.agent-badge--pieces_validated { background: #d1fae5; color: #065f46; }
.agent-badge--completed        { background: #d1fae5; color: #065f46; }
.agent-badge--cancelled        { background: #fee2e2; color: #991b1b; }

.agent-badge--pending          { background: #fef3c7; color: #92400e; }
.agent-badge--approved         { background: #d1fae5; color: #065f46; }
.agent-badge--rejected         { background: #fee2e2; color: #991b1b; }

.agent-badge--internal         { background: #f3f4f6; color: #374151; }

.agent-link {
  font-size: .85rem;
  font-weight: 600;
  color: var(--ag-orange);
  text-decoration: none;
}

.agent-link:hover { text-decoration: underline; }

.agent-empty {
  color: var(--ag-muted);
  font-size: .875rem;
  text-align: center;
  padding: 2rem;
}

.agent-order-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.agent-card {
  background: var(--ag-surface);
  border-radius: var(--ag-radius);
  box-shadow: var(--ag-shadow);
  padding: 1.25rem 1.5rem;
}

.agent-card--full {
  grid-column: 1 / -1;
}

.agent-card__title {
  margin: 0 0 1rem;
  font-size: .95rem;
  font-weight: 700;
  color: var(--ag-text);
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--ag-border);
}

.agent-dl {
  margin: 0;
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: .35rem .75rem;
  font-size: .875rem;
}

.agent-dl dt {
  font-weight: 600;
  color: var(--ag-muted);
  align-self: baseline;
}

.agent-dl dd {
  margin: 0;
  color: var(--ag-text);
  word-break: break-word;
}

.agent-dl dd pre {
  margin: 0;
  font-size: .78rem;
  background: #f3f4f6;
  padding: .5rem;
  border-radius: 6px;
  overflow-x: auto;
}

.agent-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.agent-list__item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 0;
  border-bottom: 1px solid var(--ag-border);
  font-size: .875rem;
}

.agent-list__item:last-child { border-bottom: none; }

.agent-list__item span:first-child { flex: 1; }

.agent-piece-actions {
  display: inline-flex;
  gap: .4rem;
  align-items: center;
}

.agent-comments {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  margin-bottom: 1.25rem;
  max-height: 400px;
  overflow-y: auto;
}

.agent-comment {
  padding: .875rem 1rem;
  border-radius: 8px;
  background: #f9fafb;
  border: 1px solid var(--ag-border);
  font-size: .875rem;
}

.agent-comment--internal {
  background: #fffbeb;
  border-color: #fde68a;
}

.agent-comment__meta {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .4rem;
  flex-wrap: wrap;
  font-size: .78rem;
  color: var(--ag-muted);
}

.agent-comment__meta strong {
  color: var(--ag-text);
  font-weight: 600;
}

.agent-comment__role {
  padding: .1rem .4rem;
  background: var(--ag-border);
  border-radius: 4px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.agent-comment p {
  margin: 0;
  color: var(--ag-text);
  white-space: pre-wrap;
}

.agent-comment-form textarea {
  width: 100%;
  padding: .65rem .85rem;
  border: 1.5px solid var(--ag-border);
  border-radius: 8px;
  font-size: .875rem;
  font-family: inherit;
  resize: vertical;
  transition: border-color .15s;
}

.agent-comment-form textarea:focus {
  outline: none;
  border-color: var(--ag-orange);
}

.agent-comment-form__footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: .75rem;
  flex-wrap: wrap;
  gap: .5rem;
}

.agent-checkbox {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--ag-muted);
}

.agent-checkbox input[type="checkbox"] {
  accent-color: var(--ag-orange);
  width: 15px;
  height: 15px;
}

.agent-order-actions {
  display: flex;
  justify-content: flex-end;
  padding: 1.25rem 0;
  border-top: 1px solid var(--ag-border);
}

@media (max-width: 640px) {
  .agent-nav { padding: 0 1rem; }
  .agent-main { padding: 1rem .875rem 2rem; }

  .agent-nav__links { display: none; }

  .agent-login__card { padding: 2rem 1.25rem; }

  .agent-dl { grid-template-columns: 1fr; }
  .agent-dl dt { margin-top: .25rem; }

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

  .agent-table { font-size: .8rem; }
  .agent-table th, .agent-table td { padding: .5rem .4rem; }
}

#app-loading {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  transition: opacity .5s ease, visibility .5s ease;
}

#app-loading.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.app-loading__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  animation: loading-appear .4s ease both;
}

@keyframes loading-appear {
  from { opacity: 0; transform: scale(.92); }
  to   { opacity: 1; transform: scale(1); }
}

.app-loading__logo {
  width: min(80vw, 380px);
  height: auto;
}

.app-loading__logo img,
.app-loading__logo svg {
  width: 100%;
  height: auto;
  display: block;
}

.app-loading__dots {
  display: flex;
  gap: .55rem;
}

.app-loading__dots span {
  display: block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ag-orange);
  animation: loading-dot 1s ease-in-out infinite;
}

.app-loading__dots span:nth-child(2) { animation-delay: .18s; }
.app-loading__dots span:nth-child(3) { animation-delay: .36s; }

@keyframes loading-dot {
  0%, 80%, 100% { transform: scale(.5); opacity: .3; }
  40%            { transform: scale(1);  opacity: 1;  }
}

#pwa-modal { display: contents; }
#pwa-modal[hidden] { display: none; }

.pwa-modal__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(2px);
  z-index: 9000;
  animation: pwa-fade-in .2s ease;
}

.pwa-modal__box {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9001;
  background: var(--ag-surface);
  border-radius: 20px 20px 0 0;
  padding: 1.75rem 1.5rem 2.5rem;
  max-width: 480px;
  margin: 0 auto;
  box-shadow: 0 -8px 40px rgba(0,0,0,.15);
  animation: pwa-slide-up .3s cubic-bezier(.32,.72,0,1);
}

@media (min-height: 700px) {
  .pwa-modal__box {
    bottom: 50%;
    transform: translateY(50%);
    border-radius: 20px;
    animation: pwa-pop-in .25s cubic-bezier(.32,.72,0,1);
  }
}

@keyframes pwa-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes pwa-slide-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

@keyframes pwa-pop-in {
  from { opacity: 0; transform: translateY(50%) scale(.96); }
  to   { opacity: 1; transform: translateY(50%) scale(1); }
}

.pwa-modal__close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: #f3f4f6;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ag-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}

.pwa-modal__close:hover { background: #e5e7eb; }

.pwa-modal__icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 1.25rem;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
}

.pwa-modal__icon img { display: block; width: 100%; height: 100%; object-fit: cover; }

.pwa-modal__icon-fallback {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: var(--ag-orange);
  color: #fff;
  font-size: 1.6rem;
  font-weight: 800;
  align-items: center;
  justify-content: center;
}

.pwa-modal__title {
  margin: 0 0 .4rem;
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
  color: var(--ag-text);
}

.pwa-modal__subtitle {
  margin: 0 0 1.5rem;
  font-size: .9rem;
  color: var(--ag-muted);
  text-align: center;
  line-height: 1.5;
}

.pwa-modal__features {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.pwa-modal__features li {
  display: flex;
  align-items: center;
  gap: .65rem;
  font-size: .9rem;
  color: var(--ag-text);
}

.pwa-modal__features li::before {
  content: '✓';
  display: inline-flex;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #d1fae5;
  color: #065f46;
  font-size: .75rem;
  font-weight: 700;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pwa-modal__cta {
  width: 100%;
  padding: .85rem;
  font-size: 1rem;
  border-radius: 12px;
  margin-bottom: .75rem;
}

.pwa-modal__steps {
  list-style: none;
  margin: 0 0 1.25rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.pwa-modal__steps li {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .9rem;
  color: var(--ag-text);
  line-height: 1.4;
}

.pwa-modal__step-icon {
  display: inline-flex;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--ag-orange);
  color: #fff;
  font-size: .78rem;
  font-weight: 700;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pwa-ios-share {
  display: inline-block;
  width: 18px;
  height: 18px;
  vertical-align: middle;
  color: #007aff;
  margin: 0 .1rem;
}

.pwa-modal__ios-arrow {
  text-align: center;
  font-size: 2rem;
  color: var(--ag-orange);
  animation: pwa-bounce .8s infinite alternate ease-in-out;
  margin-bottom: .75rem;
}

@keyframes pwa-bounce {
  from { transform: translateY(0); }
  to   { transform: translateY(6px); }
}

.pwa-modal__later {
  display: block;
  width: 100%;
  background: none;
  border: none;
  font-size: .875rem;
  color: var(--ag-muted);
  cursor: pointer;
  padding: .5rem;
  text-align: center;
  transition: color .15s;
}

.pwa-modal__later:hover { color: var(--ag-text); }

.agent-week-schedule {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.agent-day-row {
  background: var(--ag-surface);
  border-radius: var(--ag-radius);
  box-shadow: var(--ag-shadow);
  padding: 1rem 1.25rem;
}

.agent-day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: .5rem;
}

.agent-day-name strong {
  font-size: .95rem;
  color: var(--ag-text);
}

.agent-slot-count {
  margin-left: .5rem;
  font-size: .78rem;
  color: var(--ag-muted);
}

.agent-slot-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
  padding: .6rem 0;
  border-top: 1px solid var(--ag-border);
}

.agent-slot-row:first-child { border-top: none; }

.agent-slot-times {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  color: var(--ag-muted);
}

.agent-slot-times input[type="time"] {
  padding: .4rem .55rem;
  border: 1.5px solid var(--ag-border);
  border-radius: 6px;
  font-size: .85rem;
  color: var(--ag-text);
}

.agent-slot-actions {
  display: flex;
  gap: .4rem;
}

.agent-no-slots {
  padding: .5rem 0;
  color: var(--ag-muted);
  font-size: .85rem;
}

.agent-exception-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
  padding: .65rem 0;
  border-top: 1px solid var(--ag-border);
}

.agent-exception-item:first-child { border-top: none; }
