/* HAMOKSHA - cat-inspired theme: ginger tabby, grey tabby, cream and charcoal. */

:root {
  --ink: #2b2118;
  --ink-soft: #5e4d3f;
  --cream: #fff8ee;
  --paper: #ffffff;
  --ginger: #e8883a;
  --ginger-dark: #b9611a;
  --ginger-soft: #fde7cf;
  --grey: #8a8f98;
  --grey-soft: #eceef1;
  --eye: #6fa85b;
  --paw: #f3b6b0;
  --danger: #b83a2b;
  --line: #ecdcc7;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(43, 33, 24, 0.08);
  --font: 'Nunito', 'Cairo', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--cream);
  line-height: 1.55;
  display: flex;
  flex-direction: column;
}
html[lang="ar"] body { font-family: 'Cairo', 'Nunito', system-ui, sans-serif; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin-top: 1.25rem; }
p { margin: 0 0 .6rem; }
.muted { color: var(--ink-soft); font-size: .9rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 3px solid var(--eye); outline-offset: 2px; }

/* ---------- Buttons & inputs ---------- */
.btn {
  font: inherit; font-weight: 700; cursor: pointer;
  border: 2px solid transparent; border-radius: 999px;
  padding: .6rem 1.2rem; transition: transform .08s, background .15s, border-color .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--ginger); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--ginger-dark); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--ginger-soft); border-color: var(--ginger); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: .3rem .85rem; font-size: .85rem; }
.btn-block { width: 100%; }

input, textarea, select {
  font: inherit; color: inherit; width: 100%;
  background: var(--paper); border: 2px solid var(--line); border-radius: 12px;
  padding: .6rem .8rem;
}
input:focus, textarea:focus, select:focus { border-color: var(--ginger); outline: none; }
textarea { resize: none; }

/* ---------- Top bar ---------- */
.banner { background: var(--ink); color: #fff; text-align: center; padding: .6rem 1rem; font-weight: 700; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1.2rem; background: var(--paper); border-bottom: 2px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--ink); text-decoration: none; font-weight: 800; letter-spacing: .12em; }
.top-actions { display: flex; align-items: center; gap: .75rem; }
.user-box { display: flex; align-items: center; gap: .75rem; }
.user-text { display: flex; flex-direction: column; text-align: end; line-height: 1.2; }

/* ---------- Auth ---------- */
.auth {
  flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 3rem; align-items: center;
  max-width: 980px; width: 100%; margin: 0 auto; padding: 2.5rem 1.2rem;
}
.hero { text-align: center; }
.hero h1 { font-size: 2.6rem; letter-spacing: .16em; color: var(--ginger-dark); }
.hero-cat { animation: bob 4s ease-in-out infinite; }
.tagline { font-size: 1.15rem; font-weight: 700; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-2deg); } }
@media (prefers-reduced-motion: reduce) { .hero-cat { animation: none; } }

.card {
  position: relative; background: var(--paper); border: 2px solid var(--line);
  border-radius: 22px; padding: 1.6rem; box-shadow: var(--shadow);
}
/* cat ears on the card */
.card.ears::before, .card.ears::after {
  content: ''; position: absolute; top: -17px; width: 36px; height: 30px;
  background: var(--ginger); clip-path: polygon(0 100%, 50% 0, 100% 100%); z-index: -1;
}
.card.ears::before { inset-inline-start: 28px; }
.card.ears::after { inset-inline-end: 28px; }

.tabs { display: flex; gap: .4rem; background: var(--grey-soft); padding: .3rem; border-radius: 999px; margin-bottom: 1.2rem; }
.tabs button {
  flex: 1; border: 0; background: transparent; font: inherit; font-weight: 700; padding: .5rem;
  border-radius: 999px; cursor: pointer; color: var(--ink-soft);
}
.tabs button[aria-selected="true"] { background: var(--paper); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.12); }

