/*
 * HAIRA AI Studio Layout Fix V5
 * Memperbaiki jarak, toolbar, tampilan awal,
 * tombol KEY, dan kestabilan layout mobile.
 */

:root {
  --haira-studio-width: 960px;
  --haira-page-gap: clamp(14px, 3.5vw, 24px);
  --haira-blue: #079cff;
  --haira-yellow: #ffd400;
}

/* ================================
   KUNCI VIEWPORT DAN PERGESERAN
================================ */

html,
body.studio-body {
  width: 100%;
  max-width: 100%;
  margin: 0;
  overflow: hidden !important;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html {
  touch-action: pan-y;
}

body.studio-body {
  position: fixed;
  inset: 0;
  min-height: 0;
  background: #000;
  touch-action: pan-y;
}

.studio-body,
.studio-body * {
  box-sizing: border-box;
}

.studio-body img,
.studio-body svg,
.studio-body canvas,
.studio-body video {
  max-width: 100%;
}

.studio-body input,
.studio-body textarea,
.studio-body select,
.studio-body button {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

/* ================================
   HEADER
================================ */

.studio-header {
  width: 100%;
  max-width: 100%;
  padding-left:
    max(var(--haira-page-gap), env(safe-area-inset-left));

  padding-right:
    max(var(--haira-page-gap), env(safe-area-inset-right));
}

.studio-header .brand {
  min-width: 0;
  flex-shrink: 1;
}

.studio-header .brand-name {
  white-space: nowrap;
}

.studio-header-actions {
  margin-left: auto;
  flex-shrink: 0;
}

.studio-header-actions button {
  white-space: nowrap;
}

/* ================================
   STRUKTUR UTAMA
================================ */

.studio-shell {
  width: min(100%, var(--haira-studio-width));
  max-width: 100%;
  margin: 0 auto;

  padding-left:
    max(var(--haira-page-gap), env(safe-area-inset-left));

  padding-right:
    max(var(--haira-page-gap), env(safe-area-inset-right));

  overflow: hidden !important;
}

/* ================================
   TOOLBAR MODEL + KEY
================================ */

.studio-toolbar {
  display: grid !important;
  grid-template-columns:
    minmax(0, 1fr)
    88px;

  align-items: end;
  width: 100%;
  max-width: 100%;
  gap: 13px;

  padding-top: 8px;
  padding-bottom: 20px;
}

.studio-toolbar label {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  gap: 9px;
}

.studio-toolbar label > span {
  display: block;
  padding-left: 2px;

  color: #929aa7;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.studio-toolbar select {
  display: block;
  width: 100%;
  min-width: 0;
  height: 56px;

  padding:
    0
    48px
    0
    18px;

  border:
    1px solid rgba(7, 156, 255, 0.36);

  border-radius: 17px;

  color: #f5f7fa;
  background-color: rgba(5, 8, 12, 0.98);

  font-weight: 700;

  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 14px 36px rgba(0, 0, 0, 0.26);
}

.settings-button {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex-direction: row !important;

  width: 88px !important;
  min-width: 88px !important;
  max-width: 88px !important;
  height: 56px !important;
  min-height: 56px !important;

  margin: 0 !important;
  padding: 0 11px !important;
  gap: 8px !important;

  overflow: hidden;
  white-space: nowrap !important;
  word-break: normal !important;

  border:
    1px solid rgba(255, 255, 255, 0.11);

  border-radius: 17px !important;

  color: #f8f9fa;

  background:
    linear-gradient(
      180deg,
      rgba(12, 16, 21, 0.98),
      rgba(5, 8, 12, 0.98)
    );

  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 14px 36px rgba(0, 0, 0, 0.24);
}

.settings-button::before,
.settings-button::after {
  content: none !important;
  display: none !important;
}

.settings-button .settings-dot {
  display: block !important;
  width: 8px !important;
  height: 8px !important;
  min-width: 8px !important;
  flex: 0 0 8px !important;

  border-radius: 50%;
  background: var(--haira-yellow);

  box-shadow:
    0 0 12px rgba(255, 212, 0, 0.72);
}

.settings-button .key-label {
  display: block;
  flex: 0 0 auto;

  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

/* ================================
   AREA CHAT
================================ */

.chat-panel {
  width: 100%;
  max-width: 100%;
  min-width: 0;

  padding:
    0
    2px
    20px;

  overflow-y: auto;
  overflow-x: hidden !important;

  overscroll-behavior-x: none;
  overscroll-behavior-y: contain;

  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

/* ================================
   TAMPILAN AWAL
================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;

  width: min(100%, 760px);
  max-width: 100%;
  min-height: auto;

  margin: 0 auto;

  padding:
    clamp(68px, 8vh, 104px)
    0
    42px;
}

.studio-core-wrap {
  margin:
    0
    auto
    24px;

  transform: scale(0.94);
  transform-origin: center;
}

.assistant-label {
  margin:
    0
    auto
    21px;

  color: var(--haira-yellow);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.empty-state h1 {
  width: min(100%, 670px);

  margin:
    0
    auto
    22px;

  color: #f5f6f8;

  font-size:
    clamp(39px, 8vw, 58px);

  font-weight: 800;
  line-height: 1.04;
  letter-spacing: -0.055em;

  text-align: center;
  text-wrap: balance;
}

.empty-state > p {
  width: min(100%, 585px);

  margin:
    0
    auto
    36px;

  color: #939ba7;

  font-size: 15px;
  line-height: 1.72;

  text-align: center;
  text-wrap: pretty;
}

.prompt-grid {
  display: grid;
  grid-template-columns:
    repeat(2, minmax(0, 1fr));

  width: min(100%, 620px);
  max-width: 100%;

  margin: 0 auto;
  gap: 13px;
}

.prompt-grid button {
  width: 100%;
  min-width: 0;
  min-height: 68px;

  padding: 13px 15px;

  border-radius: 18px;

  overflow: hidden;
  text-align: left;
  white-space: normal;

  background:
    linear-gradient(
      140deg,
      rgba(7, 156, 255, 0.05),
      rgba(255, 212, 0, 0.025)
    ),
    rgba(6, 9, 13, 0.94);

  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 14px 36px rgba(0, 0, 0, 0.22);
}

/* ================================
   PESAN
================================ */

.messages {
  width: min(100%, 850px);
  max-width: 100%;

  margin: 0 auto;
  padding:
    17px
    0
    10px;

  gap: 19px;
}

.message {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.message-content {
  width: 100%;
  max-width: 100%;
  min-width: 0;

  overflow: hidden;
  border-radius: 19px;
}

.message-content,
.markdown-body,
.markdown-body p,
.markdown-body li {
  overflow-wrap: anywhere;
}

/* ================================
   COMPOSER
================================ */

.composer {
  width: min(100%, 880px);
  max-width: 100%;

  margin:
    12px
    auto
    0;

  border-radius: 21px;
  overflow: hidden;
}

.composer textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;

  font-size: 16px !important;
  touch-action: pan-y;
}

/* ================================
   MOBILE
================================ */

@media (max-width: 640px) {
  :root {
    --haira-page-gap: 15px;
  }

  .studio-toolbar {
    grid-template-columns:
      minmax(0, 1fr)
      82px;

    gap: 11px;
    padding-top: 7px;
    padding-bottom: 18px;
  }

  .studio-toolbar select {
    height: 54px;
    padding-left: 16px;
    border-radius: 16px;
  }

  .settings-button {
    width: 82px !important;
    min-width: 82px !important;
    max-width: 82px !important;

    height: 54px !important;
    min-height: 54px !important;

    border-radius: 16px !important;
  }

  .empty-state {
    padding:
      clamp(58px, 7.3vh, 84px)
      0
      32px;
  }

  .studio-core-wrap {
    margin-bottom: 20px;
    transform: scale(0.9);
  }

  .assistant-label {
    margin-bottom: 18px;
  }

  .empty-state h1 {
    max-width: 570px;

    margin-bottom: 20px;

    font-size:
      clamp(37px, 10vw, 47px);

    line-height: 1.05;
  }

  .empty-state > p {
    max-width: 540px;

    margin-bottom: 32px;

    font-size: 14px;
    line-height: 1.68;
  }

  .prompt-grid {
    gap: 11px;
  }

  .prompt-grid button {
    min-height: 66px;
    border-radius: 17px;
  }

  .messages {
    padding-top: 12px;
  }
}

/* HP berukuran kecil */

@media (max-width: 390px) {
  :root {
    --haira-page-gap: 12px;
  }

  .studio-toolbar {
    grid-template-columns:
      minmax(0, 1fr)
      74px;

    gap: 9px;
  }

  .settings-button {
    width: 74px !important;
    min-width: 74px !important;
    max-width: 74px !important;
  }

  .settings-button .key-label {
    font-size: 11px;
  }

  .empty-state h1 {
    font-size:
      clamp(34px, 10.8vw, 43px);
  }

  .prompt-grid {
    grid-template-columns: 1fr;
  }
}

/* Layar pendek karena keyboard atau landscape */

@media (max-height: 760px) {
  .empty-state {
    padding-top: 33px;
  }

  .studio-core-wrap {
    transform: scale(0.82);
    margin-bottom: 13px;
  }

  .assistant-label {
    margin-bottom: 13px;
  }

  .empty-state h1 {
    margin-bottom: 15px;
    font-size: clamp(33px, 8vw, 44px);
  }

  .empty-state > p {
    margin-bottom: 21px;
  }
}
