/* ==========================================================================
   QES Design Tokens & Stylesheet
   Matches Q Techs Solar Design System
   ========================================================================== */

:root {
  --brand-teal: #1cbdbe;
  --brand-teal-light: #22d3ee;
  --brand-orange: #f57d31;
  --solar-yellow: #fbd055;
  --headings: #101524;

  /* Light mode defaults */
  --bg-page: #fafafa;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f4f4f5;
  --border-color: #e2e8f0;
  --text-main: #09090b;
  --text-muted: #52525b;
  --card-radius: 16px;
  --shadow-soft: 0 4px 20px -2px rgba(16, 21, 36, 0.06);
  --shadow-lg: 0 12px 30px -4px rgba(16, 21, 36, 0.1);
  --btn-primary-bg: #101524;
  --btn-primary-text: #ffffff;
}

[data-theme="dark"] {
  --bg-page: #050508;
  --bg-surface: #09090b;
  --bg-surface-elevated: #121217;
  --border-color: #27272a;
  --text-main: #ffffff;
  --text-muted: #a1a1aa;
  --shadow-soft: 0 4px 20px -2px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 12px 30px -4px rgba(0, 0, 0, 0.7);
  --btn-primary-bg: #1cbdbe;
  --btn-primary-text: #050508;
}

/* Embedded mode (inside QesPage iframe) */
body.is-embedded {
  background-color: transparent !important;
}

body.is-embedded .qes-footer-line {
  display: none !important;
}

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

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s ease, color 0.25s ease;
}

h1, h2, h3, h4, h5, h6, .font-heading {
  font-family: 'Outfit', sans-serif;
  letter-spacing: -0.02em;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(161, 161, 170, 0.3);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(161, 161, 170, 0.5);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  text-decoration: none;
  user-select: none;
}

.btn:hover {
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background-color: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  box-shadow: 0 4px 14px rgba(16, 21, 36, 0.15);
}
.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-cta {
  background: linear-gradient(135deg, #fbd055 0%, #f57d31 100%);
  color: #101524;
  font-weight: 800;
  box-shadow: 0 4px 16px rgba(245, 125, 49, 0.3);
}
.btn-cta:hover {
  box-shadow: 0 6px 20px rgba(245, 125, 49, 0.45);
  filter: brightness(1.05);
}

.btn-secondary {
  background-color: var(--bg-surface);
  color: var(--text-main);
  border-color: var(--border-color);
}
.btn-secondary:hover {
  background-color: var(--bg-surface-elevated);
}

.btn-danger {
  background-color: #ef4444;
  color: #ffffff;
}
.btn-danger:hover {
  background-color: #dc2626;
}

.btn-sm {
  padding: 0.375rem 0.875rem;
  font-size: 0.7rem;
}

/* Cards */
.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-soft);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  border-color: rgba(28, 189, 190, 0.4);
}

/* Focus styles */
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-teal) !important;
  box-shadow: 0 0 0 3px rgba(28, 189, 190, 0.2) !important;
}

/* Badges / Chips */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-amber {
  background: rgba(245, 125, 49, 0.12);
  color: #f57d31;
  border: 1px solid rgba(245, 125, 49, 0.25);
}

.badge-teal {
  background: rgba(28, 189, 190, 0.12);
  color: #1cbdbe;
  border: 1px solid rgba(28, 189, 190, 0.25);
}

.badge-green {
  background: rgba(16, 185, 129, 0.12);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.badge-red {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.25);
}

/* Rubber Stamp Effect */
.stamp {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  font-family: 'Outfit', monospace;
  font-weight: 900;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border: 2px dashed currentColor;
  border-radius: 6px;
  transform: rotate(-3deg);
  opacity: 0.9;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(5, 5, 8, 0.75);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-content {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

/* Pulsing Amber Dot */
.pulsing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #f57d31;
  position: relative;
  display: inline-block;
}

.pulsing-dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background-color: #f57d31;
  opacity: 0.6;
  animation: pulse-wave 1.8s infinite ease-out;
}

