:root,
[data-theme="light"] {
  color-scheme: light;
  --ink: #152238;
  --muted: #64748b;
  --line: #dbe5ef;
  --ice: #eaf6ff;
  --panel: #ffffffd9;
  --panel-solid: #ffffff;
  --surface: #fbfdff;
  --surface-2: #f4f8fb;
  --blue: #1683d8;
  --blue2: #0b5ca8;
  --danger: #be123c;
  --shadow: 0 18px 55px #2946641c;
  --bg: radial-gradient(circle at 10% 0, #dff4ff 0, transparent 33%), linear-gradient(135deg, #f7fbff, #e8f3fa);
}

[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e8f2fb;
  --muted: #94a3b8;
  --line: #2a3a4f;
  --ice: #1e293b;
  --panel: #111827e6;
  --panel-solid: #111827;
  --surface: #0f172a;
  --surface-2: #1e293b;
  --blue: #38bdf8;
  --blue2: #0284c7;
  --danger: #fb7185;
  --shadow: 0 18px 55px #00000055;
  --bg: radial-gradient(circle at 10% 0, #1e3a5f 0, transparent 35%), linear-gradient(135deg, #0b1220, #111827);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  font: 15px/1.45 Inter, ui-sans-serif, system-ui, sans-serif;
  color: var(--ink);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; border: 0; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: min(430px, 100%);
  padding: 38px;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: 25px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 24px;
  font-weight: 750;
  letter-spacing: -0.04em;
}

.flake {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 13px;
  color: white;
  background: linear-gradient(135deg, #5dc7ff, #1665c1);
  box-shadow: 0 8px 20px #1683d866;
}

.sub { color: var(--muted); margin: 10px 0 28px; }

label {
  display: grid;
  gap: 7px;
  margin: 14px 0;
  color: color-mix(in srgb, var(--ink) 80%, var(--muted));
  font-weight: 600;
}

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel-solid);
  padding: 12px;
  color: var(--ink);
  outline: none;
}

input:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 20%, transparent);
}

.primary {
  width: 100%;
  padding: 12px 16px;
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  border-radius: 11px;
  font-weight: 700;
  margin-top: 12px;
}

.primary:disabled { opacity: 0.65; cursor: wait; }

.notice { margin-top: 16px; color: var(--danger); min-height: 22px; }

.shell {
  display: grid;
  grid-template-columns: 255px minmax(300px, 420px) 1fr;
  min-height: 100vh;
}

.side {
  position: relative;
  padding: 22px 14px 100px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(15px);
}

.side .brand { margin: 0 9px 26px; }

.compose {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--blue) 18%, var(--surface)), color-mix(in srgb, var(--blue) 10%, var(--surface-2)));
  color: var(--blue2);
  border: 1px solid color-mix(in srgb, var(--blue) 35%, var(--line));
  border-radius: 13px;
  font-weight: 750;
  margin-bottom: 17px;
}

.mailbox {
  width: 100%;
  text-align: left;
  padding: 10px 11px;
  margin: 2px 0;
  border-radius: 9px;
  background: transparent;
  color: color-mix(in srgb, var(--ink) 75%, var(--muted));
  display: flex;
  justify-content: space-between;
}

.mailbox.active,
.mailbox:hover {
  background: color-mix(in srgb, var(--blue) 14%, var(--surface-2));
  color: var(--blue2);
}

.count { font-size: 12px; color: var(--muted); }
.badge {
  background: var(--blue);
  color: white;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  text-align: center;
}

.profile {
  position: absolute;
  bottom: 18px;
  left: 18px;
  right: 18px;
  display: flex;
  gap: 9px;
  align-items: center;
  color: var(--muted);
  overflow: hidden;
  padding-bottom: 5px;
}

.quota {
  position: absolute;
  bottom: 60px;
  left: 18px;
  right: 18px;
  font-size: 12px;
  color: var(--muted);
}

.quota-bar {
  height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}

.quota-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.profile span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 32px;
  height: 32px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--blue) 18%, var(--surface-2));
  color: var(--blue2);
  font-weight: 800;
}

.profile button,
.theme-toggle {
  background: transparent;
  color: var(--muted);
}

.theme-toggle {
  position: absolute;
  top: 22px;
  right: 14px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
}

.list {
  background: var(--panel-solid);
  border-right: 1px solid var(--line);
  min-width: 0;
}

.toolbar {
  height: 72px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.search {
  flex: 1;
  background: var(--surface-2);
  border: 0;
  border-radius: 10px;
}

.rows { overflow: auto; max-height: calc(100vh - 72px); }

.row {
  width: 100%;
  padding: 15px 17px;
  text-align: left;
  background: var(--panel-solid);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  color: var(--ink);
}

.row:hover,
.row.selected { background: color-mix(in srgb, var(--blue) 10%, var(--surface)); }
.row.unread { 
  font-weight: 750; 
  background: color-mix(in srgb, var(--blue) 5%, var(--surface));
}

.from, .subject {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.from { font-size: 13px; font-weight: 600; }

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

.time {
  float: right;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.view { background: var(--surface); min-width: 0; }

.empty,
.loading {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 40px;
  color: var(--muted);
  text-align: center;
}

.empty h2 {
  margin: 16px 0 8px;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
}

.empty p {
  margin: 0;
  font-size: 14px;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid color-mix(in srgb, var(--blue) 20%, transparent);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}

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

.message { padding: 28px; max-width: 900px; margin: auto; }

.subjectline {
  font-size: 25px;
  letter-spacing: -0.035em;
  margin: 0 0 20px;
}

.msghead {
  display: flex;
  gap: 11px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 17px;
}

.actions { margin-left: auto; display: flex; gap: 7px; flex-wrap: wrap; }

.icon {
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 8px;
  color: color-mix(in srgb, var(--ink) 70%, var(--muted));
}

.body {
  padding: 24px 2px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}

.body a {
  color: var(--blue);
  text-decoration: underline;
}

.body a:hover {
  color: var(--blue2);
}

.composebox { padding: 26px; max-width: 800px; margin: auto; }
.composebox h2 { margin-top: 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.composebox textarea { min-height: 260px; resize: vertical; }

.foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.secondary {
  padding: 11px 14px;
  background: var(--surface-2);
  border-radius: 10px;
  color: color-mix(in srgb, var(--ink) 70%, var(--muted));
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #142a40;
  color: white;
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 1000;
}

.toast.error { background: #7f1d1d; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 210px minmax(280px, 1fr); }
  .view { display: none; }
  .shell.viewing { grid-template-columns: 210px 1fr; }
  .shell.viewing .list { display: none; }
  .shell.viewing .view { display: block; }
}

@media (max-width: 620px) {
  .shell, .shell.viewing { grid-template-columns: 1fr; }
  .side { display: none; }
  .list { border: 0; }
  .shell.viewing .view { display: block; }
  .grid2 { grid-template-columns: 1fr; }
  .message, .composebox { padding: 18px; }
  .toolbar { height: 64px; }
  .toast { left: 16px; right: 16px; bottom: 16px; }
  .quota { bottom: 60px; }
}