.form { display: grid; gap: .9rem; }
.form label { display: grid; gap: .3rem; font-weight: 700; font-size: .92rem; }
.role-pick { border: 0; padding: 0; margin: 0; display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.role-pick legend { font-weight: 700; font-size: .92rem; padding: 0; margin-bottom: .3rem; }
.chip { display: inline-flex !important; }
.chip input { position: absolute; opacity: 0; width: 0; }
.chip span {
  border: 2px solid var(--line); border-radius: 999px; padding: .35rem 1rem; cursor: pointer; font-weight: 700;
}
.chip input:checked + span { background: var(--ginger-soft); border-color: var(--ginger); }
.chip input:focus-visible + span { outline: 3px solid var(--eye); }

/* ---------- App layout ---------- */
.app { flex: 1; display: grid; grid-template-columns: 270px 1fr; min-height: 0; }
.sidebar {
  background: var(--paper); border-inline-end: 2px solid var(--line);
  padding: 1rem; overflow-y: auto; display: flex; flex-direction: column; gap: 1rem;
}
.nav-title { font-size: .75rem; text-transform: uppercase; letter-spacing: .1em; color: var(--grey); font-weight: 800; margin: .6rem .4rem .3rem; }
#nav button {
  display: flex; align-items: center; gap: .6rem; width: 100%; text-align: start;
  background: transparent; border: 0; font: inherit; font-weight: 700; color: var(--ink);
  padding: .55rem .7rem; border-radius: 12px; cursor: pointer;
}
#nav button:hover { background: var(--ginger-soft); }
#nav button.active { background: var(--ginger); color: #fff; }
#nav .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--paw); flex: none; }
#nav button.active .dot { background: #fff; }

.history-head { display: flex; justify-content: space-between; align-items: center; }
.history ul, .class-list, .room-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.history li button {
  width: 100%; text-align: start; border: 0; background: transparent; font: inherit; color: var(--ink-soft);
  padding: .45rem .7rem; border-radius: 10px; cursor: pointer; overflow: hidden;
}
.history li button span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history li button:hover { background: var(--grey-soft); }
.history li.active button { background: var(--grey-soft); color: var(--ink); font-weight: 700; }

