:root {
  color-scheme: light;
  font-family: system-ui, sans-serif;

  --bg: #ffffff;
  --fg: #1f2937;
  --panel-bg: #ffffff;
  --border: #cccccc;
  --hover-bg: #f0f0f0;
  --muted: #666666;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --accent-disabled: #93b4f0;
  --secondary-bg: #e5e7eb;
  --error: #dc2626;
  --success: #16a34a;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111827;
  --fg: #e5e7eb;
  --panel-bg: #1f2937;
  --border: #374151;
  --hover-bg: #27303f;
  --muted: #9ca3af;
  --accent: #3b82f6;
  --accent-fg: #ffffff;
  --accent-disabled: #3b5480;
  --secondary-bg: #374151;
  --error: #f87171;
  --success: #4ade80;
}

:root[data-theme="ocean"] {
  --bg: #f0f9ff;
  --fg: #0c4a6e;
  --panel-bg: #ffffff;
  --border: #bae6fd;
  --hover-bg: #e0f2fe;
  --muted: #0369a1;
  --accent: #0284c7;
  --accent-fg: #ffffff;
  --accent-disabled: #7dd3fc;
  --secondary-bg: #e0f2fe;
  --error: #dc2626;
  --success: #059669;
}

:root[data-theme="sunset"] {
  --bg: #fff7ed;
  --fg: #7c2d12;
  --panel-bg: #fffbeb;
  --border: #fed7aa;
  --hover-bg: #ffedd5;
  --muted: #9a3412;
  --accent: #ea580c;
  --accent-fg: #ffffff;
  --accent-disabled: #fdba74;
  --secondary-bg: #ffedd5;
  --error: #dc2626;
  --success: #15803d;
}

body {
  margin: 0;
  height: 100vh;
  background: var(--bg);
  color: var(--fg);
}

#app {
  display: flex;
  height: 100vh;
}

#domains {
  width: 220px;
  flex: 0 0 220px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 0.5rem;
  box-sizing: border-box;
  background: var(--panel-bg);
}

#domains h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

#domain-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
}

#domain-list li {
  padding: 0.4rem 0.5rem;
  cursor: pointer;
  border-radius: 4px;
  word-break: break-all;
}

#domain-list li:hover {
  background: var(--hover-bg);
}

#domain-list li.selected {
  background: var(--accent);
  color: var(--accent-fg);
}

#domain-list li.error {
  color: var(--error);
  cursor: default;
}

#settings {
  flex: 0 0 auto;
  position: relative;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}

#settings-toggle {
  width: 100%;
  padding: 0.4rem 0.5rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
  cursor: pointer;
  text-align: left;
}

#theme-picker {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin-bottom: 0.25rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.theme-option {
  padding: 0.35rem 0.5rem;
  background: none;
  border: none;
  border-radius: 4px;
  color: var(--fg);
  text-align: left;
  cursor: pointer;
}

.theme-option:hover {
  background: var(--hover-bg);
}

#user-footer {
  flex: 0 0 auto;
  padding-top: 0.5rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.85rem;
}

#user-email {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#logout-link {
  flex: 0 0 auto;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}

#logout-link:hover {
  text-decoration: underline;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#fields {
  flex: 0 0 auto;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.field label {
  width: 70px;
  flex: 0 0 70px;
  font-weight: 600;
}

.field input {
  flex: 1;
  padding: 0.35rem 0.5rem;
  font-size: 1rem;
  background: var(--panel-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.from-row {
  display: flex;
  flex: 1;
  gap: 0.4rem;
  align-items: center;
}

.from-row input {
  flex: 0 0 160px;
}

#from-domain {
  color: var(--muted);
}

#body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1rem;
  min-height: 0;
}

#message {
  flex: 1;
  resize: none;
  padding: 0.5rem;
  font-family: inherit;
  font-size: 1rem;
  box-sizing: border-box;
  background: var(--panel-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
}

#status {
  min-height: 1.2rem;
  margin: 0.4rem 0;
  font-size: 0.9rem;
}

#status.error {
  color: var(--error);
}

#status.success {
  color: var(--success);
}

#actions {
  display: flex;
  gap: 0.5rem;
}

#actions button {
  padding: 0.5rem 1.25rem;
  font-size: 1rem;
  cursor: pointer;
  border-radius: 4px;
  border: none;
}

#send {
  background: var(--accent);
  color: var(--accent-fg);
}

#send:disabled {
  background: var(--accent-disabled);
  cursor: default;
}

#cancel {
  background: var(--secondary-bg);
  color: var(--fg);
}

#history {
  width: 280px;
  flex: 0 0 280px;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  padding: 0.5rem;
  box-sizing: border-box;
  background: var(--panel-bg);
}

#history h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

#history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

#history-list li {
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  margin-bottom: 0.25rem;
  border-left: 3px solid transparent;
}

#history-list li:hover {
  background: var(--hover-bg);
}

#history-list li.success {
  border-left-color: var(--success);
}

#history-list li.error {
  border-left-color: var(--error);
  cursor: pointer;
}

#history-list li.empty {
  color: var(--muted);
  cursor: default;
  border-left-color: transparent;
}

.history-to {
  font-weight: 600;
  word-break: break-all;
}

.history-subject {
  color: var(--muted);
  font-size: 0.9rem;
}

.history-time {
  color: var(--muted);
  font-size: 0.75rem;
}
