/* The frame: rail, top bar, panes and how the three collapse into two and
   then one as the window narrows. */

#root.app {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  height: 100dvh;
  background: var(--bg);
}

/* ---------- rail ---------- */

.rail {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--rail);
  border-right: 1px solid var(--line);
  padding: 0 8px calc(8px + var(--safe-b));
}

.rail-top {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h); padding: 0 6px; flex: none;
}
.rail-brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.rail-brand img { width: 26px; height: 26px; border-radius: 7px; }
.rail-brand b { font-size: 15px; font-weight: 700; letter-spacing: -.015em; }
.rail-brand b span { color: var(--accent); }
.rail-close { display: none; margin-left: auto; }

.compose-btn {
  display: flex; align-items: center; gap: 10px;
  height: 44px; margin: 4px 6px 14px; padding: 0 18px;
  border-radius: var(--r-pill);
  background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: 14px;
  box-shadow: var(--shadow-1);
  transition: background .12s ease, box-shadow .12s ease, transform .06s ease;
}
.compose-btn:hover { background: var(--accent-2); box-shadow: var(--shadow-2); }
.compose-btn:active { transform: translateY(1px); }
.compose-btn svg { width: 18px; height: 18px; }

.rail-scroll { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: 8px; }

.folder {
  display: flex; align-items: center; gap: 12px;
  height: 34px; padding: 0 12px; margin-bottom: 1px;
  border-radius: var(--r-pill);
  color: var(--text-2); font-size: 14px;
  transition: background .1s ease, color .1s ease;
}
.folder:hover { background: var(--hover); color: var(--text); }
.folder svg { width: 18px; height: 18px; opacity: .9; }
.folder-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-count { font-size: 12px; font-weight: 700; color: var(--text-3); font-variant-numeric: tabular-nums; }
.folder.is-active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.folder.is-active svg { color: var(--accent); opacity: 1; }
.folder.is-active .folder-count { color: var(--accent); }
.folder.is-drop { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }
.folder.has-unread .folder-name { font-weight: 700; color: var(--text); }

.rail-section { margin-top: 14px; }
.rail-section-head {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 12px; color: var(--text-4);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
}
.rail-section-head span { flex: 1; }
.rail-section-head .icon-btn { width: 24px; height: 24px; }
.rail-section-head .icon-btn svg { width: 14px; height: 14px; }

.label-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.folder .label-menu { opacity: 0; width: 22px; height: 22px; }
.folder:hover .label-menu, .folder .label-menu:focus-visible { opacity: 1; }
.folder .label-menu svg { width: 14px; height: 14px; }

.rail-foot { flex: none; padding-top: 8px; border-top: 1px solid var(--line); }
.rail-quota { padding: 8px 12px 4px; font-size: 11px; color: var(--text-4); }
.rail-quota .bar { height: 4px; border-radius: 2px; background: var(--line); margin-bottom: 5px; overflow: hidden; }
.rail-quota .bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

/* ---------- main column ---------- */

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

.topbar {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h); flex: none;
  padding: 0 12px 0 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.menu-btn { display: none; }

.search {
  position: relative; flex: 1; max-width: 720px;
}
.search-box {
  display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 10px 0 12px;
  background: var(--surface); border: 1px solid transparent;
  border-radius: var(--r-pill);
  transition: background .12s ease, border-color .12s ease, border-radius .12s ease;
}
.search.is-open .search-box { border-radius: var(--r) var(--r) 0 0; border-color: var(--line); background: var(--card); }
.search-box:focus-within { border-color: var(--accent); }
.search-box svg { width: 17px; height: 17px; color: var(--text-3); }
.search-box input {
  flex: 1; min-width: 0; height: 100%; border: 0; background: none; outline: none;
  font-size: 14px; color: var(--text);
}
.search-box input::placeholder { color: var(--text-4); }

.search-panel {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 60;
  background: var(--card); border: 1px solid var(--line); border-top: 0;
  border-radius: 0 0 var(--r) var(--r); box-shadow: var(--shadow-2);
  padding: 8px; max-height: 62vh; overflow: auto;
}
.search-op {
  display: flex; align-items: baseline; gap: 10px; width: 100%;
  padding: 7px 10px; border-radius: var(--r-sm); text-align: left; font-size: 13px;
}
.search-op:hover, .search-op.is-cursor { background: var(--hover); }
.search-op code { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.search-op span { color: var(--text-3); font-size: 12px; }

.topbar-right { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.account-btn { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; }
.account-btn:hover { box-shadow: 0 0 0 2px var(--hover); }

.account-card { padding: 12px 12px 8px; display: flex; gap: 11px; align-items: center; }
.account-card .who { min-width: 0; }
.account-card .who b { display: block; font-size: 14px; }
.account-card .who span { display: block; font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; }

/* ---------- panes ---------- */

.panes {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(360px, 460px) 1fr;
}
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.pane-list { background: var(--pane); border-right: 1px solid var(--line); }
.pane-thread { background: var(--surface); }

/* Settings is a page, not a conversation: it takes the whole area rather
   than sitting next to an empty list. */
body.settings-view .panes { grid-template-columns: 1fr; }
body.settings-view .pane-list { display: none; }
body.settings-view .pane-thread { display: flex; }

.bottombar { display: none; }

/* ---------- responsive ---------- */

/* Tablet: the reading pane takes the whole width when a thread is open. */
@media (max-width: 1099px) {
  .panes { grid-template-columns: 1fr; }
  .pane-thread { display: none; }
  body.has-thread .pane-list { display: none; }
  body.has-thread .pane-thread { display: flex; }
  .pane-list { border-right: 0; }
}

@media (max-width: 899px) {
  :root { --rail-w: 0px; }
  #root.app { grid-template-columns: 1fr; }
  .rail {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 110;
    width: 280px; padding-top: var(--safe-t);
    transform: translateX(-102%);
    transition: transform .18s ease;
    box-shadow: var(--shadow-3);
  }
  body.rail-open .rail { transform: none; }
  body.rail-open::after {
    content: ''; position: fixed; inset: 0; z-index: 105; background: rgba(0, 0, 0, .5);
  }
  .rail-close { display: inline-flex; }
  .menu-btn { display: inline-flex; }
}

/* Phone: one pane, a bottom bar, and a compose that fills the screen. */
@media (max-width: 719px) {
  .topbar { padding: 0 8px; gap: 6px; }
  .search-box { height: 38px; }
  .panes { padding-bottom: calc(56px + var(--safe-b)); }
  .bottombar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
    display: flex; align-items: stretch;
    height: calc(56px + var(--safe-b)); padding-bottom: var(--safe-b);
    background: var(--rail); border-top: 1px solid var(--line);
  }
  .bottombar a, .bottombar button {
    flex: 1; display: grid; place-items: center; gap: 3px;
    color: var(--text-3); font-size: 10px; font-weight: 600;
  }
  .bottombar svg { width: 20px; height: 20px; }
  .bottombar .is-active { color: var(--accent); }
  .bottombar .bb-compose {
    color: var(--accent-ink);
  }
  .bottombar .bb-compose i {
    display: grid; place-items: center; width: 44px; height: 32px;
    border-radius: var(--r-pill); background: var(--accent);
  }
  body.has-thread .bottombar { display: none; }
  body.has-thread .panes { padding-bottom: 0; }
}

@media (min-width: 1500px) {
  .panes { grid-template-columns: minmax(400px, 520px) 1fr; }
}
