/* Polaris Dashboard Styles */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #007AFF;
  --primary-hover: #0062CC;
  --bg: #f5f5f7;
  --card-bg: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #666;
  --border: #e0e0e0;
  --success: #34C759;
  --danger: #FF3B30;
  --radius: 10px;
}

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

/* Screens */
.screen { display: none; }
.screen.active { display: block; }

/* Login */
.login-card {
  max-width: 380px;
  margin: 120px auto;
  padding: 40px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  text-align: center;
}

.login-card h1 {
  font-size: 28px;
  margin-bottom: 8px;
  color: var(--primary);
}

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

.login-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 12px;
  outline: none;
}

.login-card input:focus { border-color: var(--primary); }

.login-card button {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.login-card button:hover { background: var(--primary-hover); }

.hint { margin-top: 16px; font-size: 13px; color: var(--text-secondary); }
.hint a { color: var(--primary); text-decoration: none; }

/* Dashboard Header */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 20px;
  color: var(--primary);
}

header span {
  flex: 1;
  font-size: 14px;
  color: var(--text-secondary);
}

/* Navigation */
nav {
  display: flex;
  gap: 2px;
  padding: 12px 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  padding: 8px 16px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  white-space: nowrap;
}

.tab:hover { background: var(--bg); }
.tab.active { background: var(--primary); color: white; }

/* Tab Content */
.tab-content { display: none; padding: 24px; max-width: 800px; }
.tab-content.active { display: block; }

.tab-content h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.tab-content p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 16px;
}

/* Buttons */
.btn-primary {
  padding: 10px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

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

.btn-secondary {
  padding: 8px 16px;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-secondary);
}

.btn-secondary:hover { border-color: var(--text-secondary); }

.btn-danger {
  padding: 6px 12px;
  background: none;
  border: 1.5px solid var(--danger);
  color: var(--danger);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

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

/* Upload Area */
.upload-area {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--card-bg);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

#upload-status {
  font-size: 13px;
  color: var(--text-secondary);
}

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

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.list-item .info {
  flex: 1;
}

.list-item .info h4 {
  font-size: 14px;
  font-weight: 600;
}

.list-item .info p {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 2px 0 0;
}

.list-item .status {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 500;
}

