:root {
  /* Modern SaaS Palette - Light Mode */
  --primary: #0ea5e9;
  --primary-hover: #0284c7;
  --secondary: #f1f5f9;
  --secondary-hover: #e2e8f0;
  
  --bg-page: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --danger-hover: #dc2626;
  
  --success: #10b981;
  --success-bg: #d1fae5;
  
  --radius-lg: 16px;
  --radius-md: 8px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

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

html, body {
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text-main);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
}

/* Header */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
  text-decoration: none;
}

.brand {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.topbar-text {
  color: var(--text-muted);
  font-size: 14px;
  border-left: 2px solid var(--border);
  padding-left: 16px;
  font-weight: 500;
}

/* Lang Switcher & Status */
.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.lang-switch,
.domain-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  outline: none;
  transition: all 0.2s;
}

.lang-switch:focus, .lang-switch:hover,
.domain-select:focus, .domain-select:hover {
  border-color: var(--primary);
}

.domain-select {
  min-width: 190px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
}

.secure-create-option {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
}

.secure-create-option:hover {
  border-color: var(--primary);
  color: var(--text-main);
  background: #f0f9ff;
}

.secure-checkbox {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.secure-checkmark {
  width: 15px;
  height: 15px;
  border: 1.5px solid #94a3b8;
  border-radius: 4px;
  background: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.secure-checkbox:checked + .secure-checkmark {
  background: var(--primary);
  border-color: var(--primary);
}

.secure-checkbox:checked + .secure-checkmark::after {
  content: '';
  width: 7px;
  height: 4px;
  border-left: 2px solid white;
  border-bottom: 2px solid white;
  transform: rotate(-45deg) translate(1px, -1px);
}

/* Control Center */
.control-center {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.inbox-display {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.inbox-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.inbox-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.inbox-email {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.01em;
  word-break: break-all;
}

.inbox-expiry {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.inbox-actions {
  display: flex;
  gap: 10px;
}

.toolbar-divider {
  height: 1px;
  background: var(--border-light);
  width: 100%;
}

.toolbar-main {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.open-form {
  display: flex;
  gap: 12px;
  flex: 1;
  min-width: 300px;
}

.input-wrapper {
  position: relative;
  flex: 1;
}

.password-wrapper {
  flex: 0 0 260px;
}

.password-wrapper .text-input {
  padding-right: 62px;
}

.password-eye {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 8px;
  cursor: pointer;
}

.password-eye:hover {
  color: var(--primary-hover);
}

.input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
}

.text-input {
  width: 100%;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px 12px 42px;
  color: var(--text-main);
  font-size: 14px;
  transition: all 0.2s;
  font-family: inherit;
}

.text-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
  background: var(--surface);
}

/* Buttons */
.button {
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
}

.button-primary {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

.button-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.button-secondary {
  background: var(--text-main);
  color: white;
}

.button-secondary:hover { background: #000; }

.button-outline {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-main);
}

.button-outline:hover {
  background: var(--secondary);
  border-color: #cbd5e1;
}

.button-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid transparent;
}

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

/* Workspace Layout */
.workspace {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
  flex: 1;
  min-height: 0;
}

/* Panels */
.list-panel, .viewer-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fcfcfc;
}

.panel-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
}

.auto-refresh-badge {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--secondary);
  padding: 4px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.list-container {
  overflow-y: auto;
  flex: 1;
}

.mail-list { padding: 12px; }

.mail-list.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-light);
  font-size: 14px;
}

.mail-item {
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: var(--surface);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.mail-item:hover {
  background: var(--bg-page);
  border-color: var(--border);
}

.mail-item.active {
  background: #f0f9ff;
  border-color: #bae6fd;
}

.mail-item.active::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 12px;
  bottom: 12px;
  width: 4px;
  background: var(--primary);
  border-radius: 0 4px 4px 0;
}

.mail-item-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
  gap: 8px;
}

.mail-item .subj {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.mail-pill {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 3px 6px;
  border-radius: 4px;
  background: var(--secondary);
  color: var(--text-muted);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.mail-item .from {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.mail-item .preview {
  font-size: 13px;
  color: var(--text-light);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
}

.mail-item .time {
  font-size: 11px;
  color: var(--text-light);
  text-align: right;
  font-weight: 500;
}

/* Viewer Panel */
.viewer-panel { position: relative; }

.viewer-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  background: var(--bg-page);
  padding: 40px;
  z-index: 10;
}

.empty-icon-wrapper {
  color: var(--text-light);
  margin-bottom: 16px;
  background: var(--surface);
  padding: 24px;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.viewer-empty h2 {
  font-size: 20px;
  color: var(--text-main);
  margin-bottom: 8px;
}

.viewer-empty p {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}

.viewer-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
}

.message-head {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.subject-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 12px;
  line-height: 1.3;
}

.message-meta-box {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px 12px;
}

.meta-item {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.meta-label {
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--text-light);
  letter-spacing: 0.05em;
  flex: 0 0 auto;
}

.meta-value {
  font-size: 13px;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.provider-badge {
  display: inline-block;
  width: fit-content;
  background: var(--secondary);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  border: 1px solid var(--border);
  flex: 0 0 auto;
}

/* Viewer Controls */
.viewer-controls {
  padding: 10px 22px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  background: #fcfcfc;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 16px;
}

.toggle-switch {
  display: flex;
  align-items: center;
  cursor: pointer;
  gap: 10px;
}

.toggle-switch input { display: none; }
.toggle-slider {
  position: relative;
  width: 36px;
  height: 20px;
  background-color: #cbd5e1;
  border-radius: 20px;
  transition: 0.3s;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: 0.3s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.toggle-switch input:checked + .toggle-slider { background-color: var(--primary); }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(16px); }
.toggle-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Message Body Area */
.message-body-container {
  padding: 22px;
  flex: 1;
}

.message-body {
  width: 100%;
  min-height: 400px;
}

.text-view {
  font-family: 'JetBrains Mono', 'Courier New', Courier, monospace;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: #334155;
  background: var(--bg-page);
  padding: 24px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.html-view {
  border: none;
  background: white;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  height: 600px;
}

/* Attachments */
.attachments {
  padding: 24px 32px;
  border-top: 1px solid var(--border);
  background: #fcfcfc;
  margin-top: auto;
}

.attachments-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main);
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.attachment-list.muted {
  color: var(--text-light);
  font-size: 14px;
}

.attachment-link {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.attachment-link::before {
  content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="%2364748b" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"></path><polyline points="13 2 13 9 20 9"></polyline></svg>');
  display: inline-block;
  width: 14px;
  height: 14px;
}

.attachment-link:hover {
  border-color: var(--primary);
  background: #f0f9ff;
  color: var(--primary);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.hidden { display: none !important; }

/* Responsive */
@media (max-width: 1024px) {
  .workspace { grid-template-columns: 300px 1fr; }
}

@media (max-width: 860px) {
  .app-shell { padding: 16px; height: auto; }
  .workspace {
    grid-template-columns: 1fr;
    display: flex;
    flex-direction: column;
  }
  .list-panel { height: 400px; flex-shrink: 0; }
  .viewer-panel { min-height: 600px; }
  .inbox-display, .toolbar-main { flex-direction: column; align-items: stretch; }
  .inbox-actions, .open-form { flex-wrap: wrap; }
  .inbox-actions .button { flex: 1; }
  .header-actions { flex-direction: column; align-items: flex-end; gap: 8px; }
}
