/*
 * Tempik Wenak — warm kitchen, not a cold console.
 * Amber and clay on charcoal: the palette of a warung at dusk.
 */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-root: #0d0a07;
  --bg-surface: #17120d;
  --bg-elevated: #201a13;
  --bg-hover: #2a2318;
  --border: #332b20;
  --border-strong: #463a29;

  --text-primary: #fdf8f0;
  --text-secondary: #cbbba4;
  --text-muted: #8f7f6a;

  --amber: #fbbf24;
  --amber-deep: #f59e0b;
  --clay: #ea580c;
  --clay-deep: #c2410c;
  --chili: #dc2626;
  --leaf: #65a30d;

  --warm-glow: rgba(251, 191, 36, 0.14);
  --clay-glow: rgba(234, 88, 12, 0.16);

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
  --transition: 170ms cubic-bezier(0.4, 0, 0.2, 1);
}

html,
body {
  min-height: 100%;
}

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-root);
  color: var(--text-primary);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(60rem 32rem at 50% -18%, rgba(234, 88, 12, 0.16), transparent 68%),
    radial-gradient(40rem 26rem at 88% 108%, rgba(251, 191, 36, 0.07), transparent 70%);
  background-attachment: fixed;
}

/* Steam rising from the top edge: the "still hot" cue. */
.steam {
  position: fixed;
  inset: 0 0 auto 0;
  height: 190px;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.steam span {
  position: absolute;
  top: 100%;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(251, 191, 36, 0.16), transparent 68%);
  filter: blur(16px);
  animation: rise 11s ease-in infinite;
}

.steam span:nth-child(1) { left: 22%; animation-delay: 0s; }
.steam span:nth-child(2) { left: 48%; animation-delay: 3.4s; width: 170px; height: 170px; }
.steam span:nth-child(3) { left: 70%; animation-delay: 6.7s; }

@keyframes rise {
  0%   { transform: translateY(20px) scale(0.7); opacity: 0; }
  25%  { opacity: 0.85; }
  100% { transform: translateY(-210px) scale(1.5); opacity: 0; }
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font-size: 13px;
  font-weight: 600;
  transition: background var(--transition), border-color var(--transition), transform var(--transition), color var(--transition);
}

button:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--clay);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.primary {
  background: linear-gradient(135deg, var(--amber) 0%, var(--clay) 100%);
  border-color: transparent;
  color: #1a1208;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(234, 88, 12, 0.28);
}

button.primary:hover:not(:disabled) {
  filter: brightness(1.06);
  border-color: transparent;
}

button.ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

.app {
  position: relative;
  z-index: 1;
  max-width: 820px;
  margin: 0 auto;
  padding: 52px 18px 96px;
}

/* ---------------- Header ---------------- */
header {
  text-align: center;
  margin-bottom: 28px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

header h1 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(30px, 5.4vw, 44px);
  font-weight: 700;
  letter-spacing: -1.2px;
  background: linear-gradient(120deg, #fff7e6 0%, var(--amber) 42%, var(--clay) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-tag {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: #2a1a06;
  background: linear-gradient(135deg, var(--amber), var(--amber-deep));
  border-radius: 999px;
  padding: 4px 11px;
  transform: translateY(2px);
}

header p {
  margin-top: 9px;
  font-size: 13.5px;
  color: var(--text-muted);
  font-style: italic;
}

/* ---------------- Address card ---------------- */
.address-card {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px;
  background: linear-gradient(160deg, #1d1610 0%, var(--bg-surface) 100%);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(251, 191, 36, 0.09);
  margin-bottom: 14px;
}

.address-main {
  min-width: 0;
  flex: 1 1 320px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.address-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  color: var(--text-muted);
  font-weight: 700;
}

.address-value {
  border: none;
  background: transparent;
  padding: 0;
  text-align: left;
  font-size: clamp(16px, 2.7vw, 22px);
  font-weight: 650;
  letter-spacing: -0.3px;
  color: var(--text-primary);
  overflow-wrap: anywhere;
  border-radius: 4px;
}

.address-value:hover:not(:disabled) {
  background: transparent;
  color: var(--amber);
  border-color: transparent;
}

.address-actions {
  display: flex;
  gap: 9px;
}

/* ---------------- Inbox chips ---------------- */
.inbox-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  min-width: 0;
}

.strip-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  color: var(--text-muted);
  font-weight: 700;
  flex: none;
}

.strip-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 3px;
  scrollbar-width: thin;
  flex: 1;
  min-width: 0;
  /* Fade the right edge instead of hard-clipping a chip mid-word. */
  mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
}

.chip {
  flex: none;
  white-space: nowrap;
  padding: 7px 13px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
}

