/* ============================================================
   Encrypted Notes — Main Stylesheet
   Dark mode default, light mode via .light-mode on body
   ============================================================ */

/* ------------------------------------------------------------
   CSS Custom Properties — Dark Mode (default)
   ------------------------------------------------------------ */
:root {
  --bg:             #1a1a2e;
  --surface:        #16213e;
  --surface-hover:  #1a2744;
  --text:           #e0e0e0;
  --text-secondary: #a0a0b0;
  --input-bg:       #0f3460;
  --input-border:   #1a4080;
  --accent:         #e94560;
  --accent-hover:   #d63851;
  --border:         #2a2a4a;
  --danger:         #ef4444;
  --success:        #4ade80;
  --link:           #53d8fb;
}

/* ------------------------------------------------------------
   Light Mode Overrides
   ------------------------------------------------------------ */
body.light-mode {
  --bg:             #f5f5f5;
  --surface:        #ffffff;
  --surface-hover:  #f0f0f0;
  --text:           #1a1a2e;
  --text-secondary: #666666;
  --input-bg:       #ffffff;
  --input-border:   #dddddd;
  --border:         #e0e0e0;
}

/* ------------------------------------------------------------
   Global Reset & Base
   ------------------------------------------------------------ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  transition: background-color 0.2s, color 0.2s;
}

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

a:hover {
  text-decoration: underline;
}

/* ------------------------------------------------------------
   Utility Classes
   ------------------------------------------------------------ */
.hidden {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------
   Shared Button Styles
   ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  font-size: 0.95rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s, opacity 0.2s;
}

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

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

.btn-secondary {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background-color: var(--surface-hover);
}

.btn-ghost {
  background: none;
  border: none;
  color: var(--text);
  padding: 8px 16px;
}

.btn-ghost:hover {
  color: var(--accent);
  background-color: var(--surface-hover);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text);
  padding: 8px;
  min-width: 36px;
  min-height: 36px;
  font-size: 1rem;
}

.btn-icon:hover {
  color: var(--accent);
  background-color: var(--surface-hover);
}

.btn-danger {
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
}

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

.btn-full {
  display: block;
  width: 100%;
  padding: 14px;
  font-size: 1rem;
}

/* ------------------------------------------------------------
   Shared Form Styles
   ------------------------------------------------------------ */
.form-group {
  margin-bottom: 12px;
}

.auth-subtext,
.modal-subtext {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin: 0 0 1rem;
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 8px;
}

/* ------------------------------------------------------------
   Setup View & Login View
   ------------------------------------------------------------ */
#setup-view,
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background-color: var(--surface);
  border-radius: 12px;
  padding: 2rem;
  border: 1px solid var(--border);
  transition: background-color 0.2s, border-color 0.2s;
}

.auth-card h1,
.auth-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
  color: var(--text);
}

.auth-card input[type="text"],
.auth-card input[type="password"] {
  display: block;
  width: 100%;
  padding: 12px;
  background-color: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s, background-color 0.2s;
}

.auth-card input:focus {
  border-color: var(--accent);
}

/* ------------------------------------------------------------
   Top Bar
   ------------------------------------------------------------ */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background-color: rgba(22, 33, 62, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  transition: background-color 0.2s, border-color 0.2s;
}

body.light-mode .top-bar {
  background-color: rgba(255, 255, 255, 0.85);
}

.top-bar .app-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  white-space: nowrap;
}

.search-wrapper {
  flex: 1;
  max-width: 400px;
}

#search-input {
  width: 100%;
  padding: 8px 12px;
  background-color: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, background-color 0.2s;
}

#search-input:focus {
  border-color: var(--accent);
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Connection status dot */
.conn-status {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-secondary);
  flex-shrink: 0;
}

.conn-status.connected {
  background-color: var(--success);
  animation: pulse 2s ease-in-out infinite;
}

.conn-status.disconnected {
  background-color: var(--danger);
}

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

/* ------------------------------------------------------------
   Action Bar
   ------------------------------------------------------------ */
.action-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
}

/* Specific button overrides for action bar */
#new-note-btn {
  font-weight: 600;
}

/* ------------------------------------------------------------
   Notes Grid
   ------------------------------------------------------------ */
#notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 0 20px 20px;
}

#notes-grid .empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-secondary);
  padding: 60px 20px;
  font-size: 1rem;
}

/* ------------------------------------------------------------
   Note Card
   ------------------------------------------------------------ */
.note-card {
  position: relative;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  overflow: hidden;
}

.note-card:hover {
  background-color: var(--surface-hover);
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transform: translateY(-2px);
}

.note-card-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0 28px 8px 0;
}

.note-card-preview {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0 0 12px;
  line-height: 1.5;
}

.note-card-timestamp {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin: 0;
}

.note-card-delete {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background-color 0.15s;
}

.note-card:hover .note-card-delete {
  opacity: 1;
}

.note-card-delete:hover {
  color: var(--danger);
  background-color: rgba(239, 68, 68, 0.15);
}

/* ------------------------------------------------------------
   Files Section
   ------------------------------------------------------------ */
#files-section {
  padding: 20px;
  border-top: 1px solid var(--border);
}

#files-section h2 {
  margin: 0 0 16px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.file-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  list-style: none;
}

.file-entry:last-child {
  border-bottom: none;
}

.file-entry-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.file-entry-size {
  color: var(--text-secondary);
  font-size: 0.8rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.file-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.file-entry-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}

