/* RysUpAudio Support Dashboard — Dark Glassmorphism */

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

:root {
  --bg: #050510;
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: 1px solid rgba(255, 255, 255, 0.15);
  --glass-radius: 16px;
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  --accent: #CE2C2C;
  --accent-glow: #ff6b6b;
  --text: rgba(255, 255, 255, 0.92);
  --text-muted: rgba(255, 255, 255, 0.65);
  --text-dim: rgba(255, 255, 255, 0.4);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* Layout */
.app {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px;
  padding-top: calc(constant(safe-area-inset-top) + 16px);
  padding-top: calc(env(safe-area-inset-top) + 16px);
  padding-bottom: calc(constant(safe-area-inset-bottom) + 16px);
  padding-bottom: calc(env(safe-area-inset-bottom) + 16px);
  min-height: 100%;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 20px;
}

.app-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.app-header h1 span {
  color: var(--accent);
}

.app-header nav {
  display: flex;
  gap: 8px;
}

.nav-btn {
  background: var(--glass-bg);
  border: var(--glass-border);
  border-radius: 8px;
  color: var(--text-muted);
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font);
  transition: color 0.15s, border-color 0.15s;
}

.nav-btn:hover, .nav-btn.active {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.25);
}

/* Login */
.login-card {
  background: var(--glass-bg);
  border: var(--glass-border);
  border-radius: var(--glass-radius);
  box-shadow: var(--glass-shadow);
  padding: 40px 32px;
  max-width: 360px;
  margin: 80px auto;
  text-align: center;
}

.login-card h2 {
  font-size: 18px;
  margin-bottom: 8px;
}

.login-card p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

.input:focus {
  border-color: rgba(255, 255, 255, 0.25);
}

.input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
  margin-top: 12px;
}

.btn:hover { background: #e03333; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-sm {
  padding: 8px 16px;
  font-size: 13px;
  width: auto;
  margin-top: 0;
}

.btn-outline {
  background: transparent;
  border: var(--glass-border);
  color: var(--text-muted);
}

.btn-outline:hover {
  border-color: rgba(255, 255, 255, 0.25);
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--glass-bg);
  border: var(--glass-border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}

.stat-card__value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.stat-card__label {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-card--alert .stat-card__value { color: var(--accent-glow); }

/* Filter Tabs */
.filter-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-tab {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  color: var(--text-dim);
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
}

.filter-tab:hover { color: var(--text-muted); border-color: rgba(255, 255, 255, 0.15); }
.filter-tab.active { color: var(--text); background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.2); }

/* Conversation List */
.conv-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.conv-item {
  background: var(--glass-bg);
  border: var(--glass-border);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.conv-item:hover {
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.conv-item__email {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.conv-item__preview {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 450px;
}

.conv-item__meta {
  text-align: right;
  font-size: 11px;
  color: var(--text-dim);
}

.conv-item__badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-escalated { background: rgba(206, 44, 44, 0.2); color: #ff6b6b; }
.badge-open { background: rgba(255, 200, 50, 0.15); color: #ffc832; }
.badge-auto_resolved { background: rgba(50, 200, 100, 0.15); color: #32c864; }
.badge-resolved { background: rgba(50, 200, 100, 0.15); color: #32c864; }
.badge-closed { background: rgba(255, 255, 255, 0.05); color: var(--text-dim); }

/* Conversation Detail */
.conv-detail {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.conv-detail__back {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  font-family: var(--font);
  padding: 0;
  transition: color 0.15s;
  align-self: flex-start;
}

.conv-detail__back:hover { color: var(--text); }

.conv-detail__info {
  background: var(--glass-bg);
  border: var(--glass-border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.conv-detail__info-text {
  font-size: 14px;
}

.conv-detail__info-text span {
  color: var(--text-muted);
  font-size: 12px;
}

.conv-detail__actions {
  display: flex;
  gap: 6px;
}

/* Messages Thread */
.msg-thread {
  background: var(--glass-bg);
  border: var(--glass-border);
  border-radius: var(--glass-radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 50vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.msg-thread::-webkit-scrollbar { width: 4px; }
.msg-thread::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 2px; }

.msg-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg-bubble a { color: var(--accent-glow); }

.msg-bubble--customer {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.msg-bubble--auto,
.msg-bubble--claude,
.msg-bubble--admin {
  align-self: flex-end;
  background: rgba(206, 44, 44, 0.15);
  border: 1px solid rgba(206, 44, 44, 0.25);
  color: var(--text);
}

.msg-bubble__meta {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Reply Box */
.reply-box {
  display: flex;
  gap: 8px;
}

.reply-box textarea {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  resize: none;
  min-height: 48px;
  max-height: 120px;
}

.reply-box textarea:focus {
  border-color: rgba(255, 255, 255, 0.25);
}

.reply-box textarea::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

/* Settings */
.settings-card {
  background: var(--glass-bg);
  border: var(--glass-border);
  border-radius: var(--glass-radius);
  padding: 24px;
}

.settings-card h3 {
  font-size: 16px;
  margin-bottom: 12px;
}

.settings-card p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.toggle-row label {
  font-size: 14px;
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  z-index: 2;
  margin: 0;
}

.toggle-switch .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  transition: background 0.2s;
}

.toggle-switch .slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .slider {
  background: var(--accent);
}

.toggle-switch input:checked + .slider::before {
  transform: translateX(20px);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-dim);
  font-size: 14px;
}

/* Loading */
.loading {
  text-align: center;
  padding: 32px;
  color: var(--text-dim);
  font-size: 14px;
}

/* Standalone PWA — fallback top padding if safe-area-inset not supported */
@media all and (display-mode: standalone) {
  .app { padding-top: 44px; }
}

/* Mobile */
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .conv-item__preview { max-width: 200px; }
  .app {
    padding-left: 12px;
    padding-right: 12px;
  }
  .conv-detail__info { flex-direction: column; align-items: flex-start; }
  /* Prevent iOS auto-zoom on input focus (requires >= 16px) */
  .input, .reply-box textarea, #login-token { font-size: 16px; }
}
