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

:root {
  --bg-gradient-start: #667eea;
  --bg-gradient-end: #764ba2;
  --bg-color: #f5f5f5;
  --container-bg: white;
  --text-color: #374151;
  --border-color: #e5e7eb;
  --card-bg: white;
  --card-hover-border: #667eea;
  --header-bg: #f9fafb;
  --input-bg: transparent;
  --button-hover-bg: #fee2e2;
  --info-bg: #f3f4f6;
  --info-text: #6b7280;
}

body.dark-mode {
  --bg-color: #1a1a1a;
  --container-bg: #2d2d2d;
  --text-color: #e5e7eb;
  --border-color: #404040;
  --card-bg: #353535;
  --card-hover-border: #667eea;
  --header-bg: #404040;
  --input-bg: #2d2d2d;
  --button-hover-bg: #4a4a4a;
  --info-bg: #404040;
  --info-text: #9ca3af;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  transition: background 0.3s;
}

.container {
  background: var(--container-bg);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 1400px;
  overflow: hidden;
  transition: background 0.3s;
}

header {
  background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
  color: white;
  padding: 20px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

h1 {
  font-size: 28px;
  font-weight: 600;
}

.search-bar input {
  padding: 8px 15px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 14px;
  min-width: 200px;
}

.search-bar input::placeholder {
  color: rgba(255, 255, 255, 0.7);
}

.search-bar input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.2);
  border-color: white;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.3);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.3s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: white;
}

.add-box-btn {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 2px solid white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
}

.add-box-btn:hover {
  background: white;
  color: var(--bg-gradient-start);
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  opacity: 0.95;
}

.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fbbf24;
  animation: pulse 2s infinite;
}

.status-indicator.connected {
  background: #10b981;
  animation: none;
}

.status-indicator.disconnected {
  background: #ef4444;
  animation: none;
}

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

main {
  padding: 30px;
  max-height: 70vh;
  overflow-y: auto;
}

.boxes-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.text-box-card {
  background: var(--card-bg);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.3s;
  display: flex;
  flex-direction: column;
}

.text-box-card:hover {
  border-color: var(--card-hover-border);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.1);
}

.text-box-card.hidden {
  display: none;
}

.box-header {
  background: var(--header-bg);
  padding: 12px 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  transition: background 0.3s;
}

.box-name {
  font-weight: 600;
  color: var(--text-color);
  font-size: 14px;
  border: none;
  background: var(--input-bg);
  outline: none;
  flex: 1;
  padding: 4px;
  border-radius: 4px;
  transition: background 0.2s;
}

.box-name:focus {
  background: var(--container-bg);
}

.box-header-right {
  display: flex;
  gap: 5px;
  align-items: center;
}

.box-toolbar {
  background: var(--header-bg);
  padding: 8px 15px;
  display: flex;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
}

.toolbar-btn {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-color);
  cursor: pointer;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 4px;
  transition: all 0.2s;
}

.toolbar-btn:hover {
  background: var(--button-hover-bg);
}

.delete-btn {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.2s;
}

.delete-btn:hover {
  background: var(--button-hover-bg);
}

.box-content-wrapper {
  flex: 1;
  position: relative;
  min-height: 200px;
}

.box-textarea {
  width: 100%;
  height: 100%;
  min-height: 200px;
  padding: 15px;
  font-size: 14px;
  line-height: 1.6;
  border: none;
  resize: vertical;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text-color);
  transition: background 0.3s, color 0.3s;
}

.box-textarea:focus {
  outline: none;
}

.box-footer {
  background: var(--header-bg);
  padding: 8px 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--info-text);
  border-top: 1px solid var(--border-color);
}

.box-stats {
  display: flex;
  gap: 15px;
}

.box-timestamp {
  font-style: italic;
}

.info {
  margin-top: 20px;
  padding: 15px;
  background: var(--info-bg);
  border-radius: 10px;
  text-align: center;
  color: var(--info-text);
  font-size: 14px;
  transition: background 0.3s;
}

@media (max-width: 768px) {
  body {
    padding: 10px;
  }

  header {
    flex-direction: column;
    gap: 15px;
    align-items: flex-start;
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
  }

  h1 {
    font-size: 24px;
  }

  main {
    padding: 20px;
  }

  .boxes-container {
    grid-template-columns: 1fr;
  }

  .search-bar input {
    min-width: 150px;
  }

  .box-toolbar {
    gap: 5px;
  }
}