@keyframes pulse-wave {
  0% { transform: scale(0.6); opacity: 0.8; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* ─── Inline document viewer ─── */
.dv { display: grid; grid-template-columns: 230px minmax(0, 1fr); border: 1px solid var(--border-color); border-radius: 14px; overflow: hidden; background: var(--bg-surface-elevated); }
.dv-rail { overflow: auto; max-height: 640px; padding: 0.5rem; display: flex; flex-direction: column; gap: 0.5rem; border-right: 1px solid var(--border-color); background: var(--bg-surface); }
.dv-item { display: flex; gap: 0.625rem; align-items: center; text-align: left; width: 100%; padding: 0.5rem; border-radius: 10px; border: 1.5px solid transparent; background: var(--bg-surface-elevated); color: var(--text-main); cursor: pointer; font: inherit; }
.dv-item:hover { border-color: var(--border-color); }
.dv-item.active { border-color: var(--brand-teal); box-shadow: 0 0 0 3px rgba(28, 189, 190, 0.18); }
.dv-item.gone { opacity: 0.55; }
.dv-thumb { flex: none; width: 56px; height: 56px; border-radius: 8px; overflow: hidden; background: #000; display: grid; place-items: center; }
.dv-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dv-ext { font-size: 0.6875rem; font-weight: 800; color: var(--brand-teal); letter-spacing: 0.04em; }
.dv-meta { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.dv-kind { font-size: 0.625rem; font-weight: 800; text-transform: uppercase; color: var(--brand-orange); letter-spacing: 0.04em; }
.dv-name { font-size: 0.75rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dv-by { font-size: 0.6875rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dv-viewer { display: flex; flex-direction: column; min-width: 0; background: #0b0f1a; }
.dv-bar { display: flex; align-items: center; gap: 2px; padding: 0.375rem 0.5rem 0.375rem 0.875rem; background: #101524; color: #e5e7eb; flex-wrap: wrap; }
.dv-bar #dv-tools { display: inline-flex; }
.dv-title { flex: 1; min-width: 0; font-size: 0.8125rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-left: 0.5rem; }
.dv-count { font-size: 0.75rem; color: #9ca3af; margin: 0 0.5rem; white-space: nowrap; }
.dv-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 8px; border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 1.05rem; text-decoration: none; line-height: 1; }
.dv-btn:hover { background: rgba(28, 189, 190, 0.2); color: var(--brand-teal-light); }
.dv-btn[disabled] { opacity: 0.3; cursor: default; background: transparent; }
.dv-stage { flex: 1; height: 62vh; min-height: 420px; max-height: 720px; overflow: auto; display: flex; background: #0b0f1a; }
.dv-holder { margin: auto; position: relative; flex: none; }
.dv-holder img { position: absolute; left: 50%; top: 50%; max-width: none; background: #fff; transform-origin: center; border-radius: 4px; }
.dv-stage iframe { border: 0; width: 100%; height: 100%; background: #fff; }
.dv-empty { margin: auto; text-align: center; color: #cbd5e1; padding: 1.5rem; font-size: 0.875rem; }
.dv-viewer:fullscreen { width: 100vw; height: 100vh; }
.dv-viewer:fullscreen .dv-stage { height: auto; max-height: none; flex: 1; }
@media (max-width: 760px) {
  .dv { grid-template-columns: 1fr; }
  .dv-rail { flex-direction: row; max-height: none; border-right: 0; border-bottom: 1px solid var(--border-color); }
  .dv-item { width: 190px; flex: none; }
  .dv-stage { min-height: 340px; }
}

.btn-trash { border: 1px solid var(--border-color); background: var(--bg-surface-elevated); color: var(--text-muted); width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 0.9rem; line-height: 1; display: inline-grid; place-items: center; }
.btn-trash:hover { color: #ef4444; border-color: rgba(239, 68, 68, 0.5); background: rgba(239, 68, 68, 0.08); }
.btn-danger-outline { color: #ef4444 !important; border-color: rgba(239, 68, 68, 0.45) !important; }
.btn-danger-outline:hover { background: rgba(239, 68, 68, 0.1) !important; }

/* ==========================================================================
   QES additions: live status, toasts, upload animation, password eye
   ========================================================================== */

/* ---- password field with show/hide eye ---- */
.pw-wrap { position: relative; display: block; width: 100%; }
.pw-wrap > input { width: 100%; padding-right: 2.75rem !important; }
.pw-eye { position: absolute; right: 0.375rem; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--text-muted); cursor: pointer; }
.pw-eye:hover { color: var(--brand-teal); background: rgba(28, 189, 190, 0.1); }
.pw-eye svg { width: 18px; height: 18px; pointer-events: none; }
.pw-eye .eye-off { display: none; }
.pw-eye.on .eye-on { display: none; }
.pw-eye.on .eye-off { display: block; }

/* ---- live status pill in header ---- */
.live-pill { display: inline-flex; align-items: center; gap: 0.375rem; padding: 0.25rem 0.625rem; border-radius: 9999px; font-size: 0.625rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; border: 1px solid rgba(16, 185, 129, 0.35); color: #10b981; background: rgba(16, 185, 129, 0.1); user-select: none; }
.live-pill i { width: 7px; height: 7px; border-radius: 50%; background: #10b981; display: inline-block; animation: live-beat 1.6s infinite ease-out; }
.live-pill.off { color: #ef4444; border-color: rgba(239, 68, 68, 0.35); background: rgba(239, 68, 68, 0.1); }
.live-pill.off i { background: #ef4444; animation: none; }
.live-pill.flash { animation: live-flash 0.9s ease-out; }
@keyframes live-beat { 0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); } 100% { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); } }
@keyframes live-flash { 0% { background: rgba(251, 208, 85, 0.55); } 100% { background: rgba(16, 185, 129, 0.1); } }

/* ---- freshly changed card glow ---- */
.just-updated { animation: just-updated 2.2s ease-out; }
@keyframes just-updated { 0% { box-shadow: 0 0 0 3px rgba(251, 208, 85, 0.85); } 100% { box-shadow: var(--shadow-soft); } }

/* ---- toasts ---- */
#qes-toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 3000; display: flex; flex-direction: column; gap: 0.5rem; align-items: flex-end; pointer-events: none; max-width: calc(100vw - 2rem); }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 0.625rem; padding: 0.75rem 1rem; border-radius: 12px; background: var(--bg-surface); color: var(--text-main); border: 1px solid var(--border-color); border-left: 4px solid var(--brand-teal); box-shadow: var(--shadow-lg); font-size: 0.8125rem; font-weight: 600; animation: toast-in 0.35s cubic-bezier(0.16, 1, 0.3, 1); max-width: 380px; }
.toast.ok { border-left-color: #10b981; }
.toast.err { border-left-color: #ef4444; }
.toast.live { border-left-color: #fbd055; }
.toast.out { animation: toast-out 0.3s ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(0.96); } }

/* ---- upload slots (New Ticket form) ---- */
.up-slot { padding: 0.75rem; border-radius: 12px; border: 1.5px dashed var(--border-color); background: var(--bg-surface-elevated); transition: border-color 0.2s, background 0.2s, box-shadow 0.2s; position: relative; overflow: hidden; }
.up-slot.uploading { border-style: solid; border-color: var(--brand-teal); background: rgba(28, 189, 190, 0.06); }
.up-slot.done { border-style: solid; border-color: #10b981; background: rgba(16, 185, 129, 0.07); }
.up-slot.error { border-style: solid; border-color: #ef4444; background: rgba(239, 68, 68, 0.07); }
.up-title { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; font-size: 0.75rem; font-weight: 800; margin-bottom: 0.5rem; }
.up-pick { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; font-size: 0.75rem; color: var(--text-muted); }
.up-pick input { display: none; }
.up-pick .up-btn { display: inline-flex; align-items: center; gap: 0.375rem; padding: 0.375rem 0.75rem; border-radius: 9999px; border: 1px solid var(--border-color); background: var(--bg-surface); color: var(--text-main); font-weight: 700; font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.04em; }
.up-pick:hover .up-btn { border-color: var(--brand-teal); color: var(--brand-teal); }
.up-file { display: none; align-items: center; gap: 0.5rem; font-size: 0.6875rem; color: var(--text-muted); margin-bottom: 0.375rem; }
.up-file b { color: var(--text-main); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.up-slot.uploading .up-file, .up-slot.done .up-file, .up-slot.error .up-file { display: flex; }
.up-bar { display: none; height: 8px; border-radius: 9999px; background: rgba(148, 163, 184, 0.25); overflow: hidden; position: relative; }
.up-slot.uploading .up-bar, .up-slot.done .up-bar { display: block; }
.up-fill { height: 100%; width: 0%; border-radius: inherit; background: linear-gradient(90deg, #1cbdbe, #22d3ee, #fbd055, #f57d31); background-size: 200% 100%; transition: width 0.18s ease-out; animation: up-flow 1.1s linear infinite; position: relative; }
.up-slot.done .up-fill { width: 100% !important; background: #10b981; animation: none; }
@keyframes up-flow { from { background-position: 0% 0; } to { background-position: -200% 0; } }
.up-status { display: flex; align-items: center; justify-content: space-between; margin-top: 0.375rem; font-size: 0.6875rem; font-weight: 700; min-height: 1.1rem; color: var(--text-muted); }
.up-slot.uploading .up-status { color: var(--brand-teal); }
.up-slot.done .up-status { color: #10b981; }
.up-slot.error .up-status { color: #ef4444; }
.up-tick { display: none; width: 22px; height: 22px; flex: none; }
.up-slot.done .up-tick { display: block; }
.up-tick circle { stroke: #10b981; stroke-width: 3; fill: none; stroke-dasharray: 150; stroke-dashoffset: 150; animation: tick-circle 0.55s ease-out forwards; }
.up-tick path { stroke: #10b981; stroke-width: 4; fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 40; stroke-dashoffset: 40; animation: tick-draw 0.4s 0.4s ease-out forwards; }
.up-slot.done { animation: slot-pop 0.5s ease-out; }
@keyframes tick-circle { to { stroke-dashoffset: 0; } }
@keyframes tick-draw { to { stroke-dashoffset: 0; } }
@keyframes slot-pop { 0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.55); } 100% { box-shadow: 0 0 0 14px rgba(16, 185, 129, 0); } }
.up-x { border: 0; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 0.25rem; }
.up-x:hover { color: #ef4444; }

/* ---- progress for the "create ticket" button ---- */
.btn[disabled] { opacity: 0.55; cursor: not-allowed; transform: none !important; filter: grayscale(0.25); }
.up-summary { display: flex; align-items: center; gap: 0.625rem; padding: 0.625rem 0.875rem; border-radius: 10px; background: var(--bg-surface-elevated); border: 1px solid var(--border-color); font-size: 0.75rem; font-weight: 700; }
.up-summary .up-meter { flex: 1; height: 6px; border-radius: 9999px; background: rgba(148, 163, 184, 0.25); overflow: hidden; }
.up-summary .up-meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #1cbdbe, #f57d31); transition: width 0.25s ease; border-radius: inherit; }
.up-summary.ready { border-color: rgba(16, 185, 129, 0.45); color: #10b981; background: rgba(16, 185, 129, 0.08); }

/* ---- full-screen upload / success overlay (letters, payments, ticket creation) ---- */
#qes-busy { position: fixed; inset: 0; z-index: 2500; display: none; align-items: center; justify-content: center; background: rgba(5, 5, 8, 0.72); backdrop-filter: blur(6px); padding: 1rem; }
#qes-busy.show { display: flex; animation: busy-in 0.2s ease-out; }
@keyframes busy-in { from { opacity: 0; } to { opacity: 1; } }
.busy-card { width: min(360px, 100%); padding: 1.75rem 1.5rem; border-radius: 20px; text-align: center; background: var(--bg-surface); border: 1px solid var(--border-color); box-shadow: var(--shadow-lg); }
.busy-ring { width: 104px; height: 104px; margin: 0 auto 1rem; position: relative; }
.busy-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.busy-ring .bg { stroke: rgba(148, 163, 184, 0.25); }
.busy-ring .fg { stroke: url(#busy-grad); stroke-linecap: round; transition: stroke-dashoffset 0.2s ease-out; }
.busy-ring .pct { position: absolute; inset: 0; display: grid; place-items: center; font-family: 'Outfit', sans-serif; font-weight: 800; font-size: 1.4rem; }
.busy-ring.spin .fg { animation: ring-spin 1.1s linear infinite; transform-origin: 50% 50%; stroke-dasharray: 90 220; }
@keyframes ring-spin { to { transform: rotate(360deg); } }
.busy-title { font-family: 'Outfit', sans-serif; font-weight: 800; font-size: 1.05rem; text-transform: uppercase; }
.busy-sub { margin-top: 0.25rem; font-size: 0.75rem; color: var(--text-muted); word-break: break-word; }
.busy-ok { width: 104px; height: 104px; margin: 0 auto 1rem; display: none; }
.busy-ok circle { stroke: #10b981; stroke-width: 4; fill: rgba(16, 185, 129, 0.1); stroke-dasharray: 190; stroke-dashoffset: 190; animation: tick-circle 0.6s ease-out forwards; }
.busy-ok path { stroke: #10b981; stroke-width: 6; fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 50; stroke-dashoffset: 50; animation: tick-draw 0.45s 0.5s ease-out forwards; }
#qes-busy.success .busy-ring { display: none; }
#qes-busy.success .busy-ok { display: block; }
#qes-busy.success .busy-card { animation: slot-pop 0.7s ease-out; }
#qes-busy.error .busy-title { color: #ef4444; }

/* ---- misc ---- */
.field-err { display: none; padding: 0.75rem; border-radius: 8px; background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.3); color: #ef4444; font-size: 0.75rem; }
.hint { font-size: 0.6875rem; color: var(--text-muted); }
@media (max-width: 640px) { #qes-toasts { left: 1rem; align-items: stretch; } .toast { max-width: none; } }
