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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  margin: 0;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  transition: background 0.5s ease, color 0.5s ease;
  color: #333;
}

body.dark {
  background: linear-gradient(135deg, #3a3a5a 0%, #26263a 100%);
  color: #f0f0f0;
}

.app {
  width: 100%;
  max-width: 1200px;
  margin: 20px 0;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  padding: 30px;
  transition: all 0.3s ease;
}

body.dark .app {
  background: rgba(30, 30, 47, 0.95);
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 3px solid #eaeaea;
}

body.dark .app-header {
  border-bottom: 3px solid #3a3a55;
}

h1 {
  font-size: 2.5rem;
  background: linear-gradient(90deg, #6a11cb 0%, #2575fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
}

body.dark h1 {
  background: linear-gradient(90deg, #a78bfa 0%, #60a5fa 100%);
  -webkit-background-clip: text;
}

.controls {
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
  margin-bottom: 25px;
}

.search-container {
  position: relative;
  flex: 1;
  min-width: 250px;
}

#export-modal .search-container {
  margin-top: 12px;
}

#export-modal .modal-content {
  box-sizing: border-box;
  max-height: 100vh;
  overflow-y: auto;
}

#search {
  width: 100%;
  padding: 14px 20px 14px 45px;
  border-radius: 12px;
  border: 2px solid #ddd;
  font-size: 1.02rem;
  transition: all 0.3s ease;
  background: #f4f4f4
}

#search:focus {
  border-color: #6a11cb;
  box-shadow: 0 0 0 3px rgba(106, 17, 203, 0.2);
  outline: none;
}

body.dark #search {
  background: #2d2d42;
  border-color: #4a4a6a;
  color: #f0f0f0;
}

.search-icon {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: #888;
}

.btn {
  padding: 14px 24px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.3s ease;
  font-size: 1rem;
}

.btn-primary {
  background: linear-gradient(90deg, #6a11cb 0%, #2575fc 100%);
  color: white;
  box-shadow: 0 4px 2px rgba(106, 17, 203, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(180deg, #5809b0 0%, #1c64e0 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 8px rgba(106, 17, 203, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(106, 17, 203, 0.3);
}

.btn-secondary {
  background: #f4f4f4;
  color: #444;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.btn-secondary:hover {
  background: #e5e8ec;
  transform: translateY(-2px);
  box-shadow: 0 6px 10px rgba(0, 0, 0, 0.1);
}

body.dark .btn-secondary {
  background: #3a3a55;
  color: #f0f0f0;
  box-shadow: 0 4px 4px rgba(0, 0, 0, 0.4);
}

body.dark .btn-secondary:hover {
  background: #4a4f6a;
}

.btn-icon {
  font-size: 1.2rem;
}

.main-content {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 30px;
}

.main-content.focus-mode-active {
  display: grid;
  grid-template-columns: 1fr;
  gap: 30px;
}

@media (max-width: 900px) {
  .main-content {
    grid-template-columns: 1fr;
  }
}

.note-form-container {
  background: #f4f4f4;
  border-radius: 16px;
  padding: 25px;
  box-shadow: 0 5px 5px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
  height: 500px;
}

body.dark .note-form-container {
  background: #2a2a3e;
  box-shadow: 0 5px 5px rgba(0, 0, 0, 0.4);
}

.note-form-container.focus-mode {
  grid-column: 1 / -1;
  height: 500px;
}

.form-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.focus-toggle {
  background: none;
  border: none;
  color: #6a11cb;
  cursor: pointer;
  font-size: 1.2rem;
}

#note-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

input, textarea, select {
  padding: 14px;
  border-radius: 10px;
  border: 2px solid #e1e5eb;
  font-family: inherit;
  font-size: 1.02rem;
  transition: all 0.3s ease;
  width: 100%;
}

input:focus, textarea:focus, select:focus {
  border-color: #6a11cb;
  box-shadow: 0 0 0 3px rgba(106, 17, 203, 0.2);
  outline: none;
}

body.dark input, 
body.dark textarea, 
body.dark select {
  background: #3a3a55;
  border-color: #4a4a6a;
  color: #f0f0f0;
}

#note-title {
  font-size: 1.3rem;
  font-weight: 600;
}

#note-content {
  min-height: 100px;
  resize: vertical;
  padding: 14px 14px 24px 14px;
}

.form-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  margin-top: 8px;
}

.word-count {
  color: #6a11cb;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 6px 12px;
  background: rgba(106, 17, 203, 0.1);
  border-radius: 8px;
  flex-shrink: 0;
  display: block;
  width: fit-content;
}

#save-note {
  margin: auto;
}

body.dark .word-count {
  color: #a86fff;
  background: rgba(167, 45, 250, 0.1);
  flex-shrink: 0;
}

.notes-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  align-items: start;
}

.note {
  background: white;
  border-radius: 16px;
  padding: 20px;
  position: relative;
  cursor: grab;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
  overflow: hidden;
}

.note:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

body.dark .note {
  background: #2a2a3e;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.note.pinned {
  border: 2px solid #ffc107;
  order: -1;
}

.note-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.note-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-right: 10px;
  word-break: break-word;
  display: flex;
  align-items: center;
  gap: 8px;
}

