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

body {
  background: #fff;
  color: #111;
  font-family: 'IBM Plex Mono', monospace;
  height: 100vh;
  overflow: hidden;
  display: flex;
}

/* ── Inputs ───────────────────────────────────────────────────────────────── */
input[type="text"],
input[type="password"],
input[type="email"],
textarea, select {
  width: 100%;
  background: #fff;
  border: 1px solid #ccc;
  color: #111;
  padding: 8px 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  margin-bottom: 10px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus { border-color: #111; }
textarea { resize: vertical; min-height: 120px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
button {
  background: #111;
  border: none;
  color: #fff;
  padding: 9px 18px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}
button:hover { background: #333; }
button.outline { background: #fff; border: 1px solid #ccc; color: #333; }
button.outline:hover { background: #f5f5f5; border-color: #999; }
button.small { padding: 5px 12px; font-size: 0.72rem; }
button.err-btn { border-color: #c00; color: #c00; background: #fff; }
button.err-btn:hover { background: #fff5f5; }

label {
  font-size: 0.72rem;
  color: #666;
  display: block;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-wrap { width: 100%; display: flex; align-items: center; justify-content: center; }
.login-box { width: 360px; padding: 48px 0; }
.login-box h1 { font-family: 'Syne', sans-serif; font-size: 2rem; font-weight: 800; margin-bottom: 4px; }
.login-box p { color: #888; font-size: 0.78rem; margin-bottom: 32px; }
.err { font-size: 0.78rem; color: #c00; border: 1px solid #c00; padding: 8px 12px; margin-bottom: 16px; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  padding: 28px 0;
  flex-shrink: 0;
}
.sidebar-logo {
  font-family: 'Syne', sans-serif;
  font-size: 1.3rem;
  font-weight: 800;
  padding: 0 24px 20px;
  border-bottom: 1px solid #e0e0e0;
  margin-bottom: 8px;
}
.sidebar-logo span {
  display: block;
  font-size: 0.62rem;
  color: #999;
  font-family: 'IBM Plex Mono';
  font-weight: 300;
  margin-top: 2px;
}
.nav-group { margin-bottom: 4px; }
.nav-divider { border-top: 1px solid #e0e0e0; margin: 8px 0; }
.nav-item {
  padding: 9px 24px;
  cursor: pointer;
  color: #888;
  font-size: 0.78rem;
  border-left: 2px solid transparent;
  transition: color 0.15s;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.nav-item:hover { color: #111; }
.nav-item.active { color: #111; border-left-color: #111; font-weight: 500; }
.nav-item.compose-btn { color: #111; font-weight: 500; }
.nav-action {
  background: none;
  border: none;
  color: #bbb;
  font-size: 0.7rem;
  padding: 0 4px;
  cursor: pointer;
  line-height: 1;
}
.nav-action:hover { color: #c00; background: none; }
.badge {
  background: #111;
  color: #fff;
  font-size: 0.6rem;
  padding: 1px 5px;
  border-radius: 8px;
  min-width: 18px;
  text-align: center;
}
.sidebar-bottom { margin-top: auto; padding: 16px 24px; border-top: 1px solid #e0e0e0; }
.current-user { font-size: 0.72rem; color: #888; margin-bottom: 8px; }
.current-user strong { color: #111; display: block; }

/* ── Main area ────────────────────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.topbar {
  border-bottom: 1px solid #e0e0e0;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}
.topbar h2 { font-family: 'Syne', sans-serif; font-size: 1.1rem; font-weight: 700; white-space: nowrap; }
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.search-wrap { display: flex; gap: 6px; align-items: center; }
.search-wrap input { width: 200px; margin: 0; }
.admin-user-wrap select { margin: 0; }
.refresh-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: #888;
  cursor: pointer;
  white-space: nowrap;
}
.refresh-toggle input { width: auto; margin: 0; }
.content { flex: 1; padding: 0; overflow: hidden; display: flex; flex-direction: column; }

/* ── Inbox page ───────────────────────────────────────────────────────────── */
#page-inbox {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Mail list view ───────────────────────────────────────────────────────── */
#mail-list-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mail-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid #e8e8e8;
  flex-shrink: 0;
  background: #fafafa;
  min-height: 42px;
}
.toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.select-all-wrap {
  display: flex;
  align-items: center;
  cursor: pointer;
  margin: 0;
}
.select-all-wrap input { width: auto; margin: 0; cursor: pointer; }
.icon-btn {
  background: none;
  border: none;
  color: #666;
  font-size: 1rem;
  padding: 4px 6px;
  cursor: pointer;
  line-height: 1;
  transition: color 0.15s;
}
.icon-btn:hover { color: #111; background: none; }
.mail-count-lbl { font-size: 0.68rem; color: #aaa; }
.bulk-bar { display: flex; align-items: center; gap: 6px; }
.bulk-count-lbl { font-size: 0.68rem; color: #888; }

/* ── Mail list column headers ─────────────────────────────────────────────── */
.mail-list-cols {
  display: grid;
  grid-template-columns: 40px 36px 200px 1fr 80px 28px;
  padding: 4px 8px;
  border-bottom: 1px solid #e8e8e8;
  font-size: 0.62rem;
  color: #bbb;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

/* ── Mail list ────────────────────────────────────────────────────────────── */
#mail-list {
  flex: 1;
  overflow-y: auto;
}

.mail-item {
  display: grid;
  grid-template-columns: 40px 36px 200px 1fr 80px 28px;
  align-items: center;
  min-height: 46px;
  padding: 0 8px;
  border-bottom: 1px solid #f2f2f2;
  cursor: pointer;
  transition: background 0.08s;
}
.mail-item:hover { background: #f8f8f8; }
.mail-item.selected { background: #eef4ff; }
.mail-item.unread .mi-from { font-weight: 600; color: #111; }
.mail-item.unread .mi-subj { font-weight: 600; color: #111; }

.mi-check {
  display: flex;
  align-items: center;
  justify-content: center;
}
.mi-check input[type="checkbox"] {
  width: auto;
  margin: 0;
  cursor: pointer;
}
.mi-star {
  display: flex;
  align-items: center;
  justify-content: center;
}
.star-btn {
  background: none;
  border: none;
  color: #ccc;
  font-size: 1rem;
  padding: 0;
  cursor: pointer;
  line-height: 1;
  transition: color 0.1s;
}
.star-btn:hover { color: #f90; background: none; }
.star-btn.starred { color: #f90; }

.mi-from {
  font-size: 0.78rem;
  color: #555;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 8px;
}
.mi-subj-wrap {
  display: flex;
  align-items: baseline;
  min-width: 0;
  overflow: hidden;
}
.mi-subj {
  font-size: 0.8rem;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
  max-width: 60%;
}
.mi-snippet {
  font-size: 0.75rem;
  color: #aaa;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.mi-date {
  font-size: 0.67rem;
  color: #aaa;
  white-space: nowrap;
  text-align: right;
  padding-right: 4px;
}
.mi-att {
  font-size: 0.78rem;
  text-align: center;
  color: #999;
}

.mail-empty { padding: 40px; text-align: center; color: #ccc; font-size: 0.8rem; }

/* ── Mail view (full screen) ──────────────────────────────────────────────── */
#mail-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mail-view-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
  background: #fafafa;
  flex-wrap: wrap;
}
.back-btn {
  background: #fff;
  border: 1px solid #ccc;
  color: #333;
  padding: 6px 14px;
  font-size: 0.78rem;
  white-space: nowrap;
}
.back-btn:hover { background: #f0f0f0; }
.mail-view-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.starred-btn { color: #f90 !important; border-color: #f90 !important; }

.mail-view-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.mail-view-header {
  padding: 24px 32px 16px;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
}
.mail-view-subject {
  font-family: 'Syne', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 14px;
  word-break: break-word;
  line-height: 1.3;
}
.mail-view-meta { display: flex; flex-direction: column; gap: 4px; }
.meta-row {
  display: flex;
  gap: 8px;
  font-size: 0.78rem;
  color: #555;
  align-items: baseline;
}
.meta-label {
  color: #bbb;
  text-transform: uppercase;
  font-size: 0.62rem;
  letter-spacing: 0.05em;
  flex-shrink: 0;
  min-width: 36px;
}
.meta-val { word-break: break-all; }

/* ── Attachments in view ──────────────────────────────────────────────────── */
.view-attachments {
  padding: 12px 32px;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
}
.att-section-label { font-size: 0.72rem; color: #888; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.04em; }
.view-att-list { display: flex; flex-wrap: wrap; gap: 8px; }
.att-item {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #e0e0e0;
  padding: 8px 12px;
  font-size: 0.75rem;
  background: #fafafa;
}
.att-item-name { color: #333; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-item-size { color: #bbb; font-size: 0.68rem; }
.att-item a { color: #111; text-decoration: none; font-size: 0.72rem; border: 1px solid #ccc; padding: 3px 8px; }
.att-item a:hover { background: #f0f0f0; }

/* ── Mail body ────────────────────────────────────────────────────────────── */
.mail-body-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0;
}
.mail-body-switch {
  padding: 8px 32px;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.active-view-btn { border-color: #111 !important; color: #111 !important; }
.mail-view-body {
  flex: 1;
  padding: 24px 32px;
  font-size: 0.85rem;
  white-space: pre-wrap;
  line-height: 1.8;
  word-break: break-word;
  overflow-y: auto;
}
.mail-view-iframe {
  flex: 1;
  border: none;
  width: 100%;
  min-height: 500px;
}

/* ── Compose ──────────────────────────────────────────────────────────────── */
#page-compose {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.compose-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-width: 900px;
  width: 100%;
}
.compose-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}
.compose-title {
  font-family: 'Syne', sans-serif;
  font-size: 1rem;
  font-weight: 700;
}
.compose-fields {
  flex-shrink: 0;
  border-bottom: 1px solid #e0e0e0;
}
.compose-field-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #f0f0f0;
  padding: 0 24px;
}
.compose-field-row:last-child { border-bottom: none; }
.field-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #bbb;
  width: 56px;
  flex-shrink: 0;
  margin: 0;
}
.compose-field-row input,
.compose-field-row select {
  flex: 1;
  border: none;
  outline: none;
  padding: 10px 0;
  margin: 0;
  font-size: 0.85rem;
  font-family: 'IBM Plex Mono', monospace;
}
.compose-field-row input:focus,
.compose-field-row select:focus { border: none; }

/* ── Rich text editor toolbar ─────────────────────────────────────────────── */
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 20px;
  border-bottom: 1px solid #e8e8e8;
  flex-shrink: 0;
  flex-wrap: wrap;
  background: #fafafa;
}
.fmt-btn {
  background: none;
  border: 1px solid transparent;
  color: #555;
  padding: 4px 8px;
  font-size: 0.8rem;
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  line-height: 1.2;
  border-radius: 2px;
  min-width: 26px;
}
.fmt-btn:hover { background: #ececec; border-color: #ccc; color: #111; }
.fmt-btn.active { background: #e0e8ff; border-color: #aac; }
.fmt-sep {
  display: inline-block;
  width: 1px;
  height: 18px;
  background: #ddd;
  margin: 0 4px;
}
.fmt-select {
  font-size: 0.72rem;
  padding: 3px 6px;
  border: 1px solid #ccc;
  background: #fff;
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  color: #555;
  width: auto;
  margin: 0;
}
.fmt-select:focus { border-color: #999; }
.color-picker {
  width: 26px;
  height: 26px;
  padding: 2px;
  border: 1px solid #ccc;
  cursor: pointer;
  margin: 0;
}

/* ── Compose editor ───────────────────────────────────────────────────────── */
.compose-editor {
  flex: 1;
  padding: 16px 24px;
  font-size: 0.88rem;
  line-height: 1.7;
  outline: none;
  overflow-y: auto;
  min-height: 200px;
  font-family: inherit;
}
.compose-editor:focus { outline: none; }
.compose-editor blockquote {
  border-left: 3px solid #ccc;
  padding-left: 12px;
  margin: 8px 0;
  color: #777;
}

/* ── Compose footer ───────────────────────────────────────────────────────── */
.compose-footer-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  border-top: 1px solid #e8e8e8;
  flex-shrink: 0;
  flex-wrap: wrap;
  background: #fafafa;
}
.attach-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: #666;
  cursor: pointer;
  padding: 5px 12px;
  border: 1px solid #ccc;
  transition: background 0.1s;
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
}
.attach-label:hover { background: #f5f5f5; }
.attach-list { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.attach-item {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #ddd;
  padding: 4px 8px;
  font-size: 0.72rem;
  color: #555;
  background: #f9f9f9;
}
.attach-item button {
  background: none;
  border: none;
  color: #aaa;
  padding: 0 2px;
  font-size: 0.7rem;
  cursor: pointer;
  line-height: 1;
}
.attach-item button:hover { color: #c00; background: none; }
.compose-send-bar {
  padding: 12px 24px;
  border-top: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.send-status { font-size: 0.75rem; color: #888; }

/* ── Cards / Settings / Users ────────────────────────────────────────────── */
.card { border: 1px solid #e0e0e0; padding: 24px; margin-bottom: 16px; }
.card h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #888;
  margin-bottom: 16px;
  font-weight: 500;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
#page-settings, #page-users { padding: 28px 32px; overflow-y: auto; }

/* ── Table ────────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
th {
  text-align: left;
  padding: 8px 12px;
  color: #888;
  border-bottom: 1px solid #e0e0e0;
  font-weight: 400;
  font-size: 0.72rem;
  text-transform: uppercase;
}
td { padding: 9px 12px; border-bottom: 1px solid #f0f0f0; }
tr:hover td { background: #fafafa; }

/* ── Keyboard shortcut key ────────────────────────────────────────────────── */
.kbd {
  display: inline-block;
  border: 1px solid #ccc;
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.72rem;
  background: #f5f5f5;
  min-width: 20px;
  text-align: center;
}
td:first-child { width: 140px; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #111;
  color: #fff;
  padding: 10px 18px;
  font-size: 0.78rem;
  display: none;
  max-width: 320px;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.toast.show { display: block; }
.toast.err { background: #c00; }

/* ── Confirm dialog ───────────────────────────────────────────────────────── */
.confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.confirm-box {
  background: #fff;
  border: 1px solid #ccc;
  padding: 28px 32px;
  min-width: 300px;
  max-width: 420px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
#confirm-msg { font-size: 0.85rem; margin-bottom: 20px; }
.confirm-actions { display: flex; gap: 10px; }

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.tag { display: inline-block; border: 1px solid #ccc; padding: 1px 6px; font-size: 0.68rem; color: #666; }

/* ── Mobile hamburger (hidden on desktop) ─────────────────────────────────── */
.hamburger {
  display: none;
  background: none;
  border: none;
  color: #333;
  font-size: 1.3rem;
  padding: 4px 8px;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
}
.hamburger:hover { background: #f0f0f0; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 499;
}
.sidebar-overlay.open { display: block; }

/* ── Mobile responsive ────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Hamburger visible */
  .hamburger { display: flex; align-items: center; }

  /* Sidebar becomes a sliding drawer */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 500;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 3px 0 16px rgba(0,0,0,0.15);
  }
  .sidebar.open { transform: translateX(0); }

  /* Main takes full width */
  .main { width: 100%; }

  /* Topbar compact */
  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar h2 { font-size: 0.9rem; }
  .topbar-right { gap: 6px; }
  .search-wrap input { width: 110px; }
  .refresh-toggle span { display: none; }

  /* Hide column header row */
  .mail-list-cols { display: none; }

  /* Mail list — 2-row grid per item */
  .mail-item {
    grid-template-columns: 36px 34px 1fr 64px;
    grid-template-rows: auto auto;
    min-height: 54px;
    padding: 6px 8px;
    gap: 0 4px;
  }
  .mi-check { grid-column: 1; grid-row: 1 / 3; align-self: center; }
  .mi-star  { grid-column: 2; grid-row: 1 / 3; align-self: center; }
  .mi-from  { grid-column: 3; grid-row: 1; font-size: 0.78rem; padding-right: 4px; }
  .mi-subj-wrap { grid-column: 3; grid-row: 2; }
  .mi-date  { grid-column: 4; grid-row: 1; font-size: 0.64rem; }
  .mi-att   { grid-column: 4; grid-row: 2; text-align: right; }
  .mi-snippet { display: none; }
  .mi-subj  { max-width: 100%; font-size: 0.75rem; }

  /* Bulk bar wraps */
  .bulk-bar { flex-wrap: wrap; gap: 4px; }

  /* Mail view toolbar */
  .mail-view-toolbar { padding: 8px 12px; gap: 6px; }
  .mail-view-actions button { padding: 5px 10px; font-size: 0.72rem; }

  /* Mail view header */
  .mail-view-header { padding: 16px; }
  .mail-view-subject { font-size: 1rem; }
  .meta-row { font-size: 0.74rem; }

  /* Attachments */
  .view-attachments { padding: 10px 16px; }
  .att-item { flex-wrap: wrap; }

  /* Body */
  .mail-body-switch { padding: 6px 16px; }
  .mail-view-body { padding: 14px 16px; font-size: 0.82rem; }

  /* Compose */
  .compose-container { max-width: 100%; }
  .compose-header { padding: 10px 14px; }
  .compose-field-row { padding: 0 12px; }
  .compose-field-row input { font-size: 0.8rem; }
  .editor-toolbar { padding: 4px 8px; gap: 1px; }
  .fmt-btn { padding: 4px 6px; font-size: 0.75rem; min-width: 24px; }
  .compose-editor { padding: 12px 14px; font-size: 0.85rem; }
  .compose-footer-bar { padding: 8px 14px; }
  .compose-send-bar { padding: 10px 14px; }

  /* Settings / Users */
  .grid2 { grid-template-columns: 1fr; gap: 12px; }
  #page-settings, #page-users { padding: 16px; }

  /* Login */
  .login-box { width: 100%; padding: 40px 24px; }

  /* Confirm dialog */
  .confirm-box { min-width: 280px; padding: 20px 20px; margin: 0 16px; }

  /* Toast */
  .toast { right: 12px; bottom: 16px; left: 12px; max-width: none; }
}