/* Only the address truncates; the badge must always stay readable. */
.chip-address {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.chip.active {
  color: #1a1208;
  border-color: transparent;
  background: linear-gradient(135deg, var(--amber), var(--amber-deep));
}

.chip-count {
  font-size: 10.5px;
  font-weight: 700;
  background: rgba(26, 18, 8, 0.16);
  border-radius: 999px;
  padding: 1px 7px;
  flex: none;
}

.chip:not(.active) .chip-count {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-muted);
}

.chip:not(.active) .chip-count.has-unread {
  background: rgba(234, 88, 12, 0.22);
  color: var(--amber);
}

.attachment.eml {
  border-style: dashed;
  color: var(--text-secondary);
}

/* ---------------- Panel ---------------- */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(251, 191, 36, 0.045), transparent);
}

.panel-title {
  min-width: 0;
}

.panel-head h2 {
  font-size: 14px;
  font-weight: 650;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}

.panel-sub {
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.panel-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.live {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  transition: color var(--transition);
}

.live.active {
  color: var(--leaf);
}

.live.active::after {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--leaf);
  animation: pulse 2.2s ease-in-out infinite;
  vertical-align: middle;
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; }
  50%      { opacity: 1; }
}

/* ---------------- Search ---------------- */
.search-row {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
}

.search-row input {
  width: 100%;
  padding: 9px 13px;
  background: var(--bg-root);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.search-row input:focus {
  outline: none;
  border-color: var(--clay);
  box-shadow: 0 0 0 3px var(--clay-glow);
}

/* ---------------- Messages ---------------- */
.message-list {
  display: flex;
  flex-direction: column;
}

.message-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 15px 20px;
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}

.message-item:last-child {
  border-bottom: none;
}

.message-item::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: linear-gradient(180deg, var(--amber), var(--clay));
  opacity: 0;
  transition: opacity var(--transition);
}

.message-item:hover {
  background: var(--bg-hover);
}

.message-item:hover::before {
  opacity: 1;
}

.message-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.message-from {
  font-size: 13px;
  font-weight: 650;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-time {
  font-size: 11.5px;
  color: var(--text-muted);
  flex: none;
}

.message-subject {
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-preview {
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-tags {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.message-tags:empty {
  display: none;
}

.tag {
  font-size: 10.5px;
  font-weight: 650;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 999px;
  padding: 1px 9px;
}

.tag.warn {
  color: var(--chili);
  background: rgba(220, 38, 38, 0.13);
}

.message-item.suspect .message-from::after {
  content: ' ⚠';
  color: var(--chili);
}

/* ---------------- Empty state ---------------- */
.empty-state {
  padding: 56px 22px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 34px;
  opacity: 0.9;
}

.empty-state .title {
  margin-top: 12px;
  font-size: 14.5px;
  font-weight: 650;
  color: var(--text-secondary);
}

.empty-state .sub {
  margin-top: 6px;
  font-size: 12.5px;
  max-width: 34ch;
  margin-inline: auto;
}

.empty-state button {
  margin-top: 16px;
}

/* ---------------- Composer ---------------- */
.composer {
  display: flex;
  gap: 9px;
  margin-top: 14px;
  padding: 13px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.composer.hidden {
  display: none;
}

.composer input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  background: var(--bg-root);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
}

.composer input:focus,
.composer select:focus {
  outline: none;
  border-color: var(--clay);
  box-shadow: 0 0 0 3px var(--clay-glow);
}

.composer select {
  max-width: 42%;
  padding: 10px 12px;
  background: var(--bg-root);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* ---------------- Reader ---------------- */
.reader {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(8, 5, 3, 0.78);
  backdrop-filter: blur(7px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.reader.hidden {
  display: none;
}

.reader-shell {
  width: min(100%, 780px);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.reader-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
  background: linear-gradient(180deg, rgba(251, 191, 36, 0.05), transparent);
}

.reader-title {
  min-width: 0;
}

.reader-title h3 {
  font-size: 15.5px;
  font-weight: 680;
  overflow-wrap: anywhere;
}

.reader-title p {
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.reader-actions {
  display: flex;
  gap: 6px;
  flex: none;
}

.reader-body {
  flex: 1;
  overflow: auto;
  min-height: 200px;
  background: #fffdf8;
}

.reader-body iframe {
  width: 100%;
  height: 100%;
  min-height: 340px;
  border: none;
  display: block;
}

.reader-body pre.plain {
  padding: 20px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.7;
  color: #1c1509;
  background: #fffdf8;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.reader-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.reader-attachments:not(:empty) {
  padding: 13px 20px;
  border-top: 1px solid var(--border);
}

.attachment {
  font-size: 12px;
  font-weight: 600;
  color: var(--amber);
  text-decoration: none;
  background: var(--warm-glow);
  border: 1px solid rgba(251, 191, 36, 0.3);
  border-radius: 999px;
  padding: 5px 13px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: border-color var(--transition), background var(--transition);
}

.attachment:hover {
  border-color: var(--amber);
  background: rgba(251, 191, 36, 0.2);
}

/* ---------------- OTP chip ---------------- */
.otp-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
  padding: 7px 13px 7px 11px;
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.16), rgba(234, 88, 12, 0.14));
  border: 1px solid rgba(251, 191, 36, 0.45);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-primary);
  transition: border-color var(--transition), transform var(--transition);
}

.otp-chip:hover:not(:disabled) {
  border-color: var(--amber);
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.24), rgba(234, 88, 12, 0.2));
}

.otp-chip b {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 15px;
  letter-spacing: 1.5px;
  color: var(--amber);
}

.otp-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  font-weight: 700;
}

.otp-copy {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-secondary);
  border-left: 1px solid var(--border-strong);
  padding-left: 9px;
}

