:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #0f172a;
  --accent-2: #0ea5e9;
  --hover: #f1f5f9;
  --selected: #e0f2fe;
  --danger: #dc2626;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
.hidden { display: none !important; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }

.btn {
  border: 1px solid var(--border); background: var(--panel); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #1e293b; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { padding: 6px 9px; }
.btn.danger:hover { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--accent-2); cursor: pointer; padding: 0; text-decoration: underline; }
.spacer { flex: 1; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card {
  background: var(--panel); padding: 32px; border-radius: 16px; width: min(360px, 100%);
  display: flex; flex-direction: column; gap: 12px; text-align: center;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .08);
}
.login-card h1 { margin: 4px 0 0; font-size: 1.4rem; }
.login-card p { margin: 0; color: var(--muted); }
.login-card img { margin: 0 auto; }
.login-card input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.login-card .btn { padding: 10px; }

/* Layout */
.app { display: grid; grid-template-columns: 240px minmax(320px, 420px) 1fr; height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 14px 10px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; padding: 0 6px 14px; }
.compose-btn { margin: 0 4px 14px; padding: 10px; }
.nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; cursor: pointer;
  border: 0; background: none; text-align: left; width: 100%; font-size: .92rem;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--selected); font-weight: 600; }
.nav-item .count { margin-left: auto; font-size: .78rem; background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; }
.nav-item .count:empty { display: none; }
.nav-item.sub { padding-left: 28px; font-size: .88rem; }
.nav-section { margin-top: 14px; padding: 4px 10px; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.nav-section .caret { margin-left: auto; transition: transform .15s; }
.nav-section.collapsed .caret { transform: rotate(-90deg); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.logout { margin-top: 10px; color: var(--muted); }

.list-pane { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; background: var(--panel); }
.list-header { display: flex; align-items: center; gap: 8px; padding: 12px 14px 6px; }
.list-header h2 { font-size: 1.05rem; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-row { display: flex; gap: 8px; padding: 6px 14px 10px; border-bottom: 1px solid var(--border); align-items: center; }
.search-row input[type=search] { flex: 1; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; min-width: 0; }
.chip { font-size: .82rem; color: var(--muted); display: flex; gap: 4px; align-items: center; white-space: nowrap; cursor: pointer; }
.list-errors { font-size: .82rem; color: var(--danger); }
.list-errors div { padding: 6px 14px; background: #fef2f2; border-bottom: 1px solid #fee2e2; }
.message-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.msg {
  display: grid; grid-template-columns: 4px 1fr auto; gap: 0 10px; padding: 10px 14px 10px 0;
  border-bottom: 1px solid var(--border); cursor: pointer; position: relative;
}
.msg:hover { background: var(--hover); }
.msg.selected { background: var(--selected); }
.msg .bar { grid-row: 1 / 3; border-radius: 0 3px 3px 0; }
.msg .from { font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .date { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.msg .subject { grid-column: 2 / 4; font-size: .86rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.unread .from, .msg.unread .subject { font-weight: 650; color: var(--text); }
.msg.unread::after { content: ""; position: absolute; right: 8px; bottom: 12px; width: 8px; height: 8px; background: var(--accent-2); border-radius: 50%; }
.msg .icons { font-size: .75rem; margin-left: 4px; }
.list-empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.more { margin: 8px; }

.read-pane { display: flex; flex-direction: column; min-width: 0; background: var(--panel); }
.read-empty { margin: auto; color: var(--muted); }
.reader { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.reader-toolbar { display: flex; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; align-items: center; }
.r-subject { font-size: 1.3rem; margin: 16px 20px 8px; word-break: break-word; }
.r-meta { display: flex; gap: 12px; padding: 0 20px 12px; align-items: flex-start; border-bottom: 1px solid var(--border); }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex: none; }
.r-meta-text { flex: 1; min-width: 0; }
.r-from { font-weight: 600; word-break: break-word; }
.r-from small { font-weight: 400; color: var(--muted); }
.r-to { font-size: .85rem; color: var(--muted); word-break: break-word; }
.r-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: .82rem; color: var(--muted); }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 10px; color: #fff; }
.r-images { font-size: .85rem; background: #fffbeb; padding: 8px 20px; border-bottom: 1px solid #fde68a; }
.r-attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px; }
.r-attachments:not(:empty) { padding: 10px 20px; border-bottom: 1px solid var(--border); }
.att { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; font-size: .84rem; text-decoration: none; color: var(--text); }
.att:hover { background: var(--hover); }
.att small { color: var(--muted); }
.r-body { flex: 1; border: 0; width: 100%; min-height: 300px; background: #fff; }

/* Composer */
.composer { border: 0; border-radius: 14px; padding: 0; width: min(720px, 96vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.composer::backdrop { background: rgba(15, 23, 42, .35); }
.composer form { display: flex; flex-direction: column; }
.composer header { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.composer header h3 { margin: 0; flex: 1; font-size: 1rem; }
.composer label:not(.btn) { display: flex; align-items: center; gap: 10px; padding: 6px 16px; border-bottom: 1px solid var(--border); font-size: .85rem; color: var(--muted); }
.composer label input, .composer label select { flex: 1; border: 0; padding: 6px 0; outline: none; background: transparent; color: var(--text); font-size: .95rem; }
.cc-toggle { position: relative; }
.cc-toggle .link { position: absolute; right: 16px; top: -30px; font-size: .82rem; }
.composer textarea { border: 0; padding: 14px 16px; resize: vertical; outline: none; min-height: 260px; font-size: .95rem; line-height: 1.5; }
.composer footer { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.file-list, .c-fwd { font-size: .8rem; color: var(--muted); }
.c-fwd:not(:empty) { padding: 6px 16px; }
.c-status { font-size: .85rem; color: var(--muted); }
.attach { cursor: pointer; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--accent); color: #fff; padding: 10px 18px; border-radius: 10px; transition: .2s; pointer-events: none; z-index: 10;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

.only-mobile { display: none; }

@media (max-width: 1100px) {
  .app { grid-template-columns: 200px minmax(280px, 360px) 1fr; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-block; }
  .sidebar { position: fixed; inset: 0 30% 0 0; z-index: 5; box-shadow: 0 0 40px rgba(0,0,0,.2); transform: translateX(-105%); transition: transform .2s; }
  .app.menu-open .sidebar { transform: none; }
  .read-pane { display: none; }
  .app.reading .list-pane { display: none; }
  .app.reading .read-pane { display: flex; height: 100vh; }
}

/* Ajustes de altura: cada panel ocupa la ventana y desplaza su propio contenido */
.app > * { height: 100vh; min-height: 0; }
.read-pane { overflow: hidden; }
.reader { overflow-y: auto; }
.r-body { min-height: 60vh; }
.r-meta { flex-wrap: wrap; }
.r-meta-text { min-width: 180px; }
@media (max-width: 1100px) { .r-side { flex-direction: row; width: 100%; justify-content: space-between; } }
