@import url("tokens.css");

:root {
  /* Proje marka rengi — sadece bu 3 satır override edilir (bkz. moonster-design/tokens.md) */
  --accent: #0071e3;
  --accent-dark: #0058b0;
  --accent-soft: #e8f2fe;

  /* Kutu rengi: her mail kutusuna id'sinden türetilen sabit bir hue atanır
     (inline --mb-h ile). Sabit renk listesi yok, sınırsız kutu destekler. */
  --mb-h: 210;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: linear-gradient(160deg, var(--bg-2), var(--bg-3));
  color: var(--fg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { letter-spacing: -0.02em; margin: 0 0 .3rem; }
a { color: inherit; }
svg.icon { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; display: block; }

/* ---------- App shell / topbar ---------- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border-dark);
  position: sticky; top: 0; z-index: 30;
}
.topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 15px; letter-spacing: -0.02em; text-decoration: none; color: var(--fg); }
.topbar .brand svg.icon { color: var(--accent); width: 22px; height: 22px; }
.topbar nav.desktop-nav { display: flex; align-items: center; gap: 4px; }
.topbar nav.desktop-nav a {
  display: flex; align-items: center; gap: 6px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 13px;
  padding: 8px 12px; border-radius: var(--radius-sm);
}
.topbar nav.desktop-nav a.active, .topbar nav.desktop-nav a:hover { color: var(--accent); background: var(--accent-soft); }
.topbar .logout-btn {
  display: flex; align-items: center; gap: 6px; background: none; border: none; cursor: pointer;
  color: var(--err); font-weight: 600; font-size: 13px; padding: 8px 10px; border-radius: var(--radius-sm); font-family: inherit;
}
.topbar .logout-btn:hover { background: color-mix(in srgb, var(--err) 8%, transparent); }

.content { flex: 1; padding: 20px; max-width: 1240px; margin: 0 auto; width: 100%; }
.bottom-nav { display: none; }

/* ---------- Auth ---------- */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-logo { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 22px; font-weight: 800; font-size: 17px; }
.auth-logo svg.icon { width: 26px; height: 26px; color: var(--accent); }

/* ---------- Card ---------- */
.card {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border-dark);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.input, textarea, select {
  width: 100%; padding: 11px 13px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg); font-size: 15px; font-family: inherit; color: var(--fg);
}
.input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 110px; resize: vertical; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 20px; border-radius: var(--radius-sm); border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: var(--bg); font-weight: 700; font-size: 14px; cursor: pointer; text-decoration: none;
  box-shadow: var(--shadow-sm); font-family: inherit;
}
.btn:active { transform: scale(0.98); }
.btn.secondary { background: var(--bg-3); color: var(--fg); box-shadow: none; }
.btn.small { padding: 7px 12px; font-size: 12px; }
.btn.block { width: 100%; }

/* ---------- Alerts ---------- */
.error { display:flex; align-items:center; gap:8px; background: color-mix(in srgb, var(--err) 8%, transparent); color: var(--err); padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 13px; font-weight: 600; }
.success { display:flex; align-items:center; gap:8px; background: color-mix(in srgb, var(--ok) 10%, transparent); color: var(--ok); padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 13px; font-weight: 600; }

/* ---------- Kutu rengi: nokta + rozet ---------- */
.mb-dot { width: 8px; height: 8px; border-radius: var(--radius-pill); background: hsl(var(--mb-h) 62% 45%); flex-shrink: 0; display: inline-block; }
.mb-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: hsl(var(--mb-h) 70% 96%); color: hsl(var(--mb-h) 62% 45%);
  padding: 3px 9px; border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 700; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- Inbox layout ---------- */
.layout { display: grid; grid-template-columns: 232px 380px 1fr; gap: 16px; align-items: start; }
.sidebar { padding: 12px; }
.sidebar a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm); color: var(--fg); text-decoration: none;
  font-size: 13px; font-weight: 600; margin-bottom: 2px;
}
.sidebar a svg.icon { width: 17px; height: 17px; color: var(--muted); }
.sidebar a .sb-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar a.active, .sidebar a:hover { background: var(--accent-soft); color: var(--accent); }
.sidebar a.active svg.icon { color: var(--accent); }

