/* DGC Tickets — dark theme, mobile-first, no build step. */

:root {
  --bg: #161822;
  --surface: #1e2433;
  --accent: #6B8AD8;
  --gold: #e6a855;
  --text: #c9d1d9;
  --text-muted: #6b7280;
  --input-bg: #2a3040;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #eab308;

  --radius-card: 12px;
  --radius-input: 8px;
  --radius-btn: 24px;
  --space: 16px;
  --gap: 12px;
  --transition: 0.15s ease;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
}

a {
  color: var(--accent);
}

#app {
  --install-banner-height: 0px;
  max-width: 480px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  display: flex;
  flex-direction: column;
}

#view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page {
  padding: var(--space);
  padding-bottom: calc(var(--space) + 80px + var(--install-banner-height));
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.page-title {
  font-size: 20px;
  margin: 4px 0 16px;
}

.section-title {
  font-size: 15px;
  color: var(--text-muted);
  margin: 24px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border-radius: var(--radius-btn);
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: transform var(--transition), opacity var(--transition), background var(--transition);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--gold);
  color: #161822;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--input-bg);
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-btn);
  cursor: pointer;
  transition: background var(--transition);
}

.btn-ghost:hover,
.btn-ghost:focus-visible {
  background: var(--input-bg);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  min-height: 44px;
  padding: 0 20px;
  border-radius: var(--radius-btn);
  cursor: pointer;
}

.back-btn {
  align-self: flex-start;
  margin-bottom: 8px;
}

/* Inputs */

.input, .textarea, .select {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  background: var(--input-bg);
  border: 1px solid transparent;
  border-radius: var(--radius-input);
  outline: none;
  transition: border-color var(--transition);
}

.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent);
}

.input::placeholder, .textarea::placeholder {
  color: var(--text-muted);
}

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

.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.field-label > .input,
.field-label > .select {
  margin-top: 6px;
}

/* Cards, chips, status dots */

.card {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: var(--space);
  margin-bottom: var(--gap);
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--input-bg);
  color: var(--text-muted);
  font-size: 12px;
  text-transform: capitalize;
}

.chip-priority-high { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.chip-priority-medium { background: rgba(234, 179, 8, 0.15); color: var(--warning); }
.chip-priority-low { background: rgba(34, 197, 94, 0.15); color: var(--success); }

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot-green { background: var(--success); }
.status-dot-yellow { background: var(--warning); }
.status-dot-blue { background: var(--accent); }
.status-dot-gray { background: var(--text-muted); }

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--input-bg);
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.avatar-sm {
  width: 28px;
  height: 28px;
  font-size: 13px;
}

/* Loading / empty / error states */

.loading-state, .empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  gap: 8px;
  flex: 1;
}

.empty-state-sm {
  padding: 20px;
}

.empty-state-icon {
  font-size: 32px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--input-bg);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Auth screens */

.auth-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space);
}

.auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-title {
  font-size: 24px;
  text-align: center;
  margin: 0;
  color: var(--gold);
}

.auth-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin: 0 0 8px;
  font-size: 14px;
}

.auth-input {
  text-align: center;
  font-size: 18px;
}

.auth-submit {
  width: 100%;
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  min-height: 18px;
}

