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

:root {
  color-scheme: dark;
  --bg: #07080a;
  --surface: #101216;
  --surface-2: #171a20;
  --surface-3: #1e222a;
  --line: rgba(255,255,255,.09);
  --line-strong: rgba(255,255,255,.15);
  --text: #f4f6f8;
  --muted: #9299a6;
  --dim: #68707d;
  --accent: #7c6cf2;
  --accent-2: #9a8cff;
  --accent-soft: rgba(124,108,242,.14);
  --danger: #fb7185;
  --danger-soft: rgba(251,113,133,.1);
  --success: #72d59d;
  --shadow: 0 22px 70px rgba(0,0,0,.42);
  --radius: 16px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html { min-width: 320px; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 50% -12%, rgba(124,108,242,.17), transparent 65%),
    linear-gradient(180deg, #090a0d 0, var(--bg) 44%);
}
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.app { width: min(900px, calc(100% - 40px)); margin: 0 auto; padding: 64px 0 80px; }
header { display: grid; justify-items: center; text-align: center; margin-bottom: 38px; }
.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  margin-bottom: 16px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(255,255,255,.11), rgba(124,108,242,.22));
  box-shadow: inset 0 1px rgba(255,255,255,.12), 0 12px 34px rgba(95,74,233,.17);
  color: #fff;
  font-weight: 750;
}
header h1 { margin: 0; font-size: clamp(32px, 6vw, 46px); letter-spacing: -.055em; line-height: 1; }
header p { margin: 11px 0 0; color: var(--muted); font-size: 14px; }

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto auto auto auto;
  gap: 8px;
  margin-bottom: 14px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(16,18,22,.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
select, input {
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color .16s, background .16s, box-shadow .16s;
}
select { padding: 0 38px 0 13px; }
input { padding: 0 14px; }
select:hover, input:hover { border-color: var(--line-strong); }
input::placeholder { color: var(--dim); }

button {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: #c9ced7;
  font-size: 12px;
  font-weight: 650;
  transition: transform .15s, border-color .15s, background .15s, color .15s;
}
button:hover { border-color: var(--line-strong); background: var(--surface-3); color: #fff; }
button:active { transform: translateY(1px); }
button.primary, #createCustomBtn {
  border-color: rgba(140,124,255,.42);
  background: linear-gradient(180deg, #8272f5, #6857df);
  color: #fff;
  box-shadow: inset 0 1px rgba(255,255,255,.16);
}
button.primary:hover, #createCustomBtn:hover { background: linear-gradient(180deg, #9184fa, #7565e8); }
button.danger { border-color: transparent; background: transparent; color: #8d6470; }
button.danger:hover { background: var(--danger-soft); color: var(--danger); }
body.busy button { pointer-events: none; opacity: .58; }

.new-box {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(190px, auto) auto auto;
  gap: 9px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid rgba(124,108,242,.27);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(124,108,242,.09), rgba(16,18,22,.96));
  animation: reveal .18s ease-out;
}
.new-box.hidden { display: none; }
@keyframes reveal { from { opacity: 0; transform: translateY(-7px); } }

.panel {
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(16,18,22,.92);
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  min-height: 78px;
  padding: 17px 20px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.025), transparent);
}
.eyebrow { display: block; margin-bottom: 5px; color: var(--dim); font-size: 9px; font-weight: 750; letter-spacing: .14em; }
.panel-head h2 { margin: 0; overflow-wrap: anywhere; font-size: 15px; font-weight: 650; letter-spacing: -.015em; }
.panel-head > span {
  flex: none;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.message-list { min-height: 280px; }
.message-item { padding: 20px; border-bottom: 1px solid var(--line); transition: background .15s; }
.message-item:last-child { border-bottom: 0; }
.message-item:hover { background: rgba(255,255,255,.018); }
.message-meta { margin-bottom: 8px; color: var(--dim); font-size: 11px; font-weight: 600; overflow-wrap: anywhere; }
.message-item strong { display: block; margin-bottom: 9px; color: var(--text); font-size: 14px; }
.message-item p { margin: 0; color: #b7bdc8; font-size: 13px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }

.empty-state { display: grid; min-height: 280px; padding: 42px 24px; place-content: center; justify-items: center; text-align: center; }
.empty-icon {
  display: grid;
  width: 38px;
  height: 38px;
  margin-bottom: 16px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--accent-2);
  font-size: 18px;
}
.empty-state .title { margin-bottom: 7px; font-size: 15px; font-weight: 650; }
.empty-state .sub { max-width: 380px; color: var(--muted); font-size: 13px; line-height: 1.55; }

footer { padding: 25px 0 0; color: var(--dim); text-align: center; font-size: 11px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.toast-container { position: fixed; right: 22px; bottom: 22px; z-index: 20; display: grid; gap: 8px; }
.toast {
  max-width: min(380px, calc(100vw - 32px));
  padding: 12px 15px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #1b1e24;
  box-shadow: 0 16px 44px rgba(0,0,0,.45);
  color: #e8ebef;
  font-size: 12px;
  animation: toast-in .18s ease-out;
}
.toast.error { border-color: rgba(251,113,133,.35); color: #fecdd3; }
.toast.fadeout { opacity: 0; transform: translateY(5px); transition: .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 760px) {
  .app { width: min(100% - 24px, 600px); padding: 36px 0 60px; }
  header { margin-bottom: 28px; }
  .toolbar { grid-template-columns: repeat(4, 1fr); }
  .toolbar select { grid-column: 1 / -1; width: 100%; }
  .toolbar button { padding: 0 8px; min-height: 44px; }
  .new-box { grid-template-columns: 1fr 1fr; }
  .new-box input, .new-box select { grid-column: 1 / -1; height: 44px; }
  .new-box button { min-height: 44px; }
}

@media (max-width: 430px) {
  .app { width: calc(100% - 20px); padding-top: 28px; }
  header h1 { font-size: 34px; }
  .toolbar { grid-template-columns: repeat(2, 1fr); }
  .toolbar button { font-size: 11px; }
  .panel-head { align-items: flex-start; padding: 15px; }
  .message-item { padding: 16px 15px; }
  .toast-container { right: 10px; bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
