:root {
  --bg-dark: #0a0e1a;
  --bg-card: #0f1629;
  --bg-card-hover: #141c33;
  --border: rgba(45, 212, 191, 0.15);
  --border-light: rgba(255, 255, 255, 0.06);
  --text: #e2e8f0;
  --text-muted: #64748b;
  --accent-teal: #2dd4bf;
  --accent-purple: #a855f7;
  --accent-blue: #3b82f6;
  --gradient-primary: linear-gradient(135deg, #2dd4bf 0%, #3b82f6 50%, #a855f7 100%);
  --gradient-button: linear-gradient(135deg, #2dd4bf 0%, #22d3ee 100%);
  --gradient-button-alt: linear-gradient(135deg, #8b5cf6 0%, #a855f7 100%);
  --danger: #ef4444;
  --shadow-glow: 0 0 20px rgba(45, 212, 191, 0.15);
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-dark);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: radial-gradient(ellipse at top, #131b2e 0%, var(--bg-dark) 70%);
}

.abs { position: absolute; }

/* Modern Button Base */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(10px);
}

.btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-teal);
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--gradient-button);
  border: none;
  color: #0a0e1a;
  font-weight: 600;
}

.btn-primary:hover {
  box-shadow: 0 0 24px rgba(45, 212, 191, 0.4);
  transform: translateY(-2px);
}

.btn-accent {
  background: var(--gradient-button-alt);
  border: none;
  color: white;
  font-weight: 600;
}

.btn-accent:hover {
  box-shadow: 0 0 24px rgba(168, 85, 247, 0.4);
}

.btn-danger {
  background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
  border: none;
  color: white;
  font-weight: 600;
}

.btn-danger:hover {
  box-shadow: 0 0 24px rgba(239, 68, 68, 0.4);
}

.btn.call-active {
  background: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
  border: none;
  color: #0a0e1a;
  font-weight: 600;
  animation: pulse-call 1.5s infinite;
}

.btn.call-active:hover {
  box-shadow: 0 0 24px rgba(245, 158, 11, 0.5);
}

@keyframes pulse-call {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.85; }
}

.btn-icon {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
}

.btn-icon svg {
  width: 22px;
  height: 22px;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(10px);
}

/* Header */
#header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: rgba(15, 22, 41, 0.8);
  border-bottom: 1px solid var(--border-light);
  backdrop-filter: blur(20px);
  z-index: 100;
}

.logo {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.15em;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#status {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

#status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-teal);
  animation: pulse 2s infinite;
}

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

/* Control Bar */
#controlBar {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  padding: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
}

#controlBar .btn {
  min-width: 80px;
}

/* Main Layout */
#mainContent {
  position: absolute;
  top: 160px;
  left: 24px;
  right: 24px;
  bottom: 100px;
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 24px;
}

/* Voice Controls Sidebar */
#voiceControls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
}

#voiceControls .btn-icon {
  width: 64px;
  height: 64px;
  background: var(--bg-card);
  border: 2px solid var(--border);
}

#voiceControls .btn-icon:hover {
  border-color: var(--accent-teal);
}

#voiceControls .btn-icon.active {
  border-color: var(--accent-teal);
  box-shadow: 0 0 20px rgba(45, 212, 191, 0.3);
}

/* Chat Panel */
#panelLog {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#panelLog.drag-over {
  border-color: var(--accent-teal);
  box-shadow: 0 0 20px rgba(45, 212, 191, 0.3), inset 0 0 30px rgba(45, 212, 191, 0.05);
}

#log {
  flex: 1;
  overflow-y: auto;
  font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.6;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.log-line {
  color: var(--accent-teal);
  white-space: pre-wrap;
  padding: 2px 0;
}

.log-line.user-msg {
  color: #f97316;
}

.log-line.irish-msg {
  color: #22d3ee;
}

#log::-webkit-scrollbar {
  width: 6px;
}

#log::-webkit-scrollbar-track {
  background: transparent;
}

#log::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Input Area */
#inputArea {
  position: absolute;
  bottom: 20px;
  left: 24px;
  right: 24px;
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
}

#textInput {
  flex: 1;
  padding: 14px 20px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: all 0.2s ease;
}

#textInput:focus {
  border-color: var(--accent-teal);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.1);
}

#textInput::placeholder {
  color: var(--text-muted);
}

