:root {
  --ink: #201C1A; --ink-soft: #4A413C; --muted: #756B64;
  --canvas: #FAF7F3; --canvas-alt: #F1EBE3; --line: #E4DBD0;
  --accent: #C4391C; --accent-dark: #8F2610; --accent-bg: #FCEAE3; --white: #fff;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--canvas); color: var(--ink); line-height: 1.55; -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }

.btn {
  background: var(--accent); color: var(--white); border: 0; font-weight: 700;
  padding: 11px 18px; border-radius: 8px; box-shadow: 3px 3px 0 var(--accent-dark);
}
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--accent-dark); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink-soft); box-shadow: none; border: 1px solid var(--line); font-weight: 600; }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.danger { background: var(--accent-dark); box-shadow: none; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.card {
  background: var(--white); border: 1px solid var(--line); border-radius: 14px; padding: 28px;
  width: 100%; max-width: 380px; box-shadow: 6px 6px 0 rgba(32,28,26,.06), 0 20px 40px rgba(32,28,26,.08);
}
.card img.logo { width: 64px; height: 64px; border-radius: 14px; margin-bottom: 14px; }
.card h1 { font-size: 24px; font-weight: 800; margin-bottom: 4px; }
.card p.sub { color: var(--muted); margin-bottom: 20px; font-size: 15px; }
label { display: block; font-size: 14px; font-weight: 600; margin: 12px 0 4px; color: var(--ink-soft); }
input[type=text], input[type=password] {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--canvas); color: var(--ink);
}
input:focus-visible, button:focus-visible { outline: 3px solid var(--accent-bg); outline-offset: 1px; border-color: var(--accent); }
.card .btn { width: 100%; margin-top: 20px; }
.err { color: var(--accent-dark); font-size: 14px; margin-top: 12px; min-height: 1.2em; }

/* Chat-Layout */
.app { height: 100%; display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; }
header.bar {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--canvas);
}
header.bar img { width: 34px; height: 34px; border-radius: 8px; }
header.bar .title { font-weight: 800; flex: 1; }
header.bar .who { color: var(--muted); font-size: 14px; }
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: 110%; background: var(--white); border: 1px solid var(--line); border-radius: 10px;
  min-width: 190px; box-shadow: 0 12px 30px rgba(32,28,26,.15); z-index: 10; overflow: hidden;
}
.menu-list button, .menu-list a {
  display: block; width: 100%; text-align: left; padding: 11px 14px; background: none; border: 0; color: var(--ink); text-decoration: none; font-size: 15px;
}
.menu-list button:hover, .menu-list a:hover { background: var(--canvas-alt); }

.chat-log { flex: 1; overflow-y: auto; padding: 18px 16px; }
.msg { margin-bottom: 18px; font-size: 16px; line-height: 1.65; max-width: 100%; overflow-wrap: anywhere; }
.msg.user { font-weight: 700; }
.msg.bot { color: var(--ink-soft); }
.msg.bot a { color: var(--accent-dark); text-decoration: underline; }
.msg.error { color: var(--accent-dark); }
.examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.examples button {
  background: var(--accent-bg); color: var(--accent-dark); border: 1px solid #F0C9B9; border-radius: 999px; padding: 7px 13px; font-size: 14px; font-weight: 600; text-align: left;
}
form.ask {
  display: flex; gap: 8px; padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--canvas);
}
form.ask input { flex: 1; font-size: 16px; }
.hint { font-size: 12px; color: var(--muted); text-align: center; padding: 0 16px 8px; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: min(380px, 92vw); margin: auto; }
dialog::backdrop { background: rgba(32,28,26,.45); }
dialog .row { display: flex; gap: 8px; margin-top: 18px; }
dialog .row .btn { margin-top: 0; }

/* Admin */
.admin { max-width: 860px; margin: 0 auto; padding: 16px; }
.admin h1 { font-size: 22px; margin: 6px 0 14px; }
.admin form.new { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 18px; }
.admin form.new div { flex: 1 1 160px; }
.admin form.new label { margin-top: 0; }
.admin .chk { flex: 0 0 auto !important; display: flex; align-items: center; gap: 6px; padding-bottom: 11px; }
.admin .chk label { margin: 0; }
table { width: 100%; border-collapse: collapse; background: var(--white); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; font-size: 15px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: var(--canvas-alt); font-size: 13px; color: var(--muted); }
td .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; background: var(--accent-bg); color: var(--accent-dark); border-radius: 999px; padding: 1px 8px; margin-left: 6px; }
.tag.off { background: var(--canvas-alt); color: var(--muted); }
.pwbox { background: #FFF6D6; border: 1px solid #E8D48A; border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; }
.pwbox code { font-size: 18px; font-weight: 700; user-select: all; word-break: break-all; }
@media (max-width: 640px) { .hide-sm { display: none; } }
.byline {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  width: fit-content; max-width: calc(100% - 32px); margin: 2px auto max(12px, env(safe-area-inset-bottom));
  padding: 6px 14px 6px 7px; background: var(--white); color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 999px; font-size: 14px; text-decoration: none;
  box-shadow: 3px 3px 0 rgba(196,57,28,.14); transition: transform .12s ease, box-shadow .12s ease;
}
.byline img { border-radius: 8px; flex: none; }
.byline strong { color: var(--accent-dark); font-weight: 800; }
.byline .arr { color: var(--accent); font-weight: 800; }
.byline:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 rgba(196,57,28,.2); }
