/* styles.css - Complete Refactor with Mobile Support and Light Steel Theme */

/* ============================================
   THEME VARIABLES
   ============================================ */
:root {
  /* THEME 13: Light Steel - Grayscale Palette */
  --color-light-1: #f8f9fa;        /* Seasalt */
  --color-light-2: #e9ecef;        /* Antiflash white */
  --color-light-3: #dee2e6;        /* Platinum */
  --color-medium-1: #ced4da;       /* French gray */
  --color-medium-2: #adb5bd;       /* French gray 2 */
  --color-medium-3: #6c757d;       /* Slate gray */
  --color-dark-1: #495057;         /* Outer space */
  --color-dark-2: #343a40;         /* Onyx */
  --color-dark-3: #212529;         /* Eerie black */
  
  /* Semantic Colors */
  --color-background: #f8f9fa;
  --color-surface: #e9ecef;
  --color-text-primary: #212529;
  --color-text-secondary: #495057;
  --color-accent: #6c757d;
  --color-border: #dee2e6;
  --color-shadow: rgba(33, 37, 41, 0.1);
  
  /* Preserved Design Elements */
  --color-header-bg: #2c3e50;
  --color-header-text: white;
  --color-message-own: #dcf8c6;
  --color-message-other: white;
  --color-czmihat-bg: #e5ddd5;
  --color-primary: #0d6efd;
  --color-success: #198754;
  --color-danger: #dc3545;
  --color-warning: #ffd700;
}

/* THEME 21: Light Steel Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --color-background: #212529;
    --color-surface: #343a40;
    --color-text-primary: #f8f9fa;
    --color-text-secondary: #adb5bd;
    --color-accent: #6c757d;
    --color-border: #495057;
    --color-shadow: rgba(248, 249, 250, 0.1);
    
    /* Adjusted for dark mode */
    --color-chat-bg: #1a1a1a;
  }
}

/* ============================================
   RESET AND BASE STYLES
   ============================================ */
* {
  box-sizing: border-box;
}

html {
  margin: 0;
  padding: 0;
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  background-color: var(--color-background);
}

body > * {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.6;
  color: var(--color-text-primary);
  width: 100%;
  max-width: 1400px;
  padding: 20px;
  box-sizing: border-box;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1, h2, h3, h4 {
  margin-bottom: 0.5rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--color-text-primary);
}

h1 {
  margin-bottom: 1rem;
}

/* ============================================
   HEADER STYLES
   ============================================ */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center !important;
  background-color: var(--color-header-bg);
  box-shadow: 0 2px 4px var(--color-shadow);
  padding: 1rem;
  margin-bottom: 2rem;
  border-radius: 5px;
  color: var(--color-header-text);
}

.header .site-title {
  color: var(--color-header-text);
  font-size: 1.5rem;
  font-weight: bold;
}

.header .site-title a {
  color: inherit;
  text-decoration: none;
}

.header .site-title a:hover {
  text-decoration: none;
  color: #ecf0f1;
}

.header .user-info {
  display: flex;
  gap: 1rem;
  align-items: center!important;
}

.header .user-info span {
  color: var(--color-header-text);
  font-weight: 500;
}

.staff-indicator {
  color: var(--color-warning);
}

/* ============================================
   NAVIGATION
   ============================================ */
.main-nav {
  display: flex;
  gap: 20px;
  align-items: center!important;
}

.nav-link {
  display: flex;
  align-items: center!important;
  gap: 5px;
  color: #ecf0f1;
  text-decoration: none;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 20px;
  transition: background-color 0.2s;
}

.nav-link:hover {
  background-color: rgba(255, 255, 255, 0.1);
  text-decoration: none;
  color: white;
}

.nav-link.active {
  background-color: #3498db;
  color: white;
}

.nav-link.active:hover {
  background-color: #2980b9;
  color: white;
}

.admin-link {
  display: flex;
  align-items: center!important;
  gap: 5px;
  color: #e74c3c;
  text-decoration: none;
  font-weight: 600;
  margin-left: 20px;
  padding: 6px 12px;
  border-radius: 20px;
  transition: background-color 0.2s;
}

.admin-link:hover {
  background-color: rgba(231, 76, 60, 0.1);
  text-decoration: none;
}

.admin-link.active {
  background-color: #e74c3c;
  color: white;
}

/* ============================================
   NOTIFICATION BELL
   ============================================ */
.notification-icon {
  position: relative;
  color: #ecf0f1;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: all 0.2s;
}

.notification-icon:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: white;
}

