/* styles.css
 * Created by Daryl Watkins
 * Date: 5/10/2023 
 * Time: 1622 
 */

/* Global settings */
* {
  box-sizing: border-box;
}

body {
  font-family: 'Roboto', 'Lato', sans-serif;
  margin: 0;
  padding: 0;
  background-image: url('/static/images/aicoffee3.jpg');
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  color: #333;
  font-size: 16px; /* Base font size for readability */
  line-height: 1.5;
  padding-left: 20px;
  padding-right: 20px;
  min-height: 100vh;
}

/* Container settings */
.container {
  display: flex;
  flex-direction: column;
  min-height: 75vh;
  align-items: flex-start;
  background-color: rgba(255, 255, 255, 0.8); /* Semi-transparent background to make the text readable */
  padding: 1rem;
}

/* Header settings */
header {
  background-color: #2a3d51;
  color: #fff;
  padding: 1rem;
}

header h1 {
  margin: 0;
  font-size: 1.0em; /* Reduced font size */
}

/* Navigation and link settings */
nav a#help-link {
  background-color: #4b4b4b;
  border: none;
  color: #fff;
  cursor: pointer;
  display: inline-block;
  font-size: .6rem; /* Reduced font size */
  margin: 0 0.5rem;
  padding: 0.5rem 1rem;
  text-decoration: none;
  transition: opacity 0.3s, background-color 0.3s;
  border-radius: 5px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
}

/* Main content settings */
main {
  padding: 1.2rem;
  font-size: .9rem; /* Reduced font size */
}

/* Chatbox settings */
.chatbox {
  display: flex;
  flex-direction: column;
  height: 80vh;
  background-color: rgba(255, 255, 255, 0.8); /* Semi-transparent background to make the text readable */
}

/* Chat container */
.chat-container {
  width: 100%;
}

/* Messages container settings */
#messages {
  border: 1px solid #dbdbdb;
  min-height: 300px;
  max-height: 50vh;
  margin-bottom: 1rem;
  overflow-y: auto;
  padding: 1rem;
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: 8px;
}

/* Message settings */
.message {
  margin-bottom: 1rem;
  font-size: .9rem; /* Reduced font size */
  padding: 0.75rem;
  border-radius: 10px;
  max-width: 85%;
  word-wrap: break-word;
  white-space: pre-wrap;
}

/* User message settings */
.user-message {
  align-self: flex-start;
  background-color: #e3f2fd;
  border-radius: 10px;
  margin-left: auto;
  text-align: right;
}

/* AI message settings */
.ai-message {
  align-self: flex-end;
  background-color: #4b4b4b;
  border-radius: 10px;
  color: #fff;
  margin-right: auto;
}

/* Loading indicator */
.loading {
  animation: pulse 1.5s ease-in-out infinite;
  opacity: 0.7;
  font-style: italic;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* Message form settings */
#message-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

/* User input settings */
#user-input {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 8px;
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
}

#user-input:focus {
  outline: none;
  border-color: #0077cc;
  box-shadow: 0 0 0 2px rgba(0, 119, 204, 0.2);
}

/* Input buttons container */
.input-buttons {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.input-buttons button {
  padding: 0.5rem 1.5rem;
  font-size: 0.9rem;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.2s ease;
}

#send-btn {
  background-color: #0077cc;
  color: white;
}

#send-btn:hover {
  background-color: #005fa3;
}

#reset-btn {
  background-color: #6c757d;
  color: white;
}

#reset-btn:hover {
  background-color: #545b62;
}

/* Microphone button */
.mic-btn {
  background-color: #28a745;
  color: white;
  font-size: 1.3rem;
  padding: 0 !important;
  border-radius: 50% !important;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid #28a745;
  box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
  transition: all 0.2s ease;
}

.mic-btn:hover {
  background-color: #218838;
  border-color: #218838;
  transform: scale(1.05);
}

.mic-btn.recording {
  background-color: #dc3545;
  border-color: #dc3545;
  box-shadow: 0 2px 12px rgba(220, 53, 69, 0.5);
  animation: pulse-recording 0.8s infinite;
}

.mic-btn.recording:hover {
  background-color: #c82333;
  border-color: #c82333;
}

@keyframes pulse-recording {
  0%, 100% { transform: scale(1); box-shadow: 0 2px 12px rgba(220, 53, 69, 0.5); }
  50% { transform: scale(1.08); box-shadow: 0 2px 20px rgba(220, 53, 69, 0.7); }
}

