/* ============================================
   Premium Dark Glassmorphism Design System
   ============================================ */

/* CSS Custom Properties */
:root {
  --bg-gradient: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-blur: blur(10px);
  --accent-gradient: linear-gradient(135deg, #667eea, #764ba2);
  --action-gradient: linear-gradient(135deg, #f093fb, #f5576c);
  --text-primary: #e2e8f0;
  --text-muted: #94a3b8;
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.2);
  --radius-lg: 12px;
  --radius-md: 8px;
  --radius-sm: 6px;
  --transition: all 0.2s ease;
}

/* Reset & Base */
* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: #f093fb;
  text-decoration: none;
  transition: var(--transition);
}

a:hover { text-decoration: underline; }

/* ============================================
   Navigation
   ============================================ */
.navbar {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  padding: clamp(12px, 2vw, 16px) clamp(16px, 4vw, 32px);
  display: flex;
  gap: clamp(16px, 3vw, 32px);
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar a {
  color: var(--text-primary);
  font-weight: 600;
  font-size: clamp(13px, 1.5vw, 15px);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.navbar a:hover,
.navbar a.active {
  color: #fff;
  text-decoration: none;
  background: rgba(102, 126, 234, 0.2);
}

.navbar .brand {
  font-size: clamp(16px, 2vw, 20px);
  font-weight: 700;
  margin-right: clamp(8px, 2vw, 20px);
  background: var(--action-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Hamburger Menu Toggle (Pure CSS) */
.nav-toggle { display: none; }
.nav-toggle-label {
  display: none;
  cursor: pointer;
  padding: 8px;
  margin-left: auto;
}

.nav-toggle-label span,
.nav-toggle-label span::before,
.nav-toggle-label span::after {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: var(--transition);
  position: relative;
}

.nav-toggle-label span::before,
.nav-toggle-label span::after {
  content: '';
  position: absolute;
}

.nav-toggle-label span::before { top: -7px; }
.nav-toggle-label span::after { top: 7px; }

/* ============================================
   Layout
   ============================================ */
.container {
  padding: clamp(16px, 3vw, 32px);
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: var(--radius-lg);
  padding: clamp(16px, 3vw, 24px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-lg);
  transition: var(--transition);
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.flex {
  display: flex;
  gap: clamp(12px, 2vw, 20px);
  flex-wrap: wrap;
}

.flex-1 { flex: 1; min-width: 0; }

/* ============================================
   Buttons
   ============================================ */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: clamp(13px, 1.5vw, 14px);
  font-weight: 600;
  font-family: inherit;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
}

.btn-primary {
  background: var(--action-gradient);
  color: #fff;
  box-shadow: 0 4px 15px rgba(240, 147, 251, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(240, 147, 251, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-danger {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  color: #fff;
  box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
}

.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4);
}

.btn-ghost {
  background: transparent;
  color: #f093fb;
  border: 1px solid rgba(240, 147, 251, 0.5);
}

.btn-ghost:hover {
  background: rgba(240, 147, 251, 0.1);
  border-color: #f093fb;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  min-height: 36px;
}

/* ============================================
   Tables
   ============================================ */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(12px, 1.5vw, 14px);
}

th, td {
  padding: clamp(10px, 2vw, 14px) clamp(12px, 2vw, 16px);
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

th {
  color: var(--text-muted);
  font-size: clamp(11px, 1.2vw, 13px);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

tr {
  transition: var(--transition);
}

tr:hover {
  background: rgba(102, 126, 234, 0.08);
}

/* ============================================
   Modals
   ============================================ */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

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

.modal {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 4vw, 32px);
  width: 500px;
  max-width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
}

.modal h2 {
  margin-bottom: 20px;
  font-size: clamp(18px, 2.5vw, 22px);
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* ============================================
   Forms
   ============================================ */
label {
  display: block;
  margin-bottom: 6px;
  font-size: clamp(12px, 1.5vw, 13px);
  color: var(--text-muted);
  margin-top: 16px;
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text-primary);
  font-size: clamp(13px, 1.5vw, 15px);
  font-family: inherit;
  transition: var(--transition);
  min-height: 44px;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(102, 126, 234, 0.5);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

input::placeholder,
textarea::placeholder {
  color: rgba(148, 163, 184, 0.6);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

.form-actions {
  margin-top: 24px;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ============================================
   Thread List
   ============================================ */
.thread-list {
  max-height: calc(100vh - 180px);
  overflow-y: auto;
  overflow-x: hidden;
}

.thread-item {
  padding: clamp(12px, 2vw, 16px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  transition: var(--transition);
  border-radius: var(--radius-sm);
  margin: 4px;
}

.thread-item:hover,
.thread-item.active {
  background: rgba(102, 126, 234, 0.15);
  border-color: transparent;
}

.thread-item .name {
  font-weight: 600;
  font-size: clamp(13px, 1.5vw, 14px);
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-item .meta {
  font-size: clamp(10px, 1.2vw, 12px);
  color: var(--text-muted);
  flex-shrink: 0;
}

.thread-item .del {
  color: #e74c3c;
  cursor: pointer;
  font-size: 18px;
  font-weight: bold;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  opacity: 0.6;
}

.thread-item .del:hover {
  color: #f5576c;
  opacity: 1;
  background: rgba(231, 76, 60, 0.15);
}

/* ============================================
   Chat Area
   ============================================ */
.chat-area {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 180px);
  min-height: 300px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: clamp(12px, 2vw, 20px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 85%;
  padding: clamp(10px, 2vw, 14px) clamp(14px, 2vw, 18px);
  border-radius: var(--radius-lg);
  font-size: clamp(13px, 1.5vw, 14px);
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: var(--shadow-md);
  animation: messageIn 0.2s ease;
}

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

.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.4), rgba(118, 75, 162, 0.4));
  border: 1px solid rgba(102, 126, 234, 0.3);
  border-bottom-right-radius: 4px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-bottom-left-radius: 4px;
}

.msg.partial {
  opacity: 0.6;
  animation: pulse 1.5s ease-in-out infinite;
}

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

.chat-input {
  display: flex;
  gap: 12px;
  padding: clamp(12px, 2vw, 16px);
  border-top: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.chat-input input {
  flex: 1;
  min-width: 0;
}

.chat-input .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

/* ============================================
   Panels
   ============================================ */
.panels {
  display: flex;
  gap: 1px;
  height: calc(100vh - 100px);
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.panel {
  background: rgba(15, 12, 41, 0.6);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  overflow-y: auto;
  flex: 1;
  min-width: 250px;
}

.panel-header {
  padding: clamp(12px, 2vw, 16px);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: clamp(13px, 1.5vw, 15px);
  background: rgba(0, 0, 0, 0.2);
  position: sticky;
  top: 0;
  z-index: 10;
}

/* ============================================
   File Browser
   ============================================ */
.file-item {
  padding: clamp(8px, 1.5vw, 12px) clamp(12px, 2vw, 16px);
  cursor: pointer;
  font-size: clamp(12px, 1.3vw, 13px);
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-item:hover {
  background: rgba(102, 126, 234, 0.12);
}

.file-item.active {
  background: rgba(102, 126, 234, 0.2);
  border-left: 3px solid #667eea;
}

.file-preview {
  padding: clamp(12px, 2vw, 16px);
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: clamp(11px, 1.2vw, 13px);
  white-space: pre-wrap;
  word-wrap: break-word;
  background: rgba(0, 0, 0, 0.4);
  color: #c9d1d9;
  overflow: auto;
  max-height: 50%;
  border-top: 1px solid var(--glass-border);
}

/* ============================================
   Scrollbar
   ============================================ */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ============================================
   Utility Classes
   ============================================ */
.text-muted { color: var(--text-muted); }
.text-accent { color: #f093fb; }
.text-gradient {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.glass {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
}

.shadow { box-shadow: var(--shadow-lg); }
.shadow-sm { box-shadow: var(--shadow-md); }

.rounded { border-radius: var(--radius-lg); }
.rounded-sm { border-radius: var(--radius-sm); }

.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ============================================
   Mobile Responsive - Tablet (768px)
   ============================================ */
@media (max-width: 768px) {
  .panels {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 100px);
  }

  .panel {
    min-width: 100%;
    max-height: 50vh;
  }

  .panel:first-child {
    border-right: none;
    border-bottom: 1px solid var(--glass-border);
  }

  .flex {
    flex-direction: column;
  }

  .flex > * {
    width: 100%;
  }

  .nav-toggle-label {
    display: block;
  }

  .navbar {
    flex-wrap: wrap;
  }

  .navbar a:not(.brand) {
    display: none;
    width: 100%;
    text-align: center;
    padding: 12px;
  }

  .nav-toggle:checked ~ a:not(.brand) {
    display: block;
  }

  .nav-toggle:checked ~ .nav-toggle-label span {
    background: transparent;
  }

  .nav-toggle:checked ~ .nav-toggle-label span::before {
    transform: rotate(45deg);
    top: 0;
  }

  .nav-toggle:checked ~ .nav-toggle-label span::after {
    transform: rotate(-45deg);
    top: 0;
  }

  .thread-list {
    max-height: 40vh;
    overflow-x: auto;
    white-space: nowrap;
    display: flex;
    flex-direction: column;
  }

  .msg {
    max-width: 92%;
  }

  .chat-area {
    min-height: 400px;
  }
}

/* ============================================
   Mobile Responsive - Phone (480px)
   ============================================ */
@media (max-width: 480px) {
  html {
    font-size: 14px;
  }

  .navbar {
    padding: 12px 16px;
  }

  .navbar .brand {
    font-size: 16px;
  }

  .container {
    padding: 12px;
  }

  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 100vh;
    height: 100%;
    border-radius: 0;
    padding: 16px;
  }

  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .btn {
    min-height: 48px;
    padding: 12px 20px;
  }

  .btn-sm {
    min-height: 40px;
    padding: 8px 14px;
  }

  input,
  select,
  textarea {
    min-height: 48px;
    font-size: 16px; /* Prevents iOS zoom */
  }

  .chat-input {
    position: sticky;
    bottom: 0;
    background: rgba(15, 12, 41, 0.95);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
  }

  .thread-list {
    max-height: 35vh;
  }

  .thread-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .thread-item .del {
    align-self: flex-end;
    padding: 8px 12px;
  }

  .messages {
    padding-bottom: 80px;
  }

  .msg {
    max-width: 95%;
    font-size: 14px;
  }

  .panels {
    min-height: auto;
  }

  .panel {
    max-height: none;
    min-height: 200px;
  }

  .file-item {
    padding: 14px 16px;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  th, td {
    padding: 12px;
    min-width: 100px;
  }
}

/* ============================================
   Landscape Mobile
   ============================================ */
@media (max-width: 896px) and (orientation: landscape) {
  .chat-area {
    height: calc(100vh - 80px);
  }

  .messages {
    max-height: calc(100vh - 160px);
  }

  .modal {
    max-height: 90vh;
  }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
  body {
    background: #fff;
    color: #000;
  }

  .navbar,
  .chat-input,
  .btn,
  .del {
    display: none;
  }

  .modal-overlay {
    display: none !important;
  }
}

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

/* ============================================
   High Contrast Mode
   ============================================ */
@media (prefers-contrast: high) {
  :root {
    --glass-bg: rgba(0, 0, 0, 0.8);
    --glass-border: rgba(255, 255, 255, 0.3);
  }

  .btn-primary,
  .btn-danger {
    border: 2px solid #fff;
  }
}
