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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  min-height: 100vh;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* Login View */
.login-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
}

.login-container h1 {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.login-container .subtitle {
  opacity: 0.9;
  margin-bottom: 2rem;
  font-size: 1.1rem;
}

#login-form {
  width: 100%;
  max-width: 320px;
}

#login-form input {
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  margin-bottom: 12px;
  background: rgba(255,255,255,0.95);
}

#login-form input:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.3);
}

#login-form button {
  width: 100%;
  padding: 14px;
  background: white;
  color: var(--primary);
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s;
}

#login-form button:active {
  transform: scale(0.98);
}

.hint {
  font-size: 0.875rem;
  opacity: 0.7;
  margin-top: 1.5rem;
}

/* Header */
header {
  background: white;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#user-name {
  font-size: 0.875rem;
  color: var(--gray-500);
}

.btn-icon {
  background: none;
  border: 1px solid var(--gray-300);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  cursor: pointer;
  color: var(--gray-500);
}

/* Tabs */
.tabs {
  display: flex;
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 0 12px;
}

.tab {
  flex: 1;
  padding: 14px 8px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.badge {
  position: absolute;
  top: 8px;
  right: calc(50% - 30px);
  background: var(--danger);
  color: white;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 600;
}

/* Tab Content */
.tab-content {
  padding: 16px;
  min-height: calc(100vh - 130px);
}

/* Message List */
.message-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.1s;
  border-left: 4px solid var(--gray-300);
}

.message-card:active {
  transform: scale(0.99);
}

.message-card.priority-urgent {
  border-left-color: var(--danger);
}

.message-card.priority-high {
  border-left-color: var(--warning);
}

.message-card.priority-normal {
  border-left-color: var(--primary);
}

.message-card .prompt {
  font-size: 1rem;
  margin-bottom: 8px;
  line-height: 1.4;
}

.message-card .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8125rem;
  color: var(--gray-500);
}

.protocol-badge {
  background: var(--gray-100);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.response-type-hint {
  font-size: 0.8125rem;
  color: var(--gray-500);
  font-style: italic;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-500);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

/* Input Type Grid */
.input-type-grid {
  display: grid;
  gap: 12px;
}

.input-type-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.1s;
  border: 2px solid transparent;
}

.input-type-card:active {
  transform: scale(0.98);
}

.input-type-card:hover {
  border-color: var(--primary);
}

.input-type-card h3 {
  font-size: 1.1rem;
  margin-bottom: 4px;
}

.input-type-card p {
  font-size: 0.875rem;
  color: var(--gray-500);
}

/* Forms */
.btn-back {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 1rem;
  cursor: pointer;
  padding: 8px 0;
  margin-bottom: 8px;
}

#input-form-title {
  font-size: 1.25rem;
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--gray-700);
}

.form-group label .required {
  color: var(--danger);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 16px;
  font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
  min-height: 100px;
  resize: vertical;
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-primary:disabled {
  background: var(--gray-300);
  cursor: not-allowed;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: 0;
}

.modal-content {
  background: white;
  width: 100%;
  max-height: 90vh;
  border-radius: 16px 16px 0 0;
  padding: 20px;
  overflow-y: auto;
  position: relative;
  animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--gray-100);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--gray-500);
}

#message-detail .message-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.priority-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
  text-transform: uppercase;
}

.priority-badge.urgent {
  background: #fef2f2;
  color: var(--danger);
}

.priority-badge.high {
  background: #fffbeb;
  color: #b45309;
}

.priority-badge.normal {
  background: #eff6ff;
  color: var(--primary);
}

.priority-badge.low {
  background: var(--gray-100);
  color: var(--gray-500);
}

#message-detail .time {
  font-size: 0.8125rem;
  color: var(--gray-500);
}

#message-detail .prompt {
  font-size: 1.25rem;
  line-height: 1.4;
  margin-bottom: 16px;
}

#message-detail .context {
  background: var(--gray-50);
  padding: 12px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 0.875rem;
}

.context-item {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
}

.context-item .key {
  color: var(--gray-500);
}

/* Response Types */
#response-area {
  margin-top: 20px;
}

.response-buttons {
  display: flex;
  gap: 12px;
}

.response-buttons button {
  flex: 1;
  padding: 16px;
  border: 2px solid var(--gray-200);
  background: white;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.response-buttons .btn-yes {
  border-color: var(--success);
  color: var(--success);
}

.response-buttons .btn-yes:hover {
  background: var(--success);
  color: white;
}

.response-buttons .btn-no {
  border-color: var(--danger);
  color: var(--danger);
}

.response-buttons .btn-no:hover {
  background: var(--danger);
  color: white;
}

.btn-confirm {
  width: 100%;
  padding: 16px;
  background: var(--success);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.choice-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.choice-option {
  padding: 14px 16px;
  border: 2px solid var(--gray-200);
  background: white;
  border-radius: var(--radius);
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
}

.choice-option:hover {
  border-color: var(--primary);
}

.choice-option.selected {
  border-color: var(--primary);
  background: #eff6ff;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-900);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  animation: fadeIn 0.2s;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* History items */
.message-card.responded {
  opacity: 0.8;
  border-left-color: var(--success);
}

.message-card .response-preview {
  font-size: 0.875rem;
  color: var(--success);
  margin-top: 8px;
  font-weight: 500;
}

/* Desktop adjustments */
@media (min-width: 640px) {
  .modal-content {
    max-width: 480px;
    border-radius: 16px;
    margin: 20px;
  }

  .modal {
    align-items: center;
  }

  .input-type-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .tab-content {
    max-width: 600px;
    margin: 0 auto;
  }
}