.main { padding: 1.2rem 1.5rem; min-width: 0; display: flex; flex-direction: column; min-height: 0; height: calc(100vh - 62px); }
.stage-title { font-size: 1.4rem; }
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.panel { background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.empty { color: var(--grey); text-align: center; padding: 1.5rem 1rem; list-style: none; }

/* ---------- Chat ---------- */
.chat-root { display: flex; flex-direction: column; flex: 1; min-height: 0; padding: 0; overflow: hidden; }
.messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .8rem; scroll-behavior: smooth; }
.msg { display: flex; gap: .6rem; align-items: flex-end; max-width: 85%; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.avatar { width: 32px; height: 32px; flex: none; }
.bubble { background: var(--grey-soft); border-radius: 16px; padding: .55rem .85rem; min-width: 0; }
.msg-ai .bubble { background: var(--ginger-soft); border-end-start-radius: 4px; }
.msg-teacher .bubble { background: #e3f1dc; border: 1px solid var(--eye); }
.msg.mine .bubble { background: var(--ink); color: #fff; border-end-end-radius: 4px; }
.msg.mine.msg-teacher .bubble { background: #2f5a24; color: #fff; }
.meta { display: flex; gap: .6rem; font-size: .75rem; opacity: .7; font-weight: 700; margin-bottom: .15rem; }
.body p { margin: 0 0 .45rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.body p:last-child { margin-bottom: 0; }
.body pre { background: #1f1812; color: #f6e9d8; padding: .7rem .9rem; border-radius: 10px; overflow-x: auto; margin: .4rem 0; direction: ltr; text-align: left; }
.body code.inline { background: rgba(0,0,0,.1); padding: .05rem .35rem; border-radius: 6px; direction: ltr; unicode-bidi: embed; }
.typing .bubble { display: flex; gap: 4px; padding: .8rem 1rem; }
.typing .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ginger-dark); animation: blink 1.2s infinite; }
.typing .dot:nth-child(3) { animation-delay: .15s; }
.typing .dot:nth-child(4) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.composer { display: flex; gap: .6rem; align-items: flex-end; padding: .8rem; border-top: 2px solid var(--line); background: var(--cream); }
.composer textarea { max-height: 160px; }

/* ---------- Teacher ---------- */
.teacher-layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 1rem; }
.teacher-left { display: flex; flex-direction: column; gap: 1rem; overflow-y: auto; min-height: 0; }
.inline-form { display: flex; gap: .5rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .6rem; }
.panel-head select { width: auto; padding: .3rem .6rem; }
.room-card button {
  width: 100%; text-align: start; display: grid; gap: .1rem; background: var(--cream);
  border: 2px solid var(--line); border-radius: 12px; padding: .55rem .75rem; font: inherit; cursor: pointer; color: inherit;
}
.room-card button:hover { border-color: var(--ginger); }
.room-card.active button { border-color: var(--ginger); background: var(--ginger-soft); }
.tag { justify-self: start; background: var(--grey-soft); border-radius: 999px; padding: 0 .6rem; font-size: .75rem; font-weight: 800; color: var(--ink-soft); }
.monitor { display: flex; flex-direction: column; min-height: 0; padding: 0; overflow: hidden; }
.monitor-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.monitor-bar { display: flex; align-items: center; gap: .6rem; padding: .8rem 1rem .2rem; }
.hint { padding: 0 1rem; margin: 0 0 .4rem; }
.monitor .chat-root { border: 0; border-radius: 0; border-top: 2px solid var(--line); }

.class-item { display: flex; justify-content: space-between; align-items: center; gap: .6rem; background: var(--cream); border: 2px solid var(--line); border-radius: 12px; padding: .6rem .8rem; }
.class-info { display: grid; min-width: 0; }
.class-actions { display: flex; gap: .4rem; flex: none; }

/* ---------- Classroom ---------- */
.meeting { position: fixed; inset: 0; z-index: 100; background: #1d1610; color: #fff; display: flex; flex-direction: column; padding: 1rem; gap: .8rem; }
.meeting-status { text-align: center; opacity: .8; margin: 0; }
.video-grid { flex: 1; min-height: 0; display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); grid-auto-rows: minmax(160px, 1fr); }
.video-grid[data-count="1"] { grid-template-columns: 1fr; }
.tile { position: relative; background: #000; border-radius: 14px; overflow: hidden; border: 2px solid #3a2d21; }
.tile video { width: 100%; height: 100%; object-fit: cover; }
.tile-label { position: absolute; bottom: .5rem; inset-inline-start: .5rem; background: rgba(0,0,0,.6); border-radius: 999px; padding: .1rem .7rem; font-size: .8rem; font-weight: 700; }
.meeting-controls { display: flex; justify-content: center; gap: .6rem; }
.meeting .btn-ghost { color: #fff; border-color: #5a4635; }
.meeting .btn-ghost[aria-pressed="false"] { background: #5a2a22; border-color: var(--danger); text-decoration: line-through; }
body.in-meeting { overflow: hidden; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; inset-inline-end: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 200; max-width: min(92vw, 380px); }
.toast { background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: 12px; box-shadow: var(--shadow); transition: opacity .4s, transform .4s; }
.toast-error { background: var(--danger); }
.toast-success { background: #2f6f3e; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; gap: 1.5rem; }
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { border-inline-end: 0; border-bottom: 2px solid var(--line); flex-direction: column; padding: .6rem; max-height: 38vh; }
  #nav { display: flex; flex-wrap: wrap; gap: .3rem; }
  #nav .nav-title { display: none; }
  #nav button { width: auto; padding: .4rem .8rem; border: 2px solid var(--line); }
  .main { height: auto; padding: .8rem; }
  .teacher-layout { grid-template-columns: 1fr; }
  .teacher-left { overflow: visible; }
  .monitor { min-height: 60vh; }
  .msg { max-width: 95%; }
  .user-text { display: none; }
}