/* ---------------- Blocked images ---------------- */
.image-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 20px;
  background: rgba(234, 88, 12, 0.1);
  border-top: 1px solid rgba(234, 88, 12, 0.28);
  font-size: 11.5px;
  color: var(--text-secondary);
}

.image-notice.hidden {
  display: none;
}

.image-notice button {
  flex: none;
  font-size: 11.5px;
  padding: 6px 12px;
}

.blocked-image {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  color: #6b5b45;
  background: #f3ece0;
  border: 1px dashed #cbb894;
  border-radius: 6px;
}

/* ---------------- Address expiry + credit ---------------- */
.address-expiry {
  flex: 1 1 100%;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.address-expiry:empty {
  display: none;
}

footer .credit {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

footer .credit a {
  color: var(--amber);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition);
}

footer .credit a:hover {
  border-bottom-color: var(--amber);
}

button.danger {
  color: var(--chili);
  border-color: rgba(220, 38, 38, 0.28);
}

button.danger:hover:not(:disabled) {
  background: rgba(220, 38, 38, 0.14);
  border-color: var(--chili);
  color: #fca5a5;
}

/* ---------------- Footer ---------------- */
footer {
  margin-top: 24px;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ---------------- Toasts ---------------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
  pointer-events: none;
}

.toast {
  padding: 10px 17px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  box-shadow: var(--shadow);
  animation: toastIn 200ms ease-out;
  transition: opacity 220ms, transform 220ms;
}

.toast.success {
  border-color: rgba(101, 163, 13, 0.5);
  color: #bef264;
}

.toast.error {
  border-color: rgba(220, 38, 38, 0.5);
  color: #fca5a5;
}

.toast.fadeout {
  opacity: 0;
  transform: translateY(6px);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------------- Responsive ---------------- */
@media (max-width: 560px) {
  .app {
    padding: 30px 12px 84px;
  }

  .chip {
    max-width: 82vw;
  }

  .chip-count {
    flex: none;
  }

  .address-card {
    padding: 15px;
  }

  .address-actions {
    width: 100%;
  }

  .address-actions button {
    flex: 1;
  }

  .composer {
    flex-wrap: wrap;
  }

  .composer input,
  .composer select,
  .composer button {
    flex: 1 1 100%;
    max-width: none;
  }

  .reader {
    padding: 0;
  }

  .reader-shell {
    max-height: 100vh;
    height: 100%;
    border-radius: 0;
    border: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  .steam span {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------------- Admin ---------------- */
.admin-panel[hidden] {
  display: none;
}

.admin-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.admin-form input {
  flex: 1 1 190px;
  min-width: 0;
  padding: 9px 13px;
  background: var(--bg-root);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.admin-form input:focus {
  outline: none;
  border-color: var(--clay);
  box-shadow: 0 0 0 3px var(--clay-glow);
}

.admin-form input[type='number'] {
  flex: 0 1 160px;
}

/* One-time key reveal: warm and loud, because losing it means making a new key. */
.admin-reveal {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--warm-glow);
}

.admin-reveal[hidden] {
  display: none;
}

.admin-warn {
  flex-basis: 100%;
  font-size: 12px;
  font-weight: 600;
  color: var(--amber);
}

.admin-reveal code {
  flex: 1 1 260px;
  min-width: 0;
  padding: 9px 12px;
  background: var(--bg-root);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

.key-list {
  list-style: none;
}

.key-item {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  align-items: center;
  padding: 13px 20px;
  border-bottom: 1px solid var(--border);
}

.key-item:last-child {
  border-bottom: none;
}

.key-item.revoked {
  opacity: 0.45;
}

.key-main {
  flex: 1 1 220px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.key-name {
  font-size: 13.5px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.key-prefix {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
  font-size: 11.5px;
  color: var(--text-muted);
}

.key-meta {
  flex: 1 1 240px;
  min-width: 0;
  font-size: 11.5px;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.key-actions {
  flex: none;
}

.admin-empty {
  padding: 16px 20px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.admin-status {
  min-height: 1.2em;
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
}

.admin-status.error {
  color: var(--chili);
}
