:root {
  --primary: #0078d4;
  --primary-hover: #106ebe;
  --secondary: #605e5c;
  --bg: #ffffff;
  --surface: #f3f2f1;
  --text: #323130;
  --text-muted: #8a8886;
  --border: #edebe9;
  --error-bg: #fde7e9;
  --error-text: #a80000;
  --success: #107c10;
  --radius: 6px;
}

:root.dark-theme {
  --primary: #4ca6e8;
  --primary-hover: #6ab8f0;
  --secondary: #b3b0ad;
  --bg: #1e1e1e;
  --surface: #2d2d2d;
  --text: #e0e0e0;
  --text-muted: #a0a0a0;
  --border: #3c3c3c;
  --error-bg: #442222;
  --error-text: #f48771;
  --success: #4ec94e;
}

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

body {
  font-family:
    "Segoe UI",
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

#app {
  padding: 16px;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.header-logo {
  width: 24px;
  height: 24px;
}

.header-action {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  padding: 4px;
}

#back-btn {
  left: 0;
  right: auto;
}

/* Cards (shared) */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin: 10px 0;
}

/* Advanced collapsible section (wraps the Agent card) */
.advanced {
  margin-top: 12px;
}

.advanced > .advanced-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  user-select: none;
}

.advanced > .advanced-summary::-webkit-details-marker {
  display: none;
}

.advanced-chevron {
  display: inline-block;
  transition: transform 0.15s ease;
  color: var(--text-muted);
}

.advanced[open] .advanced-chevron {
  transform: rotate(90deg);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.card-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-header h3,
.card-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.card-icon {
  font-size: 18px;
  line-height: 1;
}

.card-body {
  padding: 16px;
}

.card-description {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.4;
}

.account-identity {
  display: flex;
  align-items: center;
  gap: 12px;
}

.account-avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--primary) 15%, transparent);
  color: var(--primary);
  font-size: 18px;
  font-weight: 600;
}

.account-identity strong,
.account-identity span {
  display: block;
}

.account-identity strong {
  font-size: 13px;
  overflow-wrap: anywhere;
}

.account-status {
  margin-top: 2px;
  color: var(--success);
  font-size: 12px;
}

.settings-details {
  padding-top: 6px;
  padding-bottom: 6px;
}

.settings-detail-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  font-size: 12px;
}

.settings-detail-row + .settings-detail-row {
  border-top: 1px solid var(--border);
}

.settings-detail-row span {
  color: var(--text-muted);
}

.settings-detail-row strong {
  max-width: 58%;
  overflow-wrap: anywhere;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
}

.btn-sign-out {
  width: 100%;
  margin-top: 2px;
  border: 1px solid var(--error-text);
  background: var(--bg);
  color: var(--error-text);
}

.btn-sign-out:hover:not(:disabled) {
  background: var(--error-bg);
}

#settings-error-box {
  margin-top: 10px;
}

.card-description a {
  color: var(--primary);
  text-decoration: none;
}

.card-description a:hover {
  text-decoration: underline;
}

.settings-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.15s;
}

.settings-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

/* Agent dropdown */
select.settings-input {
  appearance: none;
  -webkit-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='%23605e5c' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  cursor: pointer;
}

select.settings-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.refresh-agents-btn {
  flex: 0 0 auto;
  margin-left: 6px;
  padding: 6px;
  font-size: 16px;
}

/* Test connection button */
.btn-test-connection {
  width: 100%;
  margin-top: 10px;
  background: var(--primary);
  color: white;
  font-size: 12px;
  padding: 8px 18px;
  font-weight: 600;
}

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

/* Connection / agent status messages */
.connection-status {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  line-height: 1.4;
}

.connection-status-success {
  background: color-mix(in srgb, var(--success) 15%, transparent);
  color: var(--success);
}

.connection-status-error {
  background: var(--error-bg);
  color: var(--error-text);
}

.connection-status-warning {
  background: color-mix(in srgb, orange 15%, transparent);
  color: #996a13;
}