.status-ready { background: #E8F5E9; color: #2E7D32; }
.status-processing { background: #FFF3E0; color: #E65100; }
.status-error { background: #FFEBEE; color: #B71C1C; }
.status-confirmed { background: #E3F2FD; color: #1565C0; }

/* Forms */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 16px 0 6px;
  color: var(--text);
}

textarea, .tab-content input[type="text"],
.tab-content input[type="email"],
.tab-content input[type="number"],
.tab-content input[type="time"] {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: var(--card-bg);
}

textarea:focus, .tab-content input:focus {
  border-color: var(--primary);
}

textarea { resize: vertical; }

.schedule-table { overflow-x: auto; margin-bottom: 16px; }

.schedule-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.schedule-table th, .schedule-table td {
  padding: 6px 8px;
  border: 1px solid var(--border);
  text-align: center;
}

.schedule-table th {
  background: var(--bg);
  font-weight: 600;
  font-size: 12px;
}

.schedule-table td:first-child { text-align: left; font-weight: 500; }

.schedule-table input[type="time"] { width: 100px; padding: 2px 4px; border: 1px solid var(--border); border-radius: 4px; }
.schedule-table input[type="checkbox"] { width: 18px; height: 18px; }

.closures-list { margin-bottom: 12px; }

.closure-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 13px;
}

.btn-danger-sm {
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 4px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.add-closure-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.add-closure-form input { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }

/* Add Service Form */
.add-service-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
  padding: 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.add-service-form .btn-primary {
  grid-column: span 2;
}

/* Test Chat */
.test-chat {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.test-messages {
  height: 350px;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.test-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
}

.test-msg.user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
}

.test-msg.bot {
  align-self: flex-start;
  background: var(--bg);
}

.msg-timestamp {
  display: block;
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 4px;
  opacity: 0.6;
}

.test-msg.bot strong, .mgmt-msg.bot strong { font-weight: 600; }
.test-msg.bot code, .mgmt-msg.bot code { background: rgba(0,0,0,0.06); padding: 1px 4px; border-radius: 3px; font-size: 0.9em; }
.test-msg.bot ul, .test-msg.bot ol, .mgmt-msg.bot ul, .mgmt-msg.bot ol { margin: 4px 0 4px 16px; }
.test-msg.bot li, .mgmt-msg.bot li { margin: 2px 0; }

.test-input {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

.test-input input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  outline: none;
}

.test-input button {
  padding: 10px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
}

/* Test Chat Actions */
.test-actions {
  align-self: flex-start;
  max-width: 90%;
}

.test-actions-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.test-actions-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.test-action-btn {
  padding: 8px 14px;
  border: 1.5px solid var(--primary);
  background: white;
  color: var(--primary);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.test-action-btn:hover:not(:disabled) {
  background: var(--primary);
  color: white;
}

.test-action-btn:disabled {
  border-color: var(--border);
  color: #bbb;
  cursor: not-allowed;
}

.test-action-btn.service {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 16px;
  border-radius: 10px;
}

.test-action-btn.service span {
  font-size: 11px;
  opacity: 0.7;
}

.test-form {
  align-self: flex-start;
  max-width: 80%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--card-bg);
  border: 1.5px solid var(--primary);
  border-radius: 12px;
  padding: 14px;
}

.test-form input {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
}

.test-form input:focus {
  border-color: var(--primary);
}

.test-confirmation {
  align-self: flex-start;
  background: #E8F5E9;
  border: 1px solid #A5D6A7;
  border-radius: 12px;
  padding: 16px 20px;
  max-width: 80%;
  text-align: center;
}

.test-confirmation .confirm-icon {
  width: 36px;
  height: 36px;
  background: var(--success);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: bold;
  margin: 0 auto 8px;
}

.test-confirmation h4 {
  font-size: 15px;
  color: #2E7D32;
  margin-bottom: 6px;
}

.test-confirmation p {
  font-size: 13px;
  color: var(--text);
  margin: 2px 0;
}

/* Onboarding Setup Assistant (embedded in dashboard) */
.onboarding-chat-frame {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.ob-messages {
  height: 400px;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.ob-msg.user { align-self: flex-end; background: var(--primary); color: white; }
.ob-msg.bot { align-self: flex-start; background: var(--bg); }
.ob-msg.system { align-self: center; background: #E8F5E9; color: #2E7D32; font-size: 13px; padding: 6px 14px; border-radius: 16px; }
.ob-msg.error { align-self: center; background: #FFEBEE; color: #B71C1C; font-size: 13px; padding: 6px 14px; border-radius: 16px; }

.ob-typing {
  align-self: flex-start;
  padding: 10px 16px;
  background: var(--bg);
  border-radius: 14px;
  display: flex;
  gap: 4px;
}

.ob-typing span {
  width: 7px; height: 7px; background: #999; border-radius: 50%;
  animation: ob-bounce 1.4s ease-in-out infinite;
}
.ob-typing span:nth-child(2) { animation-delay: 0.2s; }
.ob-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ob-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

.ob-input-bar {
  display: flex; gap: 8px; padding: 12px;
  border-top: 1px solid var(--border); align-items: center;
}

.ob-input-bar input[type="text"] {
  flex: 1; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: 20px; font-size: 14px; outline: none;
}
.ob-input-bar input[type="text"]:focus { border-color: var(--primary); }
.ob-input-bar input[type="text"].password-mode { -webkit-text-security: disc; }

.ob-input-bar button:last-child {
  padding: 10px 20px; background: var(--primary); color: white;
  border: none; border-radius: 20px; font-size: 14px; cursor: pointer;
}

.ob-upload-btn {
  width: 36px; height: 36px; border: none; background: none;
  color: var(--text-secondary); cursor: pointer; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.ob-upload-btn:hover { background: var(--bg); color: var(--primary); }

.ob-embed-block {
  align-self: flex-start; max-width: 90%;
  background: #1a1a1a; border-radius: 8px; overflow: hidden;
}
.ob-embed-block-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px; background: #2a2a2a; font-size: 12px; color: #999;
}
.ob-embed-block-header button {
  padding: 3px 8px; background: #444; color: #ddd;
  border: none; border-radius: 4px; font-size: 11px; cursor: pointer;
}
.ob-embed-block pre {
  margin: 0; padding: 10px 12px; color: #e0e0e0;
  font-size: 12px; line-height: 1.5; overflow-x: auto; background: transparent;
}

/* Embed Code */
pre {
  background: #1a1a1a;
  color: #e0e0e0;
  padding: 16px;
  border-radius: 8px;
  font-size: 13px;
  overflow-x: auto;
  margin-bottom: 12px;
  line-height: 1.6;
}

/* Floating Management Assistant Widget */
#mgmt-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
}

#mgmt-fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  transition: transform 0.2s, box-shadow 0.2s;
}

#mgmt-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

.mgmt-panel {
  display: none;
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 380px;
  max-height: 520px;
  background: var(--card-bg);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  overflow: hidden;
  flex-direction: column;
}

.mgmt-panel.open {
  display: flex;
}

.mgmt-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--primary);
  color: white;
  font-weight: 600;
  font-size: 14px;
}

.mgmt-header button {
  background: none;
  border: none;
  color: white;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

.mgmt-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 300px;
  max-height: 380px;
}

.mgmt-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
}

.mgmt-msg.user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
}

.mgmt-msg.bot {
  align-self: flex-start;
  background: var(--bg);
  color: var(--text);
}

.mgmt-msg.system {
  align-self: center;
  background: #E8F5E9;
  color: #2E7D32;
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 14px;
}

.mgmt-typing {
  align-self: flex-start;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 14px;
  display: flex;
  gap: 4px;
}

.mgmt-typing span {
  width: 6px; height: 6px; background: #999; border-radius: 50%;
  animation: mgmt-bounce 1.4s ease-in-out infinite;
}
.mgmt-typing span:nth-child(2) { animation-delay: 0.2s; }
.mgmt-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes mgmt-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

.mgmt-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

.mgmt-input-bar input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
}

.mgmt-input-bar input:focus { border-color: var(--primary); }

.mgmt-input-bar button {
  padding: 10px 18px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

/* Responsive */
@media (max-width: 600px) {
  .tab-content { padding: 16px; }
  .add-service-form { grid-template-columns: 1fr; }
  .add-service-form .btn-primary { grid-column: span 1; }
  nav { padding: 8px 12px; }
}