.file-entry-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  background-color: var(--surface-hover);
}

.file-entry-btn.danger:hover {
  color: var(--danger);
  border-color: var(--danger);
  background-color: rgba(239, 68, 68, 0.1);
}

/* Reset list styles for file list */
#files-list {
  padding: 0;
  margin: 0;
  list-style: none;
}

/* ------------------------------------------------------------
   Drop Zone (drag-and-drop overlay)
   ------------------------------------------------------------ */
#drop-zone {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  align-items: center;
  justify-content: center;
  background-color: rgba(233, 69, 96, 0.15);
  border: 3px dashed var(--accent);
  pointer-events: none;
}

#drop-zone.active {
  display: flex;
}

#drop-zone p {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
  pointer-events: none;
}

/* ------------------------------------------------------------
   Editor Modal
   ------------------------------------------------------------ */
#editor-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 150;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.6);
  padding: 20px;
  opacity: 0;
  transition: opacity 0.2s;
}

#editor-modal.open {
  display: flex;
  opacity: 1;
}

.editor-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 700px;
  max-height: 80vh;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: background-color 0.2s, border-color 0.2s;
}

.editor-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

#editor-title {
  padding: 16px 20px 8px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 700;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}

#editor-title::placeholder {
  color: var(--text-secondary);
}

#editor-content {
  flex: 1;
  padding: 16px 20px;
  background-color: var(--surface);
  color: var(--text);
  border: none;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.6;
  min-height: 300px;
  resize: vertical;
  outline: none;
  transition: background-color 0.2s;
}

#editor-content::placeholder {
  color: var(--text-secondary);
}

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  gap: 12px;
}

#save-status {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ------------------------------------------------------------
   Modal Shared (reenter + conflict)
   ------------------------------------------------------------ */
.modal-backdrop {
  /* Base styles applied via #id selectors below */
}

.modal-box {
  width: 100%;
  max-width: 400px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  transition: background-color 0.2s, border-color 0.2s;
}

.modal-box h2 {
  margin: 0 0 0.75rem;
  font-size: 1.2rem;
  color: var(--text);
}

.modal-box input[type="password"] {
  display: block;
  width: 100%;
  padding: 12px;
  margin-bottom: 12px;
  background-color: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s, background-color 0.2s;
}

.modal-box input:focus {
  border-color: var(--accent);
}

/* ------------------------------------------------------------
   Reenter Modal
   ------------------------------------------------------------ */
#reenter-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.7);
  padding: 20px;
  opacity: 0;
  transition: opacity 0.2s;
}

#reenter-modal.open {
  display: flex;
  opacity: 1;
}

/* ------------------------------------------------------------
   Conflict Modal
   ------------------------------------------------------------ */
#conflict-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.7);
  padding: 20px;
  opacity: 0;
  transition: opacity 0.2s;
}

#conflict-modal.open {
  display: flex;
  opacity: 1;
}

.conflict-actions {
  display: flex;
  gap: 12px;
  margin-top: 1rem;
}

.conflict-actions .btn {
  flex: 1;
  padding: 12px;
}

/* ------------------------------------------------------------
   Upload Progress Bar
   ------------------------------------------------------------ */
#upload-progress {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  z-index: 300;
  background-color: var(--border);
}

#upload-progress.active {
  display: block;
}

#upload-progress-fill {
  height: 100%;
  background-color: var(--accent);
  transition: width 0.2s ease;
  width: 0%;
}

/* ------------------------------------------------------------
   Scrollbar Styling
   ------------------------------------------------------------ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

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

::-webkit-scrollbar-thumb:hover {
  background-color: var(--text-secondary);
}

/* ============================================================
   Responsive — Tablet (601px–900px)
   ============================================================ */
@media (min-width: 601px) and (max-width: 900px) {
  #notes-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .editor-container {
    width: 90%;
  }
}

/* ============================================================
   Responsive — Mobile (max 600px)
   ============================================================ */
@media (max-width: 600px) {
  #notes-grid {
    grid-template-columns: 1fr;
    padding: 0 12px 12px;
  }

  .top-bar {
    flex-wrap: wrap;
    padding: 10px 12px;
  }

  .top-bar .app-title {
    flex: 1;
  }

  .search-wrapper {
    order: 3;
    max-width: 100%;
    flex-basis: 100%;
  }

  .action-bar {
    flex-direction: column;
    align-items: stretch;
    padding: 12px;
  }

  .action-bar .btn {
    width: 100%;
    padding: 14px;
    min-height: 44px;
  }

  .auth-card {
    padding: 1.5rem;
  }

  .auth-card input[type="text"],
  .auth-card input[type="password"] {
    padding: 14px 12px;
    min-height: 44px;
  }

  .auth-card .btn {
    min-height: 44px;
  }

  .note-card-delete {
    opacity: 1;
  }

  #editor-modal {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
  }

  .editor-container {
    max-width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
    border: none;
  }

  #editor-content {
    min-height: 0;
  }

  .modal-box {
    padding: 1.5rem;
  }

  .modal-box input[type="password"] {
    min-height: 44px;
    padding: 14px 12px;
  }

  .modal-box .btn {
    min-height: 44px;
  }

  #files-section {
    padding: 12px;
  }

  .file-entry-btn {
    padding: 8px 12px;
    min-height: 36px;
  }
}
