/* ============================================================
   Survey Web App — Style
   ============================================================ */

:root {
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-light: #EEF2FF;
  --bg: #F3F4F6;
  --card: #FFFFFF;
  --text: #1F2937;
  --text2: #6B7280;
  --muted: #9CA3AF;
  --border: #E5E7EB;
  --danger: #EF4444;
  --danger-hover: #DC2626;
  --success: #10B981;
  --warning: #F59E0B;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
  --radius: 8px;
  --radius-lg: 12px;
  --max-width: 860px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

html { font-size: 16px; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--card);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
}

header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  color: var(--primary);
}

header nav { display: flex; gap: 4px; }

header nav a {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text2);
  text-decoration: none;
  transition: all .15s;
}

header nav a:hover,
header nav a.active {
  color: var(--primary);
  background: var(--primary-light);
}

/* ── Main views ── */
.view {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ── Hidden ── */
.hidden { display: none !important; }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 22px;
  border-radius: 20px;
  font-size: .875rem;
  color: #fff;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
}
#toast.show { opacity: 1; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 7px;
  border: 1px solid var(--border);
  font-size: .875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
  background: var(--card);
  color: var(--text);
}
.btn:hover { opacity: .85; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 4px 10px; font-size: .8rem; }
.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: 6px; font-size: .85rem; }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.toolbar input[type="text"] {
  width: 220px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: .875rem;
  font-family: inherit;
  outline: none;
}
.toolbar input[type="text"]:focus { border-color: var(--primary); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 1rem;
}

/* ── Survey list cards ── */
.survey-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: box-shadow .15s;
}
.survey-card:hover { box-shadow: var(--shadow-md); }
.card-info { flex: 1; min-width: 0; }
.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: .8rem;
  color: var(--text2);
  flex-wrap: wrap;
}
.card-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Status badges */
.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: .75rem;
  font-weight: 600;
}
.status-active { background: #D1FAE5; color: #065F46; }
.status-draft { background: #F3F4F6; color: var(--text2); }
.status-closed { background: #FEE2E2; color: #991B1B; }

/* ── Forms ── */
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  margin-bottom: 5px;
  font-size: .875rem;
  font-weight: 500;
}
.required { color: var(--danger); }
.hint { color: var(--muted); font-size: .8rem; font-weight: 400; }

input[type="text"],
input[type="number"],
input[type="password"],
input[type="datetime-local"],
textarea,
select {
  width: 100%;
  padding: 9px 12px;
  font-size: .9rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--card);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); }
textarea { min-height: 72px; resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23999' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 16px; height: 16px; cursor: pointer; vertical-align: middle; }

.form-row { display: flex; flex-wrap: wrap; gap: 14px; }
.form-row .form-group { flex: 1; min-width: 180px; }
.form-actions { display: flex; gap: 10px; margin-top: 24px; flex-wrap: wrap; }

/* ── Question cards (editor) ── */
.question-card {
  background: var(--card);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 14px;
}
.q-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.drag-handle { color: var(--muted); cursor: grab; font-size: 1.1rem; user-select: none; flex-shrink: 0; }
.q-number { font-weight: 700; color: var(--primary); font-size: .9rem; flex-shrink: 0; min-width: 24px; }
.q-header > input[type="text"] { flex: 1; min-width: 160px; }
.q-header > select { width: auto; min-width: 90px; flex-shrink: 0; }
.q-actions { display: flex; gap: 4px; flex-shrink: 0; }

.options-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.option-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.option-row > span { color: var(--muted); font-size: .8rem; width: 22px; text-align: right; flex-shrink: 0; }
.option-row > input[type="text"] { flex: 1; }

.q-footer {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
}
.q-footer label { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--text2); cursor: pointer; margin: 0; }

/* ── Take survey ── */
.take-question {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin-bottom: 14px;
}
.tq-title { font-size: 1rem; font-weight: 600; margin-bottom: 14px; color: var(--text); }
.required-star { color: var(--danger); margin-left: 2px; }

/* Option items in take view */
.take-question .option-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all .15s;
}
.take-question .option-item:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.take-question .option-item label { flex: 1; cursor: pointer; margin: 0; font-weight: 400; font-size: .92rem; }
.take-question textarea { margin-top: 4px; }
.take-question input[type="checkbox"] { width: 18px; height: 18px; }

/* Rating stars */
.rating-stars { display: flex; gap: 4px; }
.rating-stars .star {
  font-size: 2rem;
  cursor: pointer;
  color: var(--border);
  transition: color .15s, transform .12s;
  user-select: none;
  line-height: 1;
}
.rating-stars .star:hover { transform: scale(1.15); }
.rating-stars .star.selected { color: #F59E0B; }

/* ── Done / Closed states ── */
.done-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 80px 20px;
}
.done-state h2 { font-size: 1.5rem; margin-bottom: 8px; }
.done-state p { color: var(--text2); font-size: 1rem; }

/* Loading */
.loading { text-align: center; padding: 60px 20px; color: var(--muted); font-size: .95rem; }

/* Survey description */
.survey-desc { color: var(--text2); font-size: .95rem; margin-bottom: 24px; }

/* ── Tabs (results) ── */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  gap: 0;
}
.tab {
  padding: 10px 22px;
  font-size: .9rem;
  font-weight: 500;
  color: var(--text2);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: all .15s;
  font-family: inherit;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content.hidden { display: none; }

/* ── Stats / Charts ── */
.chart-wrap {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 14px;
}
.chart-wrap h4 { margin: 0 0 14px 0; font-size: .95rem; font-weight: 600; }
.chart-wrap canvas { max-height: 300px; }

.text-responses { display: flex; flex-direction: column; gap: 6px; max-height: 400px; overflow-y: auto; }
.text-response-item {
  padding: 10px 14px;
  background: #F9FAFB;
  border-radius: 6px;
  font-size: .9rem;
  color: var(--text);
  border-left: 3px solid var(--primary);
}

/* ── Response table ── */
.resp-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.resp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
  min-width: 600px;
  background: var(--card);
}
.resp-table thead {
  position: sticky;
  top: 56px;
  z-index: 5;
}
.resp-table th {
  background: #F9FAFB;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text2);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.resp-table td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.resp-table tbody tr:nth-child(even) { background: #FAFBFC; }
.resp-table tbody tr:hover { background: var(--primary-light); }

/* ── Responsive ── */
@media (max-width: 640px) {
  header { padding: 0 12px; }
  header h1 { font-size: 1rem; }
  header nav a { padding: 5px 8px; font-size: .8rem; }

  .view { padding: 16px 12px 40px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar input[type="text"] { width: 100%; }

  .survey-card { flex-direction: column; align-items: stretch; }
  .card-actions { flex-wrap: wrap; }
  .card-actions .btn { flex: 1; }

  .form-row { flex-direction: column; gap: 0; }
  .form-row .form-group { min-width: 100%; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; }

  .q-header { flex-direction: column; align-items: stretch; }
  .q-header > input[type="text"] { min-width: 100%; }
  .q-actions { justify-content: flex-end; }

  .chart-wrap canvas { max-height: 240px; }
  .tabs { overflow-x: auto; }
}
