/*
 * PDTHUB Mail.
 *
 * Three columns on a desktop, stacking down to one on a phone. Light, because
 * mail arrives written for a white background and a dark shell around a white
 * message body looks like a mistake rather than a theme.
 */

:root {
  --bg:        #f4f6f8;
  --panel:     #ffffff;
  --panel-2:   #f8fafb;
  --line:      #e3e7ec;
  --text:      #1b1f27;
  --muted:     #6b7280;
  --accent:    #2f7fd4;
  --accent-2:  #1f6ab8;
  --danger:    #c0392b;
  --ok:        #1f8a4c;
  --unread:    #eef5fd;
}

* { box-sizing: border-box; }

/*
 * THE hidden ATTRIBUTE MUST WIN.
 *
 * Browsers implement it as `[hidden] { display: none }` in their own default
 * stylesheet, which any class of ours with a `display` outranks. `.empty` sets
 * `display: grid`, so "Izaberite poruku" stayed on screen after being hidden -
 * filling the reader and pushing the message that had just loaded below it.
 *
 * Nothing looks wrong in the markup, the element genuinely has hidden set, and
 * the message genuinely arrived. One rule removes the whole class of problem.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

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

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.err  { color: var(--danger); margin: 10px 0 0; }
.ok   { color: var(--ok); margin: 10px 0 0; }

/* ------------------------------------------------------------- sign in -- */

.signin-page { display: grid; place-items: center; }

.signin-wrap { width: 100%; padding: 24px; display: grid; place-items: center; min-height: 100vh; }

.signin {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 30px 28px 26px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, .06);
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand b { display: block; font-size: 17px; letter-spacing: .04em; }
.brand span { color: var(--muted); font-size: 13px; }

.signin label,
.modal label {
  display: block;
  margin: 14px 0 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}

.signin input,
.modal input,
.modal textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
}

.signin input:focus,
.modal input:focus,
.modal textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.signin button[type="submit"] {
  width: 100%;
  margin-top: 20px;
  padding: 12px;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.signin button[type="submit"]:hover { background: var(--accent-2); }
.signin button[type="submit"]:disabled { opacity: .6; cursor: default; }

/* --------------------------------------------------------------- shell -- */

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.top b { letter-spacing: .03em; }
.spacer { flex: 1; }
.who { color: var(--muted); font-size: 13px; }

.search { flex: 0 1 420px; margin-left: 18px; }

.search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel-2);
}

button.ghost {
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

button.ghost:hover { background: var(--panel-2); }
button.ghost:disabled { opacity: .5; cursor: default; }

/* Destructive, and dressed as such. Nothing else in this application is
   irreversible, so nothing else is red. */
button.danger,
.message-actions button.danger {
  color: var(--danger);
  border-color: #e8c9c4;
}

button.danger:hover { background: #fdf3f2; }

button.link {
  border: 0;
  background: none;
  color: var(--accent);
  text-decoration: underline;
  padding: 0;
}

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

/* ------------------------------------------------------------ folders -- */

.folders {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 14px 12px;
  overflow-y: auto;
}

.compose {
  width: 100%;
  padding: 11px;
  margin-bottom: 16px;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.compose:hover { background: var(--accent-2); }

.folders ul { list-style: none; margin: 0; padding: 0; }

.folder {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 11px;
  margin-bottom: 2px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  text-align: left;
}

.folder:hover { background: var(--panel-2); }
.folder.active { background: var(--unread); color: var(--accent-2); font-weight: 600; }

.badge {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 11.5px;
  text-align: center;
}

/* --------------------------------------------------------------- list -- */

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

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.list-head h1 { margin: 0; font-size: 15px; }

.rows { flex: 1; overflow-y: auto; }

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
}

.row:hover { background: var(--panel-2); }
.row.selected { background: var(--unread); }
.row.unread .row-who,
.row.unread .row-subject { font-weight: 700; }

.row-who     { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-when    { font-size: 12px; color: var(--muted); white-space: nowrap; }
.row-subject { grid-column: 1 / -1; font-size: 13.5px; color: #3c4250; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px;
  border-top: 1px solid var(--line);
}

.loading { padding: 26px 14px; color: var(--muted); text-align: center; }

/* ------------------------------------------------------------- reader -- */

.reader { overflow-y: auto; background: var(--bg); }

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

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

.message-head {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
  padding: 18px 20px;
}

.message-head h2 { margin: 0 0 12px; font-size: 19px; line-height: 1.35; }

.meta { font-size: 13.5px; }
.meta div { margin-bottom: 2px; }

.message-actions { display: flex; gap: 8px; margin-top: 14px; }

.message-actions button {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.message-actions #replyBtn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.images-blocked {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 20px;
  background: #fff8e6;
  border: 1px solid #f0e0b6;
  border-top: 0;
  font-size: 13px;
}

.attachments {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 20px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-top: 0;
}

.chip {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  font-size: 12.5px;
  color: var(--text);
  text-decoration: none;
}

/* Only the ones that are links. A chip listing a file about to be sent is not
   clickable and should not pretend to be. */
a.chip:hover {
  border-color: var(--accent);
  color: var(--accent-2);
  background: var(--unread);
}

.body {
  display: block;
  width: 100%;

  /* Fixed, and it scrolls inside. The frame is sandboxed to a null origin so
     the page cannot measure its contents to grow it - and letting it run a
     script purely to report its own height would hand a script back to a
     document whose whole purpose is not to have one. */
  height: 70vh;
  min-height: 320px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 12px 12px;
  background: #fff;
}

/* -------------------------------------------------------------- modal -- */

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

.modal-back[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 14px;
  padding: 24px 26px;
  box-shadow: 0 20px 50px rgba(16, 24, 40, .25);
}

.modal h3 { margin: 0 0 6px; font-size: 17px; }

.compose-modal { max-width: 680px; }

.modal textarea { resize: vertical; min-height: 120px; }

.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.actions button {
  padding: 10px 18px;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.actions button.ghost {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 400;
}

.tabs { display: flex; gap: 6px; margin: 16px 0 4px; border-bottom: 1px solid var(--line); }

.tab {
  padding: 9px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
}

.tab.active { color: var(--accent-2); border-bottom-color: var(--accent); font-weight: 600; }

.tab-body { padding-top: 6px; }
.tab-body[hidden] { display: none; }

/* ------------------------------------------------------------ smaller -- */

/*
 * Narrow windows show ONE of the two panes, not neither.
 *
 * The first version simply switched the reader off below 1000px, which meant
 * that on a laptop, or a browser at 125% zoom, clicking a message did
 * nothing at all: the click worked, the message loaded, and it was rendered
 * into a pane that CSS had removed from the page.
 *
 * So the list is what you see until you open something, and then the message
 * takes its place with a way back.
 */

.back-to-list { display: none; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 170px 1fr; }
  .search { flex-basis: 220px; }

  .reader { display: none; }

  .layout.reading .list   { display: none; }
  .layout.reading .reader { display: block; }

  /* Only useful where the two panes are not side by side. */
  .back-to-list { display: inline-block; }

  .message { padding: 12px; }
}

@media (max-width: 640px) {
  .layout { grid-template-columns: 1fr; }
  .folders { display: none; }
  .layout.reading .folders { display: none; }
  .who { display: none; }
}