.notification-badge {
  position: absolute;
  top: 0;
  right: 0;
  background-color: #e74c3c;
  color: white;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center!important;
  justify-content: center!important;
  font-size: 0.7rem;
  font-weight: bold;
  transform: translate(25%, -25%);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  background-color: var(--color-primary);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
  text-decoration: none;
  font-family: inherit;
}

.btn:hover {
  background-color: #0b5ed7;
  text-decoration: none;
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
}

.btn-success {
  background-color: var(--color-success);
}

.btn-success:hover {
  background-color: #157347;
}

.btn-danger {
  background-color: var(--color-danger);
}

.btn-danger:hover {
  background-color: #bb2d3b;
}

.btn-primary {
  background-color: var(--color-primary);
}

.btn-primary:hover {
  background-color: #0b5ed7;
}

.header .btn-danger {
  background-color: #e74c3c;
  border: none;
  padding: 6px 12px;
  border-radius: 20px;
  color: white;
  text-decoration: none;
  transition: background-color 0.2s;
}

.header .btn-danger:hover {
  background-color: #c0392b;
  text-decoration: none;
  color: white;
}

/* ============================================
   CHAT LOG
   ============================================ */
#chat-log {
  height: 600px !important;
  overflow-y: auto;
  background-color: var(--color-chat-bg);
  border-radius: 8px;
  margin-bottom: 1rem;
  box-shadow: 0 2px 10px var(--color-shadow);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  padding: 20px;
}

#chat-log::after {
  content: "";
  display: table;
  clear: both;
}

/* ============================================
   MESSAGE BUBBLES
   ============================================ */
.message-row {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  margin-bottom: 15px;
  position: relative;
  clear: both;
}

.message-row.own-message {
  align-self: flex-end;
  float: right;
  margin-left: auto;
}

.message-row.other-message {
  align-self: flex-start;
  float: left;
}

.message-bubble {
  padding: 12px 15px;
  border-radius: 18px;
  position: relative;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  margin-bottom: 5px;
}

.own-message .message-bubble {
  background-color: var(--color-message-own);
  border-bottom-right-radius: 5px;
  margin-left: auto;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}

.other-message .message-bubble {
  background-color: var(--color-message-other);
  border-bottom-left-radius: 5px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}

.message-content-container {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  width: 100%;
}

.message-content {
  flex: 1;
  word-wrap: break-word;
  font-size: 0.95rem;
  color: #303030;
  line-height: 1.4;
  padding-right: 4px;
}

.timestamp {
  font-size: 0.7rem;
  color: rgba(0, 0, 0, 0.45);
  white-space: nowrap;
  margin-left: auto;
  margin-bottom: 1px;
  position: static;
  align-self: flex-end;
}

.username {
  font-weight: bold;
  color: var(--color-primary);
  margin-bottom: 4px;
  font-size: 0.85rem;
}

.username[data-user="admin"] {
  color: var(--color-danger);
}

.own-message .message-bubble:after {
  content: "";
  position: absolute;
  right: -8px;
  bottom: 0;
  width: 0;
  height: 0;
  border: 8px solid transparent;
  border-left-color: var(--color-message-own);
  border-right: 0;
  border-bottom: 0;
  margin-right: 0;
}

.other-message .message-bubble:after {
  content: "";
  position: absolute;
  left: -8px;
  bottom: 0;
  width: 0;
  height: 0;
  border: 8px solid transparent;
  border-right-color: var(--color-message-other);
  border-left: 0;
  border-bottom: 0;
  margin-left: 0;
}

.message-row + .message-row.own-message {
  margin-top: -8px;
}

.message-row + .message-row.other-message {
  margin-top: -8px;
}

/* ============================================
   CHAT INPUT
   ============================================ */
.chat-input-container {
  display: flex;
  margin-top: 15px;
  margin-bottom: 15px;
  gap: 10px;
  position: relative;
  background-color: #f0f0f0;
  border-radius: 30px;
  padding: 8px;
  box-shadow: 0 1px 3px var(--color-shadow);
  align-items: flex-end;
  width: 100%;
  box-sizing: border-box;
}

#chat-message-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 150px;
  padding: 12px 20px;
  border: none;
  border-radius: 24px;
  font-size: 1rem;
  background-color: white;
  transition: box-shadow 0.2s;
  box-sizing: border-box;
  resize: none;
  overflow-y: auto;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.4;
}

#chat-message-input:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.25);
}

#chat-message-submit {
  padding: 10px 18px;
  background-color: #0d6efd;
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  margin-left: 4px;
}

