/* ========================================
   MOBILE.CSS - Mobile-First Progressive Web App
   ======================================== */

/* GLOBAL RESET & PWA ENHANCEMENTS */
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

/* MOBILE BASE (<1024px) */
@media only screen and (max-width: 1023px) {

  body {
    margin: 0;
    margin-top: 1vh;
    margin-bottom: 1vh;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    overflow-x: hidden;
    min-height: 100vh;
    background-attachment: fixed;
  }

  .container {
    width: 100vw;
    max-width: 100vw;
    min-width: 400px;
    padding: 0;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
  }

  /* TOP BAR */
  .top-bar {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: rgba(34,34,34,0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 12px 16px;
    padding-top: 0px;
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
  }

  body.light .top-bar {
    background: rgba(255,255,255,0.98);
  }

  .top-bar h2 {
    font-size: 1.4rem;
    margin: 0;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .top-bar h2 span:first-child { font-size: 1.3rem; }

  /* TOP BAR BUTTONS */
  .top-bar-buttons {
    display: flex;
    gap: 6px;
    margin-left: auto;
    flex-shrink: 0;
  }

  #registerBtn, #loginBtn, #logoutBtn, #changePasswordBtn, #promptBtn, #configBtn, #profileBtn, #darkModeBtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    min-width: 40px;
    font-size: 16px;
    gap: 0;
  }

  #registerBtn .btn-text,
  #loginBtn .btn-text,
  #logoutBtn .btn-text,
  #changePasswordBtn .btn-text,
  #promptBtn .btn-text,
  #configBtn .btn-text,
  #profileBtn .btn-text,
  #darkModeBtn .btn-text { display: none; }

  /* AI CONTAINER */
  .ai-container, .ai-prompt-container {
    margin: 0;
    padding: 16px;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.03);
    gap: 12px;
  }

  body.light .ai-container, body.light .ai-prompt-container {
    background: rgba(0,0,0,0.02);
    border-bottom: 1px solid rgba(0,0,0,0.1);
  }

  /* ROW & SELECT GROUP */
  .row {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 0;
  }

  .select-group {
    width: 100%;
    padding: 14px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
  }

  body.light .select-group {
    background: rgba(0,0,0,0.03);
    border: 1px solid rgba(0,0,0,0.1);
  }

  .select-group label { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
  .select-group input, .select-group select { margin-bottom: 0; }

  /* RANGE & NUMBER INPUT */
  input[type="range"], input[type="number"] {
    width: 100%;
    font-size: 16px;
    padding: 12px 16px;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.08);
    transition: all 0.2s ease;
  }

  body.light input[type="range"], body.light input[type="number"] {
    border: 1px solid rgba(0,0,0,0.15);
    background: rgba(0,0,0,0.04);
  }

  input[type="range"] { cursor: pointer; height: 44px; -webkit-appearance: none; }
  input[type="range"]::-webkit-slider-track {
    height: 6px; background: rgba(255,255,255,0.2);
  }
  body.light input[type="range"]::-webkit-slider-track { background: rgba(0,0,0,0.2); }
  input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 24px; height: 24px; border-radius: 50%;
    background: #007bff; box-shadow: 0 2px 6px rgba(0,0,0,0.3); cursor: pointer; border: none;
  }
  input[type="number"] { margin-top: 8px; color: white; }

  .light input[type="number"] { margin-top: 8px; color: black; }

  /* ANSWER BOX */
  #answerBox {
    margin: 16px 0; padding: 16px;
    min-height: 120px; max-height: 40vh; font-size: 15px; line-height: 1.6;
    overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
    background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.2);
  }
  body.light #answerBox { background: rgba(0,0,0,0.03); border: 1px solid rgba(0,0,0,0.1); box-shadow: inset 0 2px 8px rgba(0,0,0,0.05); }

  /* QUESTION BOX */
  #questionBox, #systemPrompt {
    resize: none; -webkit-overflow-scrolling: touch;
    background: rgba(255,255,255,0.08); border: 2px solid rgba(0,123,255,0.3);
    transition: all 0.3s ease;
  }
  body.light #questionBox, body.light #systemPrompt { background: rgba(0,0,0,0.04); }
  #questionBox:focus #systemPrompt:focus { border-color: #007bff; box-shadow: 0 0 0 4px rgba(0,123,255,0.15); background: rgba(255,255,255,0.12); }
  body.light #questionBox:focus, body.light #systemPrompt:focus { background: rgba(0,0,0,0.06); }

  /* BOTTOM ACTIONS */
  .bottom-actions {
    display: grid; grid-template-columns: repeat(2,1fr); gap:10px; margin:16px 0;
  }
  .bottom-actions button {
    min-height: 56px; padding: 10px 8px; font-size: 13px;
    display: flex; flex-direction: column; align-items:center;
    justify-content: center; gap: 6px; border: 1px solid rgba(255,255,255,0.1); box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  }
  body.light .bottom-actions button { border:1px solid rgba(0,0,0,0.1); box-shadow:0 2px 8px rgba(0,0,0,0.1); }
  .bottom-actions button:active { transform: scale(0.96); }
  .bottom-actions .btn-icon { font-size:24px; }
  .bottom-actions .btn-text { font-size:11px; text-align:center; }

  /* SUBMIT BUTTON */
  #submitButton { grid-column: span 2; min-height: 60px; flex-direction: row; gap:10px; font-size:16px; font-weight:700; box-shadow:0 4px 12px rgba(40,167,69,0.4); }
  #submitButton .btn-icon { font-size:26px; }
  #submitButton .btn-text { font-size:16px; }

  /* HISTORY BOXES */
  #historyBox, #aiLogBox { max-height:50vh; padding:8px 0; overflow-y:auto; overflow-x:hidden; margin-bottom:16px; }
}

/* TABLET (768px - 1023px) */
@media only screen and (min-width:768px) and (max-width:1023px) {
  .row { flex-direction: row; flex-wrap: wrap; gap:12px; width: 100%; }
  .select-group { flex:1 1 calc(50% - 12px); }
  .bottom-actions { grid-template-columns: repeat(4,1fr); }
  #submitButton { grid-column: span 1; }
}
