/*
 * Ruang Belajar: tombol sesi, tautan materi, chat mentor, dan lampiran.
 * Gaya Ruang Penulis: hijau hutan, kuning kertas, tuts mesin tik, kertas bergaris.
 *
 * File ini hanya mengatur tampilan (CSS). Tidak menyentuh data, database, atau file peserta.
 * Dimuat paling akhir di index.php, jadi aturan di sini menimpa gaya lama dengan aman.
 */

:root {
  --rpx-green: #174c39;
  --rpx-green-hover: #1f5e47;
  --rpx-green-deep: #0e3425;
  --rpx-gold: #ffce0c;
  --rpx-gold-soft: #fff6cf;
  --rpx-gold-line: #f0d96b;
  --rpx-leaf: #eef4e5;
  --rpx-leaf-line: #d5e4cb;
  --rpx-paper: #fbfcf4;
  --rpx-ruled: #e7eedb;
  --rpx-ink: #1d3b2c;
  --rpx-muted: #5f735a;
  --rpx-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ==========================================================================
   1. Tombol "Buka sesi" dan tautan materi: tampil seperti tuts mesin tik
   ========================================================================== */

body .rp-class-footer button[data-open-session],
body .rp-session-originals .area-body > a[href],
body .session-area .area-body > a[href],
body .session-block.archived > a[href] {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 10px !important;
  min-height: 48px !important;
  padding: 12px 22px !important;
  border: 1px solid var(--rpx-green-deep) !important;
  border-radius: 14px !important;
  background: linear-gradient(180deg, var(--rpx-green-hover), var(--rpx-green)) !important;
  color: #fff !important;
  font-size: 14px !important;
  font-weight: 800 !important;
  line-height: 1.4 !important;
  letter-spacing: 0.01em;
  text-decoration: none !important;
  /* sisi bawah tebal = tuts yang bisa ditekan */
  box-shadow:
    0 4px 0 var(--rpx-green-deep),
    0 10px 18px rgba(23, 76, 57, 0.22) !important;
  transition:
    transform 0.18s var(--rpx-ease),
    box-shadow 0.18s var(--rpx-ease),
    background 0.18s;
  cursor: pointer;
}

body .rp-session-originals .area-body > a[href],
body .session-area .area-body > a[href],
body .session-block.archived > a[href] {
  margin: 12px 10px 10px 0;
}

body .rp-class-footer button[data-open-session]:hover,
body .rp-session-originals .area-body > a[href]:hover,
body .session-area .area-body > a[href]:hover,
body .session-block.archived > a[href]:hover {
  transform: translateY(-2px);
  box-shadow:
    0 6px 0 var(--rpx-green-deep),
    0 14px 22px rgba(23, 76, 57, 0.26) !important;
}

body .rp-class-footer button[data-open-session]:active,
body .rp-session-originals .area-body > a[href]:active,
body .session-area .area-body > a[href]:active,
body .session-block.archived > a[href]:active {
  transform: translateY(3px);
  box-shadow:
    0 1px 0 var(--rpx-green-deep),
    0 4px 8px rgba(23, 76, 57, 0.2) !important;
}

body .rp-class-footer button[data-open-session] svg {
  flex-shrink: 0;
  transition: transform 0.25s var(--rpx-ease);
}

body .rp-class-footer button[data-open-session]:hover svg {
  transform: translate(2px, -2px) rotate(-6deg);
}

body .rp-class-footer button[data-open-session]:focus-visible,
body .rp-session-originals .area-body > a[href]:focus-visible,
body .session-area .area-body > a[href]:focus-visible,
body .session-block.archived > a[href]:focus-visible {
  outline: 3px solid var(--rpx-gold);
  outline-offset: 3px;
}

/* ==========================================================================
   2. Chat mentor: kertas bergaris, gelembung hangat, tombol tuts
   ========================================================================== */

#rp-floating-chat .rp-floating-header {
  background:
    radial-gradient(circle at 12px 12px, rgba(255, 206, 12, 0.22) 1.5px, transparent 2px) 0 0 / 24px 24px,
    linear-gradient(135deg, var(--rpx-green-deep), var(--rpx-green) 55%, var(--rpx-green-hover));
}