/* Options row */
.options {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.option label {
  font-size: 0.85rem;
  font-weight: 500;
}

.option input[type="number"] {
  width: 70px;
  padding: 0.25rem 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.85rem;
}

/* Conversation Status Indicator */
.conversation-status {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: 25px;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.75rem;
  transition: all 0.3s ease;
}

.conversation-status.listening {
  background: linear-gradient(135deg, #4CAF50, #45a049);
  color: white;
  animation: pulse-status 1.5s infinite;
}

.conversation-status.processing {
  background: linear-gradient(135deg, #2196F3, #1976D2);
  color: white;
  animation: pulse-status 1s infinite;
}

.conversation-status.speaking {
  background: linear-gradient(135deg, #FF9800, #F57C00);
  color: white;
  cursor: pointer;
}

.conversation-status.speaking:hover {
  background: linear-gradient(135deg, #F57C00, #E65100);
  transform: scale(1.02);
}

@keyframes pulse-status {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.85; transform: scale(0.98); }
}

/* Audio Settings */
.audio-settings {
  background-color: rgba(240, 240, 240, 0.9);
  border-radius: 8px;
  padding: 1rem;
  margin-top: 0.5rem;
}

.audio-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.audio-toggle label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}

.audio-main-toggle {
  background-color: #e8f4e8;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 2px solid #28a745;
  transition: all 0.2s;
}

.audio-main-toggle:hover {
  background-color: #d4edda;
}

.audio-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.auto-listen-label {
  opacity: 0.7;
  transition: opacity 0.2s;
}

.auto-listen-label:hover {
  opacity: 1;
}

/* Pause Duration Control */
.pause-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid #ddd;
  margin-bottom: 0.75rem;
}

.pause-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: #555;
}

.pause-buttons {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.pause-btn {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  border: 2px solid #ddd;
  border-radius: 20px;
  background-color: #fff;
  color: #666;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.pause-btn:hover {
  border-color: #0077cc;
  color: #0077cc;
}

.pause-btn.active {
  background-color: #0077cc;
  border-color: #0077cc;
  color: white;
}

.audio-controls {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #ddd;
}

.audio-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.audio-option label {
  min-width: 60px;
  font-size: 0.85rem;
  font-weight: 500;
}

.audio-option select {
  flex: 1;
  padding: 0.4rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.85rem;
  max-width: 300px;
}

.audio-option input[type="range"] {
  flex: 1;
  max-width: 150px;
  cursor: pointer;
}

.audio-option span {
  min-width: 45px;
  font-size: 0.8rem;
  color: #666;
}

/* Page options */
.page-options {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.page-options button {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  background-color: #6c757d;
  color: white;
  transition: background-color 0.2s;
}

.page-options button:hover {
  background-color: #545b62;
}

/* Print media settings */
@media print {
  /* Hide UI elements */
  button, .audio-settings, .options, .page-options, #message-form, 
  .conversation-status, .input-buttons, .mic-btn, #user-input,
  .audio-toggle, .audio-controls, h1 {
    display: none !important;
  }
  
  /* Reset body for print */
  body {
    background-image: none !important;
    background-color: white !important;
    padding: 0 !important;
    font-size: 12pt;
  }
  
  .container {
    background-color: white;
    height: auto;
    min-height: auto;
    padding: 0;
  }
  
  /* Messages container */
  #messages {
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    border: none;
    padding: 0;
    background: white;
  }
  
  /* Message styling for print */
  .message {
    page-break-inside: avoid;
    margin-bottom: 1rem;
    padding: 0.75rem;
    border-radius: 0;
    max-width: 100%;
    font-size: 11pt;
    line-height: 1.5;
  }
  
  .user-message {
    background-color: #f0f0f0 !important;
    border-left: 4px solid #0077cc;
    color: black;
  }
  
  .user-message::before {
    content: "You: ";
    font-weight: bold;
    color: #0077cc;
  }
  
  .ai-message {
    background-color: #fff !important;
    border-left: 4px solid #28a745;
    color: black !important;
  }
  
  .ai-message::before {
    content: "Coach: ";
    font-weight: bold;
    color: #28a745;
  }
  
  /* Print header - injected via JS */
  .print-header {
    display: block !important;
    text-align: center;
    padding: 1rem 0 2rem 0;
    border-bottom: 2px solid #333;
    margin-bottom: 1.5rem;
  }
  
  .print-header h1 {
    display: block !important;
    font-size: 18pt;
    margin: 0 0 0.5rem 0;
    color: #333;
  }
  
  .print-header .print-date {
    font-size: 10pt;
    color: #666;
  }
}

/* ============================================
   RESPONSIVE & MOBILE OPTIMIZATION
   ============================================ */

/* Tablet breakpoint */
@media (max-width: 768px) {
  body {
    padding-left: 10px;
    padding-right: 10px;
  }
  
  .container {
    padding: 0.75rem;
  }
  
  #messages {
    min-height: 250px;
    max-height: 45vh;
  }
  
  .message {
    max-width: 90%;
    font-size: 0.95rem;
  }
  
  .page-options {
    flex-wrap: wrap;
  }
  
  .page-options button {
    flex: 1;
    min-width: 100px;
  }
}

/* Mobile breakpoint */
@media (max-width: 600px) {
  body {
    font-size: 14px; /* Increase base font for readability */
    padding: 0;
  }
  
  .container {
    min-height: 100vh;
    padding: 0.5rem;
    border-radius: 0;
  }
  
  h1 {
    font-size: 1.5rem;
    text-align: center;
    margin-bottom: 0.5rem;
  }
  
  /* Messages area - more height on mobile */
  #messages {
    min-height: 200px;
    max-height: 40vh;
    padding: 0.75rem;
    font-size: 1rem;
  }
  
  .message {
    max-width: 95%;
    padding: 0.6rem;
    font-size: 1rem;
    line-height: 1.4;
  }
  
  /* Larger textarea for easier typing */
  #user-input {
    font-size: 16px; /* Prevents iOS zoom on focus */
    min-height: 50px;
    padding: 0.6rem;
  }
  
  /* Stack buttons and make touch-friendly */
  .input-buttons {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  
  .input-buttons button {
    padding: 0.75rem 1rem;
    font-size: 1rem;
    min-height: 44px; /* iOS touch target minimum */
  }
  
  #send-btn {
    flex: 1;
    order: 1;
  }
  
  .mic-btn {
    width: 54px;
    height: 54px;
    font-size: 1.5rem;
    order: 2;
    border-width: 4px;
  }
  
  #reset-btn {
    order: 3;
  }
  
  /* Options stacked vertically */
  .options {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .option {
    width: 100%;
    justify-content: space-between;
  }
  
  .option input[type="number"] {
    width: 80px;
    padding: 0.4rem;
    font-size: 1rem;
    min-height: 44px;
  }
  
  /* Audio settings optimized for mobile */
  .audio-settings {
    padding: 0.75rem;
  }
  
  .audio-toggle {
    flex-direction: column;
    gap: 0.75rem;
  }
  
  .audio-toggle label {
    font-size: 1rem;
    padding: 0.5rem 0;
  }
  
  .audio-toggle input[type="checkbox"] {
    width: 22px;
    height: 22px;
  }
  
  .audio-controls {
    gap: 1rem;
  }
  
  .pause-control {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .pause-buttons {
    width: 100%;
    justify-content: space-between;
  }
  
  .pause-btn {
    flex: 1;
    padding: 0.5rem 0.4rem;
    font-size: 0.75rem;
    min-height: 38px;
  }
  
  .audio-option {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  
  .audio-option label {
    width: 100%;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
  }
  
  .audio-option select {
    width: 100%;
    max-width: none;
    padding: 0.6rem;
    font-size: 1rem;
    min-height: 44px;
  }
  
  .audio-option input[type="range"] {
    flex: 1;
    max-width: none;
    height: 30px;
  }
  
  .audio-option span {
    min-width: 50px;
    font-size: 0.9rem;
  }
  
  /* Status indicator */
  .conversation-status {
    font-size: 0.85rem;
    padding: 0.6rem 0.75rem;
  }
  
  /* Page options as full-width buttons */
  .page-options {
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
  }
  
  .page-options button {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    min-height: 48px;
  }
}

/* Small mobile (iPhone SE, etc.) */
@media (max-width: 375px) {
  .container {
    padding: 0.4rem;
  }
  
  h1 {
    font-size: 1.3rem;
  }
  
  #messages {
    max-height: 35vh;
  }
  
  .message {
    font-size: 0.95rem;
    padding: 0.5rem;
  }
  
  .mic-btn {
    width: 44px;
    height: 44px;
    font-size: 1.2rem;
  }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
  .container {
    min-height: auto;
  }
  
  #messages {
    min-height: 120px;
    max-height: 30vh;
  }
  
  .audio-settings {
    display: none; /* Hide on landscape to save space, or make collapsible */
  }
  
  .page-options {
    flex-direction: row;
    flex-wrap: wrap;
  }
  
  .page-options button {
    flex: 1;
    min-width: auto;
  }
}

/* Safe area for notched phones (iPhone X+) */
@supports (padding-top: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* High contrast / accessibility */
@media (prefers-contrast: high) {
  .message {
    border: 2px solid;
  }
  
  .user-message {
    border-color: #0077cc;
  }
  
  .ai-message {
    border-color: #333;
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