#chat-message-submit:hover {
  background-color: #0b5ed7;
  transform: scale(1.05);
}

#chat-message-submit:active {
  transform: scale(0.95);
}

#chat-message-submit i {
  font-size: 1.1rem;
}

/* ============================================
   ROOM LIST
   ============================================ */
.section-title {
  color: var(--color-text-primary);
  margin-bottom: 1rem;
  font-size: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.room-card {
  background-color: var(--color-surface);
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 2px 4px var(--color-shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.room-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px var(--color-shadow);
}

.room-card h3 {
  margin: 0 0 0.5rem 0;
  color: var(--color-text-primary);
  font-size: 1.25rem;
}

.room-card h3 a {
  color: var(--color-primary);
  text-decoration: none;
}

.room-card h3 a:hover {
  text-decoration: underline;
}

.room-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
  color: var(--color-text-secondary);
}

.created-by, .created-at {
  color: var(--color-text-secondary);
}

.encryption-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.encryption-indicator i {
  color: var(--color-success);
}

.no-rooms-message {
  text-align: center;
  padding: 3rem;
  background-color: var(--color-surface);
  border-radius: 8px;
  color: var(--color-text-secondary);
  box-shadow: 0 2px 4px var(--color-shadow);
}

.no-rooms-message i {
  font-size: 3rem;
  margin-bottom: 1rem;
  color: var(--color-accent);
}

/* ============================================
   ROOM HEADER
   ============================================ */
.room-header {
  background-color: var(--color-surface);
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  box-shadow: 0 2px 4px var(--color-shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.room-header h3 {
  margin: 0;
  color: var(--color-text-primary);
}

.room-meta {
  display: flex;
  gap: 1rem;
  align-items: center;
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  flex-wrap: wrap;
}

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

/* ============================================
   FILTER SECTION
   ============================================ */
.filter-section {
  background-color: var(--color-surface);
  padding: 1.5rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  box-shadow: 0 2px 4px var(--color-shadow);
}

.filter-section h3 {
  margin-top: 0;
  margin-bottom: 1rem;
  color: var(--color-text-primary);
}

.filter-input-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-input, 
.filter-select {
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 1rem;
  background-color: white;
  color: var(--color-text-primary);
  flex: 1;
  min-width: 200px;
}

.filter-input:focus,
.filter-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.1);
}

.filter-btn {
  padding: 0.5rem 1rem;
  background-color: var(--color-primary);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.filter-btn:hover {
  background-color: #0b5ed7;
}

.clear-btn {
  padding: 0.5rem 1rem;
  background-color: var(--color-accent);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.clear-btn:hover {
  background-color: var(--color-dark-1);
}

/* ============================================
   ENCRYPTION KEY DISPLAY
   ============================================ */
.key-display {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--color-surface);
  padding: 12px;
  border-radius: 8px;
  margin-top: 1rem;
  border: 1px solid var(--color-border);
}

.key-text {
  flex: 1;
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
  color: var(--color-text-primary);
  word-break: break-all;
  background-color: white;
  padding: 8px;
  border-radius: 4px;
  border: 1px solid var(--color-border);
}

.key-btn {
  padding: 8px 12px;
  background-color: white;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--color-text-primary);
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background-color 0.2s;
}

.key-btn:hover {
  background-color: #e0e0e0;
}

.key-btn i {
  font-size: 0.7rem;
}

/* ============================================
   ENCRYPTION MODAL
   ============================================ */
.encryption-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.encryption-modal-content {
  background-color: var(--color-surface);
  border-radius: 8px;
  box-shadow: 0 4px 20px var(--color-shadow);
  width: 90%;
  max-width: 500px;
  overflow: hidden;
}

.encryption-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid var(--color-border);
}

.encryption-modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--color-text-primary);
}

.close-encryption-modal {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--color-accent);
}

.encryption-modal-body {
  padding: 20px;
  max-height: 70vh;
  overflow-y: auto;
  color: var(--color-text-primary);
}

.encryption-modal-footer {
  padding: 15px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--color-border);
}

/* ============================================
   AUTHENTICATION FORMS
   ============================================ */
.auth-container {
  max-width: 500px;
  margin: 2rem auto;
  background-color: var(--color-surface);
  border-radius: 5px;
  box-shadow: 0 2px 4px var(--color-shadow);
  padding: 2rem;
}

.auth-container h2 {
  text-align: center;
  margin-bottom: 1.5rem;
  color: var(--color-text-primary);
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--color-text-primary);
}

.form-control {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 1rem;
  background-color: white;
  color: var(--color-text-primary);
}