#rp-floating-chat .rp-floating-avatar {
  background: var(--rpx-gold);
  color: var(--rpx-green);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
}

#rp-floating-chat #rp-floating-policy {
  background: var(--rpx-gold-soft);
  color: #4d4200;
  border-left: 4px solid var(--rpx-gold);
  font-size: 12px;
  line-height: 1.6;
}

#rp-floating-chat #rp-floating-messages {
  background-color: var(--rpx-paper);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 27px,
    var(--rpx-ruled) 27px,
    var(--rpx-ruled) 28px
  );
  background-attachment: local;
}

#rp-floating-chat .rp-floating-message {
  background: #fff;
  border: 1px solid var(--rpx-leaf-line);
  border-radius: 16px 16px 16px 5px;
  box-shadow: 0 2px 0 rgba(23, 76, 57, 0.07);
  color: var(--rpx-ink);
}

#rp-floating-chat .rp-floating-message.own {
  background: var(--rpx-gold-soft);
  border-color: var(--rpx-gold-line);
  border-radius: 16px 16px 5px 16px;
}

#rp-floating-chat .rp-floating-message > strong {
  color: var(--rpx-green);
  font-size: 12px;
}

#rp-floating-chat .rp-floating-message > small {
  color: var(--rpx-muted);
  font-size: 10.5px;
}

#rp-floating-chat .rp-chat-empty {
  text-align: center;
  color: var(--rpx-muted);
  line-height: 1.7;
}

#rp-floating-chat .rp-chat-empty::before {
  content: '';
  display: block;
  width: 46px;
  height: 46px;
  margin: 0 auto 10px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Ccircle cx='24' cy='24' r='23' fill='%23ffce0c'/%3E%3Cpath d='M14 34l2-8 14-14a3 3 0 0 1 4 0l2 2a3 3 0 0 1 0 4L22 32l-8 2z' fill='%23174c39'/%3E%3Cpath d='M28 15l5 5' stroke='%23ffce0c' stroke-width='2'/%3E%3C/svg%3E")
    center / contain no-repeat;
}

#rp-floating-chat #rp-floating-input {
  border-radius: 14px;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

#rp-floating-chat #rp-floating-input:focus {
  border-color: var(--rpx-green);
  box-shadow: 0 0 0 3px rgba(255, 206, 12, 0.45);
  outline: none;
}

/* Tombol kirim + lampirkan */
.rp-chat-send-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
}

.rp-chat-send-actions #rp-floating-send {
  flex: 1;
  min-width: 0;
  margin: 0;
  min-height: 44px;
  border: 1px solid var(--rpx-green-deep);
  border-radius: 13px;
  background: linear-gradient(180deg, var(--rpx-green-hover), var(--rpx-green));
  color: #fff;
  font-weight: 800;
  box-shadow: 0 3px 0 var(--rpx-green-deep);
  transition:
    transform 0.16s var(--rpx-ease),
    box-shadow 0.16s var(--rpx-ease);
}

.rp-chat-send-actions #rp-floating-send:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 0 var(--rpx-green-deep);
}

.rp-chat-send-actions #rp-floating-send:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--rpx-green-deep);
}

.rp-chat-send-actions #rp-floating-send:disabled {
  opacity: 0.5;
  box-shadow: none;
  cursor: default;
}

.rp-chat-send-actions #rp-floating-attach {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 10px 14px;
  border: 1.5px dashed #9fbe8d;
  border-radius: 13px;
  background: var(--rpx-leaf);
  color: var(--rpx-green);
  font-size: 12px;
  font-weight: 800;
  transition:
    background 0.15s,
    border-color 0.15s;
}

.rp-chat-send-actions #rp-floating-attach svg {
  transition: transform 0.25s var(--rpx-ease);
}

.rp-chat-send-actions #rp-floating-attach:hover:not(:disabled) {
  background: var(--rpx-gold-soft);
  border-color: var(--rpx-gold);
}

.rp-chat-send-actions #rp-floating-attach:hover:not(:disabled) svg {
  transform: rotate(-18deg) translateY(-1px);
}

.rp-chat-send-actions #rp-floating-attach:disabled {
  opacity: 0.45;
  cursor: default;
}

#rp-floating-file[hidden],
#rp-floating-attachment[hidden] {
  display: none !important;
}