/* Dropdown Menu - Compact Scrollable */
.dropdown {
  position: fixed;
  display: none;
  min-width: 180px;
  max-width: 220px;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  box-shadow: var(--shadow-card), 0 0 40px rgba(0, 0, 0, 0.4);
  z-index: 10000;
  backdrop-filter: blur(20px);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.dropdown::-webkit-scrollbar {
  width: 4px;
}

.dropdown::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.dropdown.open { display: block; }

.dd-group {
  padding: 2px 0;
  border-bottom: 1px solid var(--border-light);
}

.dd-group:last-child { border-bottom: none; }

.dd-title {
  padding: 4px 8px;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-teal);
  opacity: 0.8;
}

.dd-item {
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 12px;
}

.dd-item:hover {
  background: rgba(45, 212, 191, 0.1);
}

.dd-item.danger {
  color: var(--danger);
}

.dd-item.danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* Toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: 120px;
  transform: translateX(-50%);
  padding: 14px 24px;
  background: var(--bg-card);
  border: 1px solid var(--accent-teal);
  border-radius: 12px;
  color: var(--text);
  font-weight: 500;
  box-shadow: var(--shadow-glow), var(--shadow-card);
  display: none;
  z-index: 10001;
}

#toast.show {
  display: block;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2s forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
  to { opacity: 0; }
}

/* Grid Overlay */
#grid {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 9999;
  background:
    linear-gradient(to right, rgba(45, 212, 191, 0.2) 1px, transparent 1px),
    linear-gradient(to top, rgba(45, 212, 191, 0.2) 1px, transparent 1px);
  background-size: 10% 10%;
  display: none;
}

#grid.show { display: block; }

.grid-label {
  position: absolute;
  font-size: 10px;
  color: var(--accent-teal);
  font-weight: 600;
  opacity: 0.8;
}

.grid-label.x { top: 2px; transform: translateX(-50%); }
.grid-label.y { left: 4px; }

#elemLabels {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 10000;
  display: none;
}

.elem-tag {
  position: absolute;
  background: var(--accent-purple);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  transform: translate(-100%, 50%);
}

/* Footer */
#footer {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 20px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  font-size: 11px;
  color: var(--text-muted);
}

#footer a {
  color: var(--accent-teal);
  text-decoration: none;
}

#footer a:hover {
  text-decoration: underline;
}

/* Mode Dropdown */
.mode-dropdown {
  min-width: 280px;
}

.mode-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
}

.mode-item.active {
  background: rgba(45, 212, 191, 0.15);
  border-left: 3px solid var(--accent-teal);
}

.mode-icon {
  font-size: 20px;
  width: 32px;
  text-align: center;
}

.mode-info {
  flex: 1;
}

.mode-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.mode-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.custom-mode-input {
  padding: 12px;
  border-top: 1px solid var(--border-light);
}

.custom-mode-input textarea {
  width: 100%;
  min-height: 80px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  outline: none;
}

.custom-mode-input textarea:focus {
  border-color: var(--accent-teal);
}

.custom-mode-input .btn {
  margin-top: 8px;
  width: 100%;
}

#btnMode.mode-active {
  background: var(--gradient-button-alt);
  border: none;
  color: white;
}

.mode-indicator {
  position: absolute;
  top: 80px;
  right: 24px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.mode-indicator .mode-badge {
  color: var(--accent-teal);
  font-weight: 600;
}

/* Call Status Light */
#callLight {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 8px #ef4444, 0 0 12px rgba(239, 68, 68, 0.5);
  transition: all 0.3s ease;
  margin: 0 12px;
}

#callLight.ringing {
  background: #3b82f6;
  box-shadow: 0 0 10px #3b82f6, 0 0 16px rgba(59, 130, 246, 0.6);
  animation: blink-light 0.8s ease-in-out infinite;
}

#callLight.active {
  background: #3b82f6;
  box-shadow: 0 0 10px #3b82f6, 0 0 16px rgba(59, 130, 246, 0.6);
}