.thread-list { max-height: 78vh; overflow-y: auto; padding: 8px; }
.list-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px 10px; font-weight: 800; font-size: 13px; color: var(--fg);
  border-bottom: 1px solid var(--line); margin-bottom: 6px;
}
.list-head .count { font-size: 11px; font-weight: 700; color: var(--muted); background: var(--bg-3); padding: 2px 8px; border-radius: var(--radius-pill); }

.thread-item {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 11px 10px; border-radius: var(--radius-sm);
  text-decoration: none; color: var(--fg); margin-bottom: 2px;
  border-left: 3px solid transparent;
}
.thread-item:hover { background: var(--bg-3); border-left-color: hsl(var(--mb-h) 62% 45%); }
.thread-avatar {
  width: 36px; height: 36px; border-radius: var(--radius-pill); flex-shrink: 0;
  background: hsl(var(--mb-h) 62% 45%); color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}
.thread-main { min-width: 0; flex: 1; }
.thread-main .row-1 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.thread-main .who { font-weight: 700; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-main .time { font-size: 11px; color: var(--muted); flex-shrink: 0; font-weight: 600; }
.thread-main .subj {
  font-size: 13.5px; font-weight: 600; color: var(--fg); margin-top: 1px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.thread-main .subj .reply-mark { display: inline-block; width: 13px; height: 13px; color: var(--muted); vertical-align: -2px; margin-right: 2px; }
.thread-main .msg-count { font-size: 11px; font-weight: 700; color: var(--muted); background: var(--bg-3); padding: 0 6px; border-radius: var(--radius-pill); margin-left: 4px; }
.thread-main .preview {
  font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.thread-main .mb-chip { margin-top: 7px; }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 40px 20px; color: var(--muted); font-size: 13px; }
.empty-state svg.icon { width: 40px; height: 40px; margin-bottom: 10px; opacity: .45; }

/* ---------- Thread detay ---------- */
.thread-page { max-width: 860px; }
.thread-top {
  display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px;
  position: sticky; top: 62px; z-index: 20; margin-bottom: 14px;
  border-left: 4px solid hsl(var(--mb-h) 62% 45%);
}
.thread-top .back-link {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: var(--bg-3); color: var(--fg); text-decoration: none; flex-shrink: 0;
}
.thread-top .back-link svg.icon { width: 17px; height: 17px; }
.thread-top-main { min-width: 0; flex: 1; }
.thread-top-main h2 { font-size: 17px; line-height: 1.3; margin: 0 0 7px; }

.msg-stream { display: flex; flex-direction: column; gap: 12px; }
.msg { border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg); overflow: hidden; }
.msg.out { border-color: color-mix(in srgb, var(--accent) 28%, transparent); background: var(--accent-soft); }
.msg-head { display: flex; gap: 11px; align-items: center; padding: 13px 15px; border-bottom: 1px solid var(--line); }
.msg.out .msg-head { border-bottom-color: color-mix(in srgb, var(--accent) 18%, transparent); }
.msg-avatar {
  width: 34px; height: 34px; border-radius: var(--radius-pill); flex-shrink: 0;
  background: var(--bg-3); color: var(--muted);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.msg.out .msg-avatar { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); color: var(--bg); }
.msg-who { min-width: 0; flex: 1; }
.msg-who .line-1 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.msg-who .name { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-who .time { font-size: 11.5px; color: var(--muted); font-weight: 600; flex-shrink: 0; }
.msg-who .line-2 { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); margin-top: 1px; }
.msg-who .addr { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-who .arrow { flex-shrink: 0; opacity: .6; }

.msg-body { padding: 4px 15px 14px; }
.mail-frame { width: 100%; border: 0; display: block; min-height: 60px; background: transparent; }
.mail-frame.is-tall { border-bottom: 1px dashed var(--line); }
.mail-plain {
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
  font-size: 14.5px; line-height: 1.6; padding-top: 8px;
}

/* ---------- Yanıt kutusu ---------- */
/* Yanit kutusu akisin sonunda durur; sticky yapilirsa uzun maillerde
   icerigin uzerini kapatiyor (okumayi engelliyor). */
.reply-box { margin-top: 14px; padding: 16px; }
.reply-from { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); margin-bottom: 9px; font-weight: 600; }
.reply-from svg.icon { width: 14px; height: 14px; color: var(--accent); }
.reply-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.sig-hint { font-size: 12px; color: var(--muted); font-weight: 600; }
.sig-hint.link { color: var(--accent); text-decoration: none; }

/* ---------- Table ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px; color: var(--muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--line); }
td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: var(--radius-pill); font-size: 11px; font-weight: 700; }
.badge.on { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }
.badge.off { background: var(--bg-3); color: var(--muted); }
.badge .dot { width: 6px; height: 6px; border-radius: var(--radius-pill); background: currentColor; }

/* ---------- Mailbox kart listesi (mobil) ---------- */
.mb-cards { display: none; }
.mb-card { display: flex; align-items: center; gap: 12px; padding: 13px; border-radius: var(--radius-sm); background: var(--bg); border: 1px solid var(--line); margin-bottom: 8px; }
.mb-card .mb-icon { width: 36px; height: 36px; border-radius: var(--radius-sm); background: hsl(var(--mb-h) 70% 96%); color: hsl(var(--mb-h) 62% 45%); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.mb-card .mb-info { flex: 1; min-width: 0; }
.mb-card .mb-info .label { font-weight: 700; font-size: 14px; }
.mb-card .mb-info .email { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ================= MOBİL ================= */
@media (max-width: 900px) {
  .content { padding: 12px 12px 92px; }
  .card { padding: 15px; border-radius: var(--radius-sm); }

  .topbar { padding: 11px 14px; }
  .topbar nav.desktop-nav { display: none; }
  .topbar .logout-btn span { display: none; }

  .bottom-nav {
    display: flex; justify-content: space-around; align-items: center;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: var(--glass-bg); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
    border-top: 1px solid var(--glass-border-dark);
    padding: 7px 6px calc(7px + env(safe-area-inset-bottom));
  }
  .bottom-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    text-decoration: none; color: var(--muted); font-size: 10px; font-weight: 700;
    padding: 4px 14px; border-radius: var(--radius-sm);
  }
  .bottom-nav a.active { color: var(--accent); }
  .bottom-nav a svg.icon { width: 21px; height: 21px; }

  /* Gelen kutusu: yan menü yatay kaydırılan filtre şeridine dönüşür */
  .layout { display: block; }
  .layout .sidebar.card {
    display: flex; gap: 7px; padding: 9px; margin-bottom: 11px;
    overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .layout .sidebar.card::-webkit-scrollbar { display: none; }
  .layout .sidebar.card a { margin-bottom: 0; white-space: nowrap; flex-shrink: 0; padding: 8px 13px; }
  .layout .thread-list.card { max-height: none; padding: 6px; margin-bottom: 0; }
  .detail-placeholder { display: none; }

  .thread-item { padding: 11px 8px; }

  /* Konuşma detayı */
  .thread-top { position: static; padding: 13px 14px; }
  .thread-top-main h2 { font-size: 16px; }
  .msg-head { padding: 11px 12px; }
  .msg-body { padding: 2px 12px 12px; }
  .msg-who .line-2 { font-size: 11.5px; }
  .reply-box { position: static; padding: 14px; }

  table.mb-table { display: none; }
  .mb-cards { display: block; }
  .table-scroll table:not(.mb-table) { font-size: 12.5px; }
  .table-scroll table:not(.mb-table) td, .table-scroll table:not(.mb-table) th { padding: 8px 6px; }

  .form-grid-2 { grid-template-columns: 1fr; }
  .auth-shell { padding: 16px; align-items: flex-start; padding-top: 54px; }
}