.code-boxes {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.code-box {
  width: 44px;
  height: 52px;
  text-align: center;
  font-size: 22px;
  background: var(--input-bg);
  border: 1px solid transparent;
  border-radius: var(--radius-input);
  outline: none;
  transition: border-color var(--transition);
}

.code-box:focus {
  border-color: var(--gold);
}

.resend-row {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.resend-link {
  color: var(--gold);
  text-decoration: none;
  font-weight: 600;
}

/* Chat view */

.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px var(--space);
  background: var(--surface);
  border-bottom: 1px solid var(--input-bg);
}

.chat-header-title {
  font-weight: 600;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.message-row {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  gap: 4px;
  position: relative;
}

.message-row-self {
  align-self: flex-end;
  align-items: flex-end;
}

.message-row-other {
  align-self: flex-start;
  align-items: flex-start;
}

.message-bubble {
  background: var(--surface);
  padding: 10px 14px;
  border-radius: var(--radius-card);
  word-break: break-word;
  white-space: pre-wrap;
}

.message-row-self .message-bubble {
  background: rgba(230, 168, 85, 0.18);
  border: 1px solid rgba(230, 168, 85, 0.3);
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 4px;
}

.message-menu-btn {
  position: absolute;
  top: -16px;
  right: -20px;
  background: var(--input-bg);
  border: none;
  color: var(--text-muted);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-row-self .message-menu-btn {
  right: auto;
  left: -20px;
}

/* Ticket bubble (promoted message) */

.ticket-bubble-wrap {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.ticket-bubble {
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-card);
  padding: 12px 14px;
  transition: background var(--transition);
}

.ticket-bubble-wrap:active .ticket-bubble {
  background: var(--input-bg);
}

.ticket-bubble-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.ticket-bubble-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ticket-bubble-body {
  font-size: 14px;
  color: var(--text);
  word-break: break-word;
}

.ticket-bubble-status {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px var(--space);
  padding-bottom: calc(max(10px, env(safe-area-inset-bottom)) + 76px + var(--install-banner-height));
  background: var(--surface);
  border-top: 1px solid var(--input-bg);
}

.chat-input {
  flex: 1;
}

.chat-send-btn {
  flex-shrink: 0;
}

/* Conversations list (admin) */

.conversation-list, .user-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.conversation-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: none;
  border-radius: var(--radius-card);
  padding: 12px;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition);
  min-height: 44px;
}

.conversation-row:active {
  background: var(--input-bg);
}

.conversation-row-info {
  flex: 1;
  min-width: 0;
}

.conversation-row-name {
  font-weight: 600;
}

.conversation-row-preview {
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-row-time {
  color: var(--text-muted);
  font-size: 12px;
  flex-shrink: 0;
}

/* Ticket list */

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 12px;
  margin-bottom: 4px;
}

.filter-chip {
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: var(--radius-btn);
  cursor: pointer;
  font-size: 13px;
  min-height: 44px;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.filter-chip-active {
  background: rgba(107, 138, 216, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.filter-chip-active::before {
  content: '✓ ';
  font-weight: 700;
}

.ticket-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ticket-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: none;
  border-radius: var(--radius-card);
  padding: 12px;
  text-align: left;
  cursor: pointer;
  min-height: 44px;
  transition: background var(--transition);
}

.ticket-row:active {
  background: var(--input-bg);
}

.ticket-row-main {
  flex: 1;
  min-width: 0;
}

.ticket-row-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ticket-row-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.ticket-row-date {
  font-size: 12px;
  color: var(--text-muted);
}

/* Ticket detail */

.ticket-info-card > .field-label:last-child {
  margin-bottom: 0;
}

.time-section {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: var(--space);
}

.time-total {
  font-size: 20px;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 12px;
}

.time-entry-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.time-entry {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--input-bg);
}

.time-entry:last-child {
  border-bottom: none;
}

.time-entry-minutes {
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

.time-entry-note {
  flex: 1;
  min-width: 0;
}

.time-entry-meta {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.time-entry-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--input-bg);
}

.time-entry-form .field-label,
.invite-form .field-label {
  margin-bottom: 0;
}

/* Users page */

.invite-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 12px;
}

.user-row-info {
  flex: 1;
  min-width: 0;
}

.user-row-name {
  font-weight: 600;
}

.user-row-meta {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: capitalize;
}

.analytics-placeholder p {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

/* Nav bubble + slide-out panel */

.nav-bubble {
  position: fixed;
  right: max(20px, calc((100vw - 480px) / 2 + 20px));
  bottom: calc(20px + var(--install-banner-height));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--gold);
  color: #161822;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  z-index: 1000;
  transition: transform var(--transition);
}

.nav-bubble:active {
  transform: scale(0.94);
}

.nav-overlay {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  width: min(100vw, 480px);
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  z-index: 1001;
}

.nav-overlay-open {
  opacity: 1;
  pointer-events: auto;
}

.nav-panel {
  position: fixed;
  top: 0;
  right: max(0px, calc((100vw - 480px) / 2));
  bottom: 0;
  width: min(280px, 80vw);
  background: var(--surface);
  transform: translateX(100%);
  transition: transform 0.2s ease;
  z-index: 1002;
  padding: max(20px, env(safe-area-inset-top)) 12px 20px;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
  visibility: hidden;
  pointer-events: none;
}

.nav-panel-open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}

.nav-panel-header {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 12px 16px;
}

.nav-panel-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-panel-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 12px;
  border-radius: var(--radius-input);
  cursor: pointer;
  min-height: 44px;
  font-size: 15px;
  transition: background var(--transition);
}

.nav-panel-item:hover,
.nav-panel-item:active {
  background: var(--input-bg);
}

.nav-panel-item-danger {
  color: var(--danger);
}

.nav-panel-icon {
  font-size: 18px;
}

/* Toasts */

#toast-container {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(400px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  background: var(--surface);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius-input);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity var(--transition), transform var(--transition);
  font-size: 14px;
}

.toast-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-error {
  border: 1px solid var(--danger);
}

/* Modal (promote to ticket) */

.modal-overlay {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  width: min(100vw, 480px);
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1500;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: var(--space);
  padding-bottom: max(var(--space), env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 100dvh;
  overflow-y: auto;
}

.modal-title {
  font-size: 18px;
  margin: 0 0 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* Install banner */

.install-banner {
  position: fixed;
  left: 50%;
  width: min(100vw, 480px);
  transform: translateX(-50%);
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--input-bg);
  padding: 14px var(--space);
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--text);
  z-index: 900;
}

.install-banner-text {
  flex: 1;
  min-width: 0;
}

.install-banner-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.install-banner-button {
  min-height: 44px;
  padding-left: 14px;
  padding-right: 14px;
  white-space: nowrap;
}

/* Desktop scaling */

@media (min-width: 481px) {
  body {
    background: #10121a;
  }

  #app {
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
    min-height: 100vh;
  }
}

/* Focus visibility for accessibility */

button:focus-visible,
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