.note-title .emoji {
  font-size: 1.4rem;
}

.note-actions {
  display: flex;
  gap: 10px;
}

.note-btn {
  background: rgba(0, 0, 0, 0.1);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  color: #484848;
  transition: all 0.2s ease;
  padding: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.note-btn:hover {
  background: rgba(0, 0, 0, 0.15);
  color: #000;
  transform: scale(1.1);
}

body.dark .note-btn {
  background: rgba(255, 255, 255, 0.12);
  color: #d8d8d8;
}

body.dark .note-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.note-btn.pinned {
  background: rgba(255, 193, 7, 0.75);
  color: #dc2f2f;
}

body.dark .note-btn.pinned {
  background: rgba(255, 193, 7, 0.75);
  color: #dc2f2f;
}

.note-content {
  word-wrap: break-word;
  line-height: 1.5;
  flex-grow: 1;
  font-size: 1.05rem;
}

.note-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid #eee;
  font-size: 0.85rem;
  color: #888;
  gap: 10px;
}

body.dark .note-footer {
  border-top: 1px solid #3a3a55;
  color: #aaa;
}

.note-category {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.note-date {
  font-size: 0.95rem;
  color: #333;
  text-shadow: 0 0 2px rgba(0,0,0,0.3);
  opacity: 0.9;
}

body.dark .note-date {
  color: #ffffff;
  text-shadow: 0 0 2px rgba(0,0,0,0.3);
  opacity: 0.9;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: #888;
  grid-column: 1 / -1;
}

body.dark .empty-state {
  color: #aaa;
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: 15px;
  opacity: 0.5;
}

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

.modal-content {
  background: white;
  padding: 30px;
  border-radius: 16px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  max-height: 80vh;
  overflow-y: auto;
}

body.dark .modal-content {
  background: #2a2a3e;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #777;
}

.modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 25px;
}

.storage-info {
  display: flex;
  justify-content: space-between;
  font-size: 1.04rem;
  color: #777;
  margin-bottom: 10px;
}

body.dark .storage-info {
  color: #aaa;
}

.storage-bar {
  height: 12px;
  background: #e9ecef;
  border-radius: 4px;
  margin-bottom: 30px;
  overflow: hidden;
}

body.dark .storage-bar {
  background: #3a3a55;
}

.storage-progress {
  height: 100%;
  background: linear-gradient(90deg, #6a11cb 0%, #2575fc 100%);
  border-radius: 4px;
  transition: width 0.5s ease;
}

.note-list {
  max-height: 225px;
  overflow-y: auto;
  margin: 20px 0;
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 10px;
}

body.dark .note-list {
  border-color: #3a3a55;
}

.note-item {
  padding: 12px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  transition: background-color 0.2s;
}

body.dark .note-item {
  border-bottom-color: #3a3a55;
}

.note-item:hover {
  background-color: #f5f5f5;
}

body.dark .note-item:hover {
  background-color: #3a3a55;
}

.note-item:last-child {
  border-bottom: none;
}

.note-item.selected {
  background-color: #e3f2fd;
  font-weight: bold;
}

body.dark .note-item.selected {
  background-color: #2a3f5d;
}

/* Nuovi stili per la selezione multipla */
.selection-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  padding: 10px;
  background: #f4f4f4;
  border-radius: 10px;
}

body.dark .selection-controls {
  background: #2d2d42;
}

.selection-info {
  font-weight: 600;
  color: #6a11cb;
}

body.dark .selection-info {
  color: #a78bfa;
}

.selection-actions {
  display: flex;
  gap: 10px;
}

.select-all-btn, .delete-selected-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.3s ease;
}

.select-all-btn {
  background: #e9ecef;
  color: #495057;
}

body.dark .select-all-btn {
  background: #3a3a55;
  color: #f0f0f0;
}

.select-all-btn:hover {
  background: #dee2e6;
}

body.dark .select-all-btn:hover {
  background: #4a4a6a;
}

.delete-selected-btn {
  background: #dc3545;
  color: white;
}

.delete-selected-btn:hover {
  background: #c82333;
}

.delete-selected-btn:disabled {
  background: #6c757d;
  cursor: not-allowed;
}

.note.selected {
  box-shadow: 0 0 0 3px #c7234e;
}

body.dark .note.selected {
  box-shadow: 0 0 0 3px #c7234e;
}

.delete-note.selected {
  background: #dc3545 !important;
  color: white !important;
}

.selection-mode-btn {
  margin-left: 5px;
  margin-right: 5px;
}

@media (max-width: 600px) {
  .app {
    padding: 15px;
  }
  
  .controls {
    flex-direction: column;
  }
  
  .search-container {
    width: 100%;
  }
  
  .btn {
    width: 100%;
    justify-content: center;
  }

  .note-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .note-date {
    align-self: flex-end;
  }

  .selection-controls {
    flex-direction: column;
    gap: 10px;
  }

  .selection-actions {
    width: 100%;
    justify-content: space-between;
  }
}

/* Animazioni */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.note {
  animation: fadeIn 0.3s ease;
}

/* Transizioni per il tema dark/light */
body, .app, .note-form-container, .note, input, textarea, select {
  transition: all 0.3s ease;
}