/* Peluncur chat */
#rp-chat-launcher {
  transition: transform 0.2s var(--rpx-ease);
}

#rp-chat-launcher:hover {
  transform: translateY(-3px) rotate(-5deg);
}

/* ==========================================================================
   3. Lampiran: catatan tempel sebelum dikirim, foto cetak dan kartu file setelahnya
   ========================================================================== */

/* Lampiran yang dipilih, siap dikirim (bisa lebih dari satu) */
#rp-floating-attachment {
  position: relative;
  margin-bottom: 12px;
  padding: 6px 12px;
  border: 1.5px dashed var(--rpx-gold-line);
  border-radius: 14px;
  background: var(--rpx-gold-soft);
  transform: rotate(-0.6deg);
  animation: rpx-pop 0.28s var(--rpx-ease);
}

/* selotip kecil di pojok */
#rp-floating-attachment::before {
  content: '';
  position: absolute;
  top: -8px;
  left: 18px;
  width: 44px;
  height: 14px;
  border-radius: 2px;
  background: rgba(255, 206, 12, 0.7);
  transform: rotate(-4deg);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
}

#rp-floating-attachment .rp-attachment-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

#rp-floating-attachment .rp-attachment-item + .rp-attachment-item {
  border-top: 1px dashed var(--rpx-gold-line);
}

#rp-floating-attachment .rp-attachment-item > img {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border: 3px solid #fff;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 2px 6px rgba(23, 76, 57, 0.22);
}

#rp-floating-attachment .rp-attachment-item > div {
  flex: 1;
  min-width: 0;
}

#rp-floating-attachment strong {
  display: block;
  color: var(--rpx-green);
  font-size: 12.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

#rp-floating-attachment small {
  display: block;
  margin-top: 2px;
  color: var(--rpx-muted);
  font-size: 11px;
  line-height: 1.5;
}

#rp-floating-attachment .rp-attachment-total {
  margin: 0;
  padding: 7px 0 4px;
  border-top: 1px dashed var(--rpx-gold-line);
  color: var(--rpx-green);
  font-size: 11px;
  font-weight: 800;
  text-align: right;
}

#rp-floating-attachment .rp-attachment-item > button {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(23, 76, 57, 0.08);
  color: var(--rpx-green);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.15s;
}

#rp-floating-attachment .rp-attachment-item > button:hover:not(:disabled) {
  background: rgba(190, 50, 50, 0.16);
  color: #8e1f1f;
  transform: rotate(90deg);
}

/* Label jenis file (PDF, DOCX, ...) berbentuk kertas terlipat */
#rp-floating-attachment .rp-attachment-document,
.rp-file-badge {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  background: var(--rpx-green);
  color: var(--rpx-gold);
  font-style: normal;
  font-weight: 800;
  letter-spacing: 0.04em;
  clip-path: polygon(0 0, 68% 0, 100% 28%, 100% 100%, 0 100%);
}

#rp-floating-attachment .rp-attachment-document {
  width: 42px;
  height: 50px;
  border-radius: 6px;
  font-size: 10px;
}

/* Meter penyimpanan akun */
.rp-usage {
  margin: 10px 2px 0;
  color: var(--rpx-muted);
  font-size: 11px;
  text-align: right;
}

.rp-usage.warn {
  color: #8e1f1f;
  font-weight: 800;
}

/* Lampiran di dalam percakapan */
.rp-chat-attachments {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 10px 0 4px;
}

.rp-floating-message .rp-chat-attachment {
  margin: 0;
}

.rp-chat-thread-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0 0 2px;
  padding: 5px 11px;
  border: 1px solid var(--rpx-leaf-line);
  border-radius: 999px;
  background: var(--rpx-leaf);
  color: var(--rpx-green);
  font: inherit;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s;
}

.rp-chat-thread-btn::before {
  content: '';
  width: 12px;
  height: 12px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23174c39' stroke-width='2.2'%3E%3Cpath d='M5 5h14a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1h-8l-4 3v-3H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z'/%3E%3C/svg%3E")
    center / contain no-repeat;
}

.rp-chat-thread-btn:hover {
  border-color: var(--rpx-gold);
  background: var(--rpx-gold-soft);
}