.form-control-readonly {
  background-color: var(--color-light-1);
  cursor: not-allowed;
}

.help-text {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: var(--color-text-secondary);
}

.errorlist {
  color: var(--color-danger);
  list-style-type: none;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
}

.auth-links {
  text-align: center;
  margin-top: 1.5rem;
}

/* ============================================
   MODALS
   ============================================ */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-content {
  background-color: var(--color-surface);
  width: 400px;
  max-width: 90%;
  border-radius: 5px;
  box-shadow: 0 4px 8px var(--color-shadow);
}

.modal-header, 
.modal-body, 
.modal-footer {
  padding: 15px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center!important;
  border-bottom: 1px solid var(--color-border);
}

.modal-header h3 {
  color: var(--color-text-primary);
}

.close-modal {
  cursor: pointer;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--color-accent);
}

.modal-body {
  color: var(--color-text-primary);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--color-border);
}

/* ============================================
   ADMIN TOOLS
   ============================================ */
.admin-panel {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.admin-section {
  background-color: var(--color-surface);
  border-radius: 5px;
  box-shadow: 0 2px 4px var(--color-shadow);
  padding: 1.5rem;
}

.admin-section h2 {
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 0.75rem;
  margin-bottom: 1.5rem;
  color: var(--color-text-primary);
}

.admin-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.create-room-form,
.delete-room-form {
  background-color: var(--color-surface);
  padding: 20px;
  border-radius: 5px;
  box-shadow: 0 2px 4px var(--color-shadow);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.admin-table th, 
.admin-table td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-primary);
}

.admin-table th {
  background-color: var(--color-light-1);
  font-weight: 600;
}

/* ============================================
   MOBILE COMPREHENSIVE SPACING FIX
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Remove all default spacing */
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    html {
        margin: 0 !important;
        padding: 0 !important;
        height: 100%;
    }

    body {
        margin: 0 !important;
        padding: 0 !important;
        padding-top: 0 !important;
        height: 100%;
        width: 100%;
        overflow-x: hidden;
    }

    .app-container {
        margin: 0 !important;
        padding: 0 !important;
    }

    .header {
        top: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .content {
        padding-top: var(--header-height) !important;
        margin: 0 !important;
    }

    .content > *:first-child {
        margin-top: 0 !important;
        padding-top: 12px;
    }

    .room-header {
        margin-top: 0 !important;
        padding-top: 12px;
    }

    .section-title {
        margin-top: 12px !important;
    }

    #chat-log {
        margin-top: 0 !important;
    }

    .rooms-grid {
        margin-top: 0 !important;
    }

    body.keyboard-open {
        position: fixed;
        width: 100%;
        overflow: hidden;
    }

    .chat-input-container {
        position: fixed !important;
        bottom: 0 !important;
        z-index: 1001 !important;
    }
}

/* ============================================
   FALLBACK FOR HIGH-RESOLUTION DEVICES
   ============================================ */
@media (max-width: 1440px) and (max-height: 3200px),
       (max-width: 3200px) and (max-height: 1440px) {
    
    @supports not ((-webkit-touch-callout: none) or (hover: none)) {
        html, body {
            margin: 0 !important;
            padding: 0 !important;
        }

        body {
            padding-top: 0 !important;
        }

        .header {
            top: 0 !important;
            margin: 0 !important;
        }

        .content {
            margin-top: 0 !important;
            padding-top: var(--header-height) !important;
        }

        .content > *:first-child {
            margin-top: 0 !important;
        }
    }
}

/* ============================================
   iOS-SPECIFIC SPACING FIXES
   ============================================ */
@supports (-webkit-touch-callout: none) {
    html {
        margin: 0 !important;
        padding: 0 !important;
    }

    body {
        margin: 0 !important;
        padding: 0 !important;
        padding-top: 0 !important;
    }

    .header {
        top: 0 !important;
    }

    .content {
        margin-top: 0 !important;
    }
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */
@media (max-width: 768px) {
  .admin-controls {
    grid-template-columns: 1fr;
  }
  
  .filter-input-group {
    flex-direction: column;
    min-width: 100%;
  }
  
  .filter-input,
  .filter-select {
    width: 100%;
    flex: none;
  }
  
  .filter-btn,
  .clear-btn {
    width: 100%;
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.hidden {
  display: none !important;
}

.text-center {
  text-align: center!important;
}

.mt-0 {
  margin-top: 0 !important;
}

.mb-0 {
  margin-bottom: 0 !important;
}

.p-0 {
  padding: 0 !important;
}