@keyframes blink-light {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ========================================
   MOBILE / IPHONE RESPONSIVE STYLES
   ======================================== */

@media (max-width: 768px) {
  html, body {
    font-size: 16px;
  }

  #app {
    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);
  }

  #header {
    height: 56px;
    padding: 0 16px;
    padding-top: env(safe-area-inset-top);
  }

  .logo {
    font-size: 18px;
  }

  #status {
    font-size: 12px;
  }

  #controlBar {
    top: calc(64px + env(safe-area-inset-top));
    left: 8px;
    right: 8px;
    transform: none;
    padding: 6px;
    gap: 6px;
    overflow-x: auto;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
  }

  #controlBar .btn {
    min-width: auto;
    padding: 10px 14px;
    font-size: 13px;
    flex-shrink: 0;
  }

  #mainContent {
    top: calc(120px + env(safe-area-inset-top));
    left: 8px;
    right: 8px;
    bottom: calc(90px + env(safe-area-inset-bottom));
    grid-template-columns: 1fr;
    gap: 12px;
  }

  #voiceControls {
    display: none;
  }

  #panelLog {
    padding: 12px;
    border-radius: 12px;
  }

  #log {
    font-size: 14px;
    line-height: 1.5;
  }

  .log-line {
    padding: 4px 0;
    word-break: break-word;
  }

  #inputArea {
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: 8px;
    right: 8px;
    padding: 8px;
    gap: 8px;
    border-radius: 12px;
  }

  #textInput {
    padding: 12px 16px;
    font-size: 16px;
    border-radius: 10px;
  }

  #inputArea .btn {
    padding: 12px 16px;
    border-radius: 10px;
  }

  #inputArea .btn-icon {
    width: 44px;
    height: 44px;
  }

  .dropdown {
    position: fixed;
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    transform: translate(-50%, -50%);
    width: calc(100vw - 32px);
    max-width: 340px;
    max-height: 80vh;
    overflow-y: auto;
    border-radius: 20px;
  }

  .dd-item {
    padding: 14px 16px;
    font-size: 16px;
  }

  .mode-dropdown {
    min-width: auto;
    width: calc(100vw - 32px);
    max-width: 340px;
  }

  .mode-item {
    padding: 14px 12px;
  }

  .mode-name {
    font-size: 15px;
  }

  .mode-desc {
    font-size: 12px;
  }

  .custom-mode-input textarea {
    min-height: 100px;
    font-size: 16px;
  }

  .mode-indicator {
    top: auto;
    bottom: calc(100px + env(safe-area-inset-bottom));
    right: 16px;
    font-size: 11px;
    padding: 4px 10px;
  }

  #callLight {
    width: 12px;
    height: 12px;
    margin: 0 8px;
  }

  #toast {
    bottom: calc(110px + env(safe-area-inset-bottom));
    left: 16px;
    right: 16px;
    transform: none;
    text-align: center;
    font-size: 14px;
  }

  #toast.show {
    animation: toastInMobile 0.3s ease, toastOut 0.3s ease 2s forwards;
  }

  @keyframes toastInMobile {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
  }

  #footer {
    display: none;
  }
}

@media (max-width: 480px) {
  #controlBar .btn {
    padding: 8px 12px;
    font-size: 12px;
  }

  #log {
    font-size: 13px;
  }

  .dropdown {
    width: calc(100vw - 24px);
    max-height: 70vh;
  }
}

/* Modal Overlay */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 20000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  min-width: 280px;
  max-width: 90vw;
  box-shadow: var(--shadow-card), 0 0 40px rgba(0, 0, 0, 0.5);
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  text-align: center;
}

.modal-filename {
  font-size: 12px;
  color: var(--accent-teal);
  text-align: center;
  margin-bottom: 16px;
  word-break: break-all;
}

.modal-section {
  margin-bottom: 12px;
}

.modal-section label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.modal-section select {
  width: 100%;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-btn {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.modal-btn:hover {
  background: rgba(45, 212, 191, 0.1);
  border-color: var(--accent-teal);
}

.modal-btn.primary {
  background: var(--accent-teal);
  color: #0f1419;
  border-color: var(--accent-teal);
  font-weight: 600;
}

.modal-btn.primary:hover {
  background: #5eead4;
}

.modal-btn.cancel {
  color: var(--text-muted);
}

.modal-btn.cancel:hover {
  color: var(--text);
}

/* Upload FAB button */
.upload-fab {
  position: fixed;
  bottom: 180px;
  right: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-teal);
  color: #0f1419;
  font-size: 24px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  z-index: 1000;
  transition: all 0.2s ease;
}

.upload-fab:hover {
  transform: scale(1.1);
  background: #5eead4;
}

@media (max-width: 768px) {
  .upload-fab {
    bottom: calc(160px + env(safe-area-inset-bottom));
    right: 16px;
    width: 44px;
    height: 44px;
    font-size: 22px;
  }
}