.rp-chat-photo-link {
  display: block;
  overflow: hidden;
  padding: 6px;
  border-radius: 10px;
  background: #fff;
  line-height: 0;
  box-shadow:
    0 1px 0 rgba(23, 76, 57, 0.08),
    0 6px 14px rgba(23, 76, 57, 0.16);
  transform: rotate(-0.8deg);
  transition: transform 0.25s var(--rpx-ease);
}

.rp-chat-photo-link:hover {
  transform: rotate(0deg) scale(1.01);
}

.rp-chat-photo {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 180px;
  max-height: 180px;
  border-radius: 6px;
  background: var(--rpx-leaf);
  object-fit: contain;
}

.rp-chat-file-link {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--rpx-leaf-line);
  border-radius: 14px;
  background: #fff;
  color: var(--rpx-green) !important;
  font-size: 12px;
  text-decoration: none;
  box-shadow: 0 2px 0 rgba(23, 76, 57, 0.06);
  transition:
    transform 0.18s var(--rpx-ease),
    border-color 0.18s,
    box-shadow 0.18s;
}

.rp-chat-file-link:hover {
  transform: translateY(-1px);
  border-color: var(--rpx-gold);
  box-shadow: 0 4px 0 rgba(255, 206, 12, 0.55);
}

.rp-chat-file-link .rp-file-badge {
  width: 38px;
  height: 46px;
  border-radius: 6px;
  font-size: 9px;
}

.rp-chat-file-link > span:not(.rp-file-arrow) {
  flex: 1;
  min-width: 0;
}

.rp-chat-file-link strong {
  display: block;
  margin: 0 !important;
  color: var(--rpx-green) !important;
  font-size: 12.5px !important;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.rp-chat-file-link small {
  display: block;
  margin-top: 3px !important;
  color: var(--rpx-muted) !important;
  font-size: 11px !important;
}

.rp-chat-file-link .rp-file-arrow {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--rpx-leaf);
  color: var(--rpx-green);
  font-size: 15px;
  font-weight: 800;
  transition:
    background 0.18s,
    transform 0.18s var(--rpx-ease);
}

.rp-chat-file-link:hover .rp-file-arrow {
  background: var(--rpx-gold);
  transform: translateY(2px);
}

/* ==========================================================================
   4. Fokus, gerak, dan layar kecil
   ========================================================================== */

.rp-chat-send-actions button:focus-visible,
#rp-floating-attachment .rp-attachment-item > button:focus-visible,
.rp-chat-thread-btn:focus-visible,
.rp-chat-file-link:focus-visible,
.rp-chat-photo-link:focus-visible,
#rp-chat-launcher:focus-visible {
  outline: 3px solid var(--rpx-gold);
  outline-offset: 2px;
}

@keyframes rpx-pop {
  from {
    opacity: 0;
    transform: translateY(6px) rotate(-0.6deg) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(-0.6deg) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  body .rp-class-footer button[data-open-session],
  body .rp-session-originals .area-body > a[href],
  body .session-area .area-body > a[href],
  body .session-block.archived > a[href],
  .rp-chat-send-actions button,
  .rp-chat-send-actions svg,
  #rp-floating-attachment,
  #rp-floating-attachment .rp-attachment-item > button,
  .rp-chat-photo-link,
  .rp-chat-file-link,
  .rp-file-arrow,
  #rp-chat-launcher {
    animation: none !important;
    transition: none !important;
  }

  body .rp-class-footer button[data-open-session]:hover,
  .rp-chat-file-link:hover,
  #rp-chat-launcher:hover {
    transform: none;
  }
}

@media (max-width: 650px) {
  body .rp-class-footer button[data-open-session],
  body .session-area .area-body > a[href] {
    width: auto;
    max-width: 100%;
    min-height: 46px !important;
    padding: 12px 18px !important;
    font-size: 13px !important;
  }

  .rp-chat-send-actions {
    gap: 7px;
  }

  .rp-chat-send-actions #rp-floating-attach {
    padding: 10px 11px;
    font-size: 11px;
  }

  .rp-chat-send-actions #rp-floating-send {
    font-size: 12px;
  }

  .rp-chat-photo {
    height: 160px;
    max-height: 160px;
  }
}
