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

:root {
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --bg-hover: #f4f4f5;
  --border: #e5e5e5;
  --border-strong: #d4d4d4;
  --text: #18181b;
  --text-muted: #71717a;
  --text-soft: #a1a1aa;
  --accent: #18181b;
  --accent-soft: #f4f4f5;
  --danger: #dc2626;
  --success: #16a34a;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-columns: 320px 380px 1fr;
  height: 100vh;
  background: var(--bg);
}

/* ===== Sidebar ===== */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-head h1 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text);
}

.count {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 24px;
  text-align: center;
}

.input-block {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.input-block label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

#accountInput {
  width: 100%;
  min-height: 90px;
  resize: vertical;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

#accountInput:focus { border-color: var(--text); }

.btn-primary {
  width: 100%;
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--text);
  color: var(--bg);
  border: 1px solid var(--text);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity 0.15s;
}

.btn-primary:hover { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-icon {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-icon:hover:not(:disabled) {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-icon:disabled { opacity: 0.4; cursor: not-allowed; }

.account-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.account-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-left: 2px solid transparent;
  cursor: pointer;
  transition: background 0.12s;
  user-select: none;
}

.account-item:hover { background: var(--bg-hover); }

.account-item.active {
  background: var(--bg);
  border-left-color: var(--text);
}

.account-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}

.account-info { min-width: 0; flex: 1; }

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

.account-status {
  font-size: 11px;
  color: var(--text-soft);
  margin-top: 1px;
}

.account-status.error { color: var(--danger); }
.account-status.success { color: var(--success); }

/* ===== Mail list ===== */
.mail-list-panel {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.panel-head h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-text {
  font-size: 11px;
  color: var(--text-muted);
}

.mail-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
}

.mail-list .empty,
.mail-body .empty {
  padding: 30px 20px;
  font-size: 13px;
  color: var(--text-soft);
  text-align: center;
}

.mail-item {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.mail-item:hover { background: var(--bg-soft); }

.mail-item.active { background: var(--bg-hover); }

.mail-item.unseen .mail-subject { font-weight: 600; }

.mail-from {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 3px;
}

.mail-from-name {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-date {
  font-size: 11px;
  color: var(--text-soft);
  flex-shrink: 0;
}

.mail-subject {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.mail-snippet {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Mail view ===== */
.mail-view {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mail-meta {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-soft);
  display: none;
}

.mail-meta.show { display: block; }

.mail-meta-row {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}

.mail-meta-label {
  color: var(--text-soft);
  min-width: 50px;
}

.mail-meta-value {
  color: var(--text);
  word-break: break-word;
}

.mail-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}

.mail-body iframe {
  width: 100%;
  border: none;
  min-height: 60vh;
}

.mail-body pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}

.attachments {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.attachments-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.attachment-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-right: 6px;
  margin-bottom: 4px;
}

/* ===== Loader ===== */
.loader {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ===== Key screen ===== */
.key-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.key-box {
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.key-box h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 6px;
}

.key-box p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.key-box input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  letter-spacing: 1px;
  text-align: center;
  outline: none;
  margin-bottom: 10px;
  background: var(--bg);
}

.key-box input:focus { border-color: var(--text); }

.key-box .btn-primary {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
}

.key-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 10px;
  min-height: 18px;
}

.key-footer {
  margin-top: 24px;
  font-size: 11px;
}

.key-footer a {
  color: var(--text-soft);
  text-decoration: none;
}

.key-footer a:hover { color: var(--text); }

/* ===== Account item: nút xoá ===== */
.account-item {
  position: relative;
}

.account-delete {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-soft);
  cursor: pointer;
  opacity: 0;
  transition: all 0.15s;
  flex-shrink: 0;
}

.account-item:hover .account-delete { opacity: 1; }

.account-delete:hover {
  background: var(--bg);
  color: var(--danger);
  border-color: var(--border);
}

/* ===== History section ===== */
.history-block {
  border-top: 1px solid var(--border);
  background: var(--bg);
  max-height: 35%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.history-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
}

.history-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  flex: 1;
}

.btn-text {
  background: transparent;
  border: none;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.15s;
}

.btn-text:hover { color: var(--danger); background: var(--bg-soft); }

.history-list {
  list-style: none;
  overflow-y: auto;
  padding: 4px 0;
  flex: 1;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  cursor: default;
  transition: background 0.12s;
}

.history-item:hover { background: var(--bg-soft); }

.history-mail {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-restore {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.history-restore:hover {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .app { grid-template-columns: 280px 320px 1fr; }
}

@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
  .sidebar, .mail-list-panel { border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar { max-height: 40vh; }
  .mail-list-panel { max-height: 35vh; }
}
