:root {
  --bg: #f6f8fc;
  --card: #ffffff;
  --border: #e3e7ee;
  --text: #202124;
  --muted: #5f6368;
  --accent: #c5221f;
  --accent-ghost: rgba(197, 34, 31, 0.1);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body.app {
  margin: 0;
  font-family: "Roboto", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-columns: 240px 1fr 200px;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.flat-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #d93025, #f26552);
  color: var(--card);
  font-weight: 700;
}

.brand-name {
  text-transform: lowercase;
  font-size: 16px;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #eef1f7;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
}

.search input {
  border: none;
  outline: none;
  background: transparent;
  width: 100%;
  font-size: 16px;
  color: var(--text);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: flex-end;
  color: var(--muted);
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #f0d6d3;
  color: #a52714;
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: calc(100vh - 64px);
}

.nav {
  padding: 12px;
  background: var(--bg);
  border-right: 1px solid var(--border);
}

.compose-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow);
  color: var(--text);
  font-weight: 500;
}

.compose-button.active {
  background: linear-gradient(135deg, #ec4a3f, #d93025);
  color: var(--card);
}

.nav-links {
  display: grid;
  margin-top: 14px;
  gap: 4px;
}

.nav-link {
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 16px;
  color: var(--text);
}

.nav-link.active,
.nav-link:hover {
  background: var(--accent-ghost);
  color: #a92a2a;
}

.content {
  background: var(--card);
  margin: 16px;
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 96px);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-button {
  border: none;
  background: transparent;
  width: 36px;
  height: 36px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--muted);
}

.icon-button:hover {
  background: #eef1f7;
}

.inbox {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr;
  min-height: 0;
  flex: 1;
}

.list-pane {
  border-right: 1px solid var(--border);
  min-height: 0;
}

.list {
  height: 100%;
  overflow-y: auto;
}

.message-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #f0f2f6;
  cursor: pointer;
  align-items: center;
  background: var(--card);
}

.message-row:hover {
  background: #f8fafc;
}

.message-row.active {
  background: #eef1f7;
}

.icon-button.active {
  background: var(--accent-ghost);
  color: #a92a2a;
}

.message-row.unread .from,
.message-row.unread .subject {
  font-weight: 700;
}

.message-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.circle {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #d93025;
  opacity: 0;
}

.message-row.unread .circle {
  opacity: 0.8;
}

.from {
  width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subject {
  color: var(--text);
}

.snippet {
  color: var(--muted);
  margin-left: 6px;
}

.subject-line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.timestamp {
  color: var(--muted);
  font-size: 13px;
}

.reader {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.reader-content {
  padding: 16px 20px;
  overflow-y: auto;
  height: 100%;
}

.reader-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.reader-subject {
  font-size: 20px;
  font-weight: 600;
}

.reader-meta {
  color: var(--muted);
  margin-top: 6px;
  font-size: 14px;
}

.reader-body {
  margin-top: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.reader-actions {
  display: flex;
  gap: 6px;
}

.empty {
  display: grid;
  place-items: center;
  gap: 8px;
  height: 100%;
  color: var(--muted);
}

.empty-label {
  font-weight: 500;
}

.small-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--accent-ghost);
  color: #a92a2a;
  font-weight: 500;
}

.pill-link {
  padding: 6px 12px;
  border-radius: 10px;
  background: #eef1f7;
  color: var(--muted);
}

.compose-pane {
  display: flex;
  align-items: center;
  justify-content: center;
}

.compose-card {
  width: min(720px, 92vw);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin: 24px 0;
}

.compose-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  margin-bottom: 12px;
}

.compose-form {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field.inline {
  align-items: center;
}

.field label {
  font-size: 14px;
  color: var(--muted);
}

.inline-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
}

.compose-form input,
.compose-form textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  background: #f8fafc;
}

.compose-form textarea {
  resize: vertical;
}

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

.primary,
.secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.primary {
  background: linear-gradient(135deg, #ec4a3f, #d93025);
  color: var(--card);
}

.secondary {
  background: #eef1f7;
  color: var(--muted);
}

.fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 32px;
  background: linear-gradient(135deg, #ec4a3f, #d93025);
  color: var(--card);
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 40;
}

.fab .material-symbols-rounded {
  font-size: 22px;
}

.fab.secondary {
  background: var(--card);
  color: var(--accent);
  border: 1px solid var(--border);
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #202124;
  color: var(--card);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 20;
}

.toast.warning {
  background: #a52714;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.muted {
  color: var(--muted);
}

.material-symbols-rounded {
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
}

@media (max-width: 1024px) {
  .topbar {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(3, auto);
  }

  .layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .nav {
    display: none;
  }

  .content {
    margin: 12px;
    min-height: auto;
  }

  .inbox {
    grid-template-columns: 1fr;
  }

  .reader {
    border-top: 1px solid var(--border);
  }

  .fab {
    display: inline-flex;
  }
}

@media (max-width: 900px) {
  .toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .toolbar-right {
    margin-left: auto;
  }

  .reader-header {
    flex-direction: column;
    gap: 8px;
  }
}

@media (max-width: 768px) {
  .content {
    margin: 10px;
    border-radius: 14px;
  }

  .message-row {
    grid-template-columns: 1fr;
    row-gap: 4px;
  }

  .message-left {
    justify-content: space-between;
  }

  .from {
    width: auto;
    font-size: 15px;
  }

  .subject-line {
    flex-direction: column;
    align-items: flex-start;
  }

  .snippet {
    margin-left: 0;
    font-size: 13px;
  }

  .timestamp {
    font-size: 12px;
    color: var(--muted);
  }

  .reader-content {
    padding: 14px;
  }

  .compose-card {
    padding: 16px;
    margin: 18px 0;
  }
}

@media (max-width: 600px) {
  .topbar {
    padding: 8px 12px;
  }

  .topbar-left {
    justify-content: space-between;
  }

  .topbar-right {
    gap: 8px;
  }

  .topbar-right .material-symbols-rounded {
    display: none;
  }

  .search {
    padding: 8px 10px;
  }

  .content {
    margin: 8px;
    border-radius: 12px;
  }

  .toolbar {
    padding: 6px 8px;
  }

  .reader-subject {
    font-size: 18px;
  }

  .compose-card {
    border: none;
    box-shadow: none;
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .primary,
  .secondary {
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .layout {
    min-height: auto;
  }

  .message-row {
    padding: 12px;
  }

  .reader-body {
    font-size: 15px;
  }

  .toolbar-left,
  .toolbar-right {
    width: 100%;
    justify-content: space-between;
  }

  .toolbar-right {
    justify-content: flex-end;
  }

  .compose-card {
    margin: 0;
    border-radius: 10px;
  }

  .fab {
    right: 14px;
    bottom: 14px;
  }
}