:root.dark-theme .connection-status-warning {
  color: #e8a735;
}

#main-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#main-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#settings-view {
  flex: 1;
}

/* Version footer */
.app-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  text-align: right;
}

.version-text {
  font-size: 10px;
  color: var(--text-muted);
  font-style: italic;
  font-weight: bold;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.15s,
    opacity 0.15s;
  font-family: inherit;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-reply {
  width: 100%;
  background: #107c10;
  color: white;
  margin: 0 0 12px 0;
}

.btn-reply:hover:not(:disabled) {
  background: #0b5e0b;
}

/* Tone rewrite */
#tone-section {
  margin-bottom: 12px;
}

.tone-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.tone-chip {
  flex: 1 1 calc(50% - 8px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
}

.tone-chip-icon {
  font-size: 15px;
  line-height: 1;
}

.tone-chip:hover:not(:disabled) {
  border-color: var(--primary);
}

.tone-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.tone-chip:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.tone-actions {
  margin-bottom: 12px;
}

.tone-applied-status {
  font-size: 13px;
  font-weight: 600;
  color: var(--success);
  text-align: center;
}

#custom-instructions-section {
  margin-bottom: 12px;
}

#custom-instructions-section label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text);
}

.custom-prompt-textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  resize: vertical;
  margin-bottom: 10px;
}

.custom-prompt-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.btn-secondary {
  background: var(--primary);
  color: white;
  font-size: 12px;
  padding: 8px 18px;
  font-weight: 600;
}

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

.btn-icon {
  background: transparent;
  padding: 4px 8px;
  font-size: 16px;
  border-radius: 4px;
  color: var(--text);
}

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

/* Email preview */
#email-preview {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 13px;
  max-height: 150px;
  overflow-y: auto;
}

#email-preview .email-meta {
  margin-bottom: 8px;
  color: var(--secondary);
  font-size: 12px;
}

#email-preview .email-meta strong {
  color: var(--text);
}

/* Response */
#response-box {
  margin-top: 16px;
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#response-content {
  font-size: 13px;
  word-break: break-word;
  flex: 0 1 auto;
  overflow-y: auto;
  min-height: 0;
}

#response-content h1,
#response-content h2,
#response-content h3 {
  margin: 12px 0 6px;
  font-weight: 600;
  color: var(--text);
}

#response-content h1 {
  font-size: 16px;
}
#response-content h2 {
  font-size: 14px;
}
#response-content h3 {
  font-size: 13px;
}

#response-content p {
  margin: 6px 0;
}

#response-content ul,
#response-content ol {
  margin: 6px 0;
  padding-left: 20px;
}

#response-content li {
  margin: 3px 0;
}

#response-content code {
  background: var(--surface);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}

#response-content pre {
  background: var(--surface);
  padding: 8px 10px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 8px 0;
}

#response-content pre code {
  background: none;
  padding: 0;
}

#response-content strong {
  font-weight: 600;
}

#response-content blockquote {
  border-left: 3px solid var(--primary);
  margin: 8px 0;
  padding: 4px 10px;
  color: var(--text-muted);
}

#response-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

#response-content a {
  color: var(--primary);
  text-decoration: none;
}

#response-content a:hover {
  text-decoration: underline;
}

/* Error */
#error-box {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--error-bg);
  color: var(--error-text);
  border-radius: var(--radius);
  font-size: 13px;
}

/* Spinner */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Loading card */
#loading-box {
  margin-top: 16px;
}

#loading-box .card-header h2 {
  animation: pulse-text 1.5s ease-in-out infinite;
}

@keyframes pulse-text {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.loading-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shimmer-line {
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    var(--border) 25%,
    var(--surface) 50%,
    var(--border) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

.shimmer-long {
  width: 100%;
}
.shimmer-medium {
  width: 75%;
}
.shimmer-short {
  width: 50%;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.hidden {
  display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--secondary);
}
