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

:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface2: #f0efe9;
  --border: #e2e0d8;
  --border2: #d0cec4;
  --text: #1a1a18;
  --text2: #5a5a54;
  --text3: #8a8a82;
  --accent: #1a56db;
  --accent-bg: #eff4ff;
  --accent-border: #b4c6fc;
  --ai: #7c3aed;
  --ai-bg: #f5f3ff;
  --ai-border: #ddd6fe;
  --success: #059669;
  --success-bg: #ecfdf5;
  --warning: #d97706;
  --danger: #dc2626;
  --sidebar-w: 220px;
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  min-height: 100vh;
  line-height: 1.6;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 10;
}

.sidebar-brand {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.sidebar-brand em { font-style: normal; color: var(--accent); }
.brand-icon { font-size: 20px; }

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  border: none;
  background: none;
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  width: 100%;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent-bg); color: var(--accent); }
.nav-item.active .nav-num { background: var(--accent); color: #fff; }
.nav-item.done { color: var(--success); }
.nav-item.done .nav-num { background: var(--success); color: #fff; }

.nav-num {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text3);
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ===== MAIN ===== */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 5;
}
.ticket-ref {
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  font-family: 'Courier New', monospace;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text3);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border2);
}
.status-dot.active { background: var(--success); }
.status-dot.loading { background: var(--warning); }

/* ===== STAGES ===== */
.stage {
  display: none;
  padding: 32px 36px 48px;
  max-width: 820px;
}
.stage.active { display: block; }

.stage-header {
  margin-bottom: 24px;
}
.stage-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}
.stage-header p {
  color: var(--text2);
  font-size: 14px;
}

/* ===== FORMS ===== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }

label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="datetime-local"],
select,
textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  resize: vertical;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: #1447c0; }
.btn-primary:active { transform: scale(0.98); }

.btn-ai {
  background: var(--ai-bg);
  color: var(--ai);
  border: 1px solid var(--ai-border);
  border-radius: var(--radius);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-ai:hover { background: #ede9fe; }
.btn-ai:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-success {
  background: var(--success);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-ghost {
  background: none;
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-ghost:hover { background: var(--surface2); }
.btn-ghost.small { padding: 7px 12px; font-size: 12px; width: 100%; text-align: left; }

.action-bar {
  margin-top: 24px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.ai-action-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.email-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

/* ===== AI OUTPUT ===== */
.ai-output {
  background: var(--ai-bg);
  border: 1px solid var(--ai-border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-top: 4px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  position: relative;
}
.ai-output.hidden { display: none; }
.ai-output.loading::after {
  content: '▋';
  animation: blink 0.8s step-end infinite;
  color: var(--ai);
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

.ai-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ai);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.copy-btn {
  position: absolute;
  top: 12px; right: 12px;
  background: var(--surface);
  border: 1px solid var(--ai-border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--ai);
  cursor: pointer;
  font-weight: 600;
}
.copy-btn:hover { background: var(--ai-bg); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-header { text-align: center; }
.modal-icon { font-size: 32px; margin-bottom: 10px; }
.modal-header h2 { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.modal-header p { font-size: 13px; color: var(--text2); line-height: 1.6; }
.modal-hint { font-size: 12px; color: var(--text3); text-align: center; }
.modal-hint a { color: var(--accent); }

/* ===== CLOSED STATE ===== */
.ticket-closed {
  background: var(--success-bg);
  border: 1px solid #a7f3d0;
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  margin-top: 16px;
}
.ticket-closed h3 { font-size: 18px; color: var(--success); margin-bottom: 6px; }
.ticket-closed p { color: var(--text2); font-size: 14px; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
