:root {
  --sidebar-w: 230px;
  --middle-w: 380px;
  --primary: #1a73e8;
  --primary-hover: #1557b0;
  --bg-sidebar: #f6f8fc;
  --bg-panel: #ffffff;
  --border: #e0e4e8;
  --text-main: #202124;
  --text-muted: #5f6368;
  --unread-color: #1a73e8;
  --badge-bg: #d93025;
  --star-color: #f4b400;
  --danger: #d93025;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text-main);
  background: #f1f3f4;
  height: 100vh;
  overflow: hidden;
}

/* Header */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 48px;
  padding: 0 16px;
  background: #1b3a5c;
  color: #fff;
  border-bottom: 1px solid rgba(0,0,0,0.1);
}
header h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.5px;
}
.header-space { flex: 1; }
.header-user { font-size: 13px; opacity: 0.9; }

/* 3-Pane Layout */
main.three-pane {
  display: flex;
  height: calc(100vh - 48px);
  background: #fff;
}

/* Left Sidebar */
nav.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  gap: 8px;
}
.sidebar-top {
  padding-bottom: 8px;
}
.btn-compose {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  transition: background 0.15s, box-shadow 0.15s;
}
.btn-compose:hover {
  background: var(--primary-hover);
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.folder-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.folder-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 18px;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}
.folder-item:hover {
  background: #e8eaed;
}
.folder-item.on {
  background: #d3e3fd;
  color: #041e49;
  font-weight: 600;
}
.badge {
  background: var(--badge-bg);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
}
.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.btn-secondary {
  padding: 7px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-main);
}
.btn-secondary:hover { background: #eee; }

/* Middle Pane: Message List */
section.middle-pane {
  width: var(--middle-w);
  min-width: 320px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
}
.search-bar {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 6px;
  background: #fafbfc;
}
.search-input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.btn-clear {
  padding: 4px 8px;
  font-size: 12px;
  background: #eee;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.bulk-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: #f8f9fa;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-main);
}
.btn-icon:hover { background: #e8eaed; }
.btn-icon:disabled { opacity: 0.4; cursor: not-allowed; }

.message-list {
  flex: 1;
  overflow-y: auto;
}
.msg-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid #f1f3f4;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.1s;
}
.msg-row:hover { background: #f8f9fa; }
.msg-row.selected { background: #e8f0fe; }
.msg-row.active { background: #d3e3fd; }
.msg-row.unread { font-weight: 600; color: #000; }
.msg-star {
  cursor: pointer;
  color: #bbb;
  font-size: 15px;
  user-select: none;
}
.msg-star.starred { color: var(--star-color); }
.msg-summary {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.msg-from {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-subject {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.msg-date { font-size: 11px; color: var(--text-muted); }
.msg-clip { font-size: 12px; }
.empty-notice {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* Right Pane: Reader & Composer */
section.right-pane {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: #fff;
  position: relative;
}
.right-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 24px;
}

/* Reader View */
.reader-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.reader-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: #fdfdfd;
}
.reader-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid #f1f3f4;
}
.reader-header h2 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 600;
}
.reader-meta {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}
.reader-attachments {
  padding: 10px 20px;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.reader-attachments-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}
.att-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.att-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 12px;
}
.att-chip.blocked {
  border-color: var(--danger);
  color: var(--danger);
  background: #fdf2f2;
}
.att-download-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
.reader-body {
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
}
.reader-body iframe {
  width: 100%;
  min-height: 480px;
  border: none;
}
.reader-body pre.body-text {
  white-space: pre-wrap;
  word-break: break-word;
  font: 14px/1.6 system-ui, sans-serif;
  margin: 0;
}

/* Composer View */
.compose-form {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px 20px;
  gap: 10px;
}
.compose-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px;
}
.compose-field {
  position: relative;
  display: flex;
  flex-direction: column;
}
.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  max-height: 160px;
  overflow-y: auto;
  z-index: 100;
}
.autocomplete-item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
}
.autocomplete-item:hover { background: #f1f3f4; }
.compose-body {
  flex: 1;
  min-height: 240px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: 14px/1.5 system-ui, sans-serif;
  resize: none;
}
.compose-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
}
.autosave-status {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
}
.conflict-banner {
  padding: 8px 12px;
  background: #fef7e0;
  color: #b06000;
  border: 1px solid #f9ab00;
  border-radius: 4px;
  font-size: 13px;
}

/* Floating Undo Banner */
.undo-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 1000;
  animation: slideDown 0.2s ease-out;
}
.btn-undo {
  background: #fdd663;
  color: #202124;
  border: none;
  padding: 4px 10px;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
}

/* Modal Dialog */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}
.modal-box {
  background: #fff;
  width: 480px;
  max-width: 90vw;
  max-height: 85vh;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-content {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.secret-alert {
  padding: 12px;
  background: #e6f4ea;
  border: 1px solid #34a853;
  border-radius: 6px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.secret-code {
  font-family: monospace;
  font-size: 15px;
  font-weight: bold;
  background: #fff;
  padding: 6px 10px;
  border-radius: 4px;
  border: 1px solid #ceead6;
  user-select: all;
}
.apps-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.apps-table td, .apps-table th {
  padding: 8px;
  border-bottom: 1px solid #eee;
  text-align: left;
}
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

/* Login Box */
form.box {
  max-width: 360px;
  margin: 15vh auto;
  padding: 28px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
form.box h1 { margin: 0 0 8px; font-size: 20px; text-align: center; color: #1b3a5c; }
input, textarea, button, select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}
.err { color: var(--danger); font-size: 13px; }

@keyframes slideDown {
  from { opacity: 0; transform: translate(-50%, -20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
