/* ═══════════════════════════════════════════════
   Variables & Reset
   ═══════════════════════════════════════════════ */
:root {
  --bg:        #0e0e0c;
  --surface:   #161614;
  --surface-2: #1e1e1b;
  --border:    #2a2a25;
  --border-2:  #3a3a34;
  --text:      #ddd8ca;
  --text-2:    #8a8679;
  --text-3:    #54524c;
  --accent:    #c8782a;
  --accent-dim:#7a4818;
  --green:     #5e9e72;
  --red:       #9e5050;
  --amber:     #c8a02a;
  --font-ui:   'IBM Plex Mono', 'Courier New', monospace;
  --font-body: 'Lora', Georgia, serif;
  --header-h:  52px;
  --sidebar-w: 260px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════════
   Header
   ═══════════════════════════════════════════════ */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 1rem;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
}

.brand-glyph {
  color: var(--accent);
  font-size: 14px;
  line-height: 1;
}

.brand-name {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .15em;
  color: var(--text);
}

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.header-actions {
  display: flex;
  gap: .25rem;
  flex-shrink: 0;
}

/* Status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: 11px;
  letter-spacing: .06em;
  padding: .25rem .6rem;
  border: 1px solid var(--border);
  color: var(--text-2);
  transition: all .2s;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
}

.status-online    .status-dot { background: var(--green); }
.status-synced    .status-dot { background: var(--green); }
.status-syncing   .status-dot { background: var(--amber); animation: pulse 1s infinite; }
.status-offline   .status-dot { background: var(--text-3); }
.status-error     .status-dot { background: var(--red); }
.status-disconnected .status-dot { background: var(--text-3); }

.status-online    { border-color: var(--green);  color: var(--green);  }
.status-synced    { border-color: var(--green);  color: var(--green);  }
.status-syncing   { border-color: var(--amber);  color: var(--amber);  }
.status-error     { border-color: var(--red);    color: var(--red);    }

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

/* Icon buttons */
.btn-icon {
  width: 34px;
  height: 34px;
  background: none;
  border: 1px solid transparent;
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.btn-icon:hover {
  border-color: var(--border-2);
  color: var(--text);
  background: var(--surface-2);
}

/* ═══════════════════════════════════════════════
   Layout
   ═══════════════════════════════════════════════ */
.main {
  display: flex;
  height: calc(100vh - var(--header-h));
  margin-top: var(--header-h);
}

/* ── Sidebar ──────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  transition: transform .25s ease;
}

.sidebar-top {
  padding: .75rem;
  border-bottom: 1px solid var(--border);
}

.btn-new {
  width: 100%;
  padding: .6rem .75rem;
  background: none;
  border: 1px solid var(--border-2);
  color: var(--text-2);
  font-family: var(--font-ui);
  font-size: 12px;
  letter-spacing: .08em;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: .5rem;
  transition: all .15s;
}
.btn-new span { color: var(--accent); font-size: 16px; line-height: 1; }
.btn-new:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--surface-2);
}

.notes-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}

.list-empty {
  padding: 2rem 1rem;
  color: var(--text-3);
  text-align: center;
  font-size: 12px;
}

/* Note item */
.note-item {
  padding: .85rem .9rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
  border-left: 2px solid transparent;
}
.note-item:hover  { background: var(--surface-2); }
.note-item.active {
  background: var(--surface-2);
  border-left-color: var(--accent);
}

.note-item-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: .3rem;
}

.note-item-preview {
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: .35rem;
}

.note-item-date {
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: .04em;
}

/* ── Editor zone ─────────────────────────────── */
.editor-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  position: relative;
}

.btn-back {
  display: none; /* shown only on mobile */
  align-items: center;
  gap: .4rem;
  padding: .65rem 1rem;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: .08em;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: color .15s;
}
.btn-back:hover { color: var(--text); }

/* Empty state */
.editor-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: var(--text-3);
}

.editor-empty-glyph {
  font-size: 32px;
  color: var(--border-2);
}

.editor-empty p {
  font-size: 12px;
  letter-spacing: .05em;
  text-align: center;
  line-height: 1.8;
}

/* Active editor */
.editor-active {
  flex: 1;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.note-title {
  padding: 1.25rem 1.5rem .75rem;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: .04em;
  outline: none;
  width: 100%;
}
.note-title::placeholder { color: var(--text-3); }

.note-body {
  flex: 1;
  padding: 1.25rem 1.5rem;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.75;
  resize: none;
  outline: none;
  width: 100%;
}
.note-body::placeholder { color: var(--text-3); }

.editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.save-status {
  font-size: 11px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: .4rem;
  min-height: 16px;
}

.dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
}
.dot-green { background: var(--green); }
.dot-amber { background: var(--amber); animation: pulse 1s infinite; }
.dot-red   { background: var(--red); }

.btn-delete {
  background: none;
  border: none;
  color: var(--text-3);
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: .06em;
  cursor: pointer;
  padding: .25rem .5rem;
  transition: color .15s;
}
.btn-delete:hover { color: var(--red); }

/* ═══════════════════════════════════════════════
   Modals / Overlays
   ═══════════════════════════════════════════════ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border-2);
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slide-up .2s ease;
}
.modal-wide { max-width: 560px; }

@keyframes slide-up {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .9rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .15em;
  color: var(--text-2);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  font-size: 12px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 1.25rem;
}

.modal-section-label {
  font-size: 10px;
  letter-spacing: .14em;
  color: var(--text-3);
  margin-bottom: .75rem;
  text-transform: uppercase;
}

/* Fields */
.field {
  margin-bottom: .9rem;
}

.field-label {
  display: block;
  font-size: 11px;
  color: var(--text-2);
  letter-spacing: .06em;
  margin-bottom: .35rem;
}

.field-input {
  width: 100%;
  padding: .55rem .75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 12px;
  outline: none;
  transition: border-color .15s;
}
.field-input:focus { border-color: var(--accent-dim); }
.field-input::placeholder { color: var(--text-3); }

.field-hint {
  display: block;
  font-size: 10px;
  color: var(--amber);
  margin-top: .4rem;
  line-height: 1.5;
}

/* Test result */
.test-result {
  padding: .6rem .8rem;
  font-size: 11px;
  border: 1px solid var(--border);
  margin-bottom: .75rem;
  letter-spacing: .04em;
}
.test-result.success { border-color: var(--green); color: var(--green); }
.test-result.error   { border-color: var(--red);   color: var(--red);   }

/* Modal actions */
.modal-actions {
  display: flex;
  gap: .6rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

/* Buttons */
.btn-primary {
  padding: .55rem 1.1rem;
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #0e0e0c;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .08em;
  cursor: pointer;
  transition: opacity .15s;
}
.btn-primary:hover    { opacity: .85; }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

.btn-secondary {
  padding: .55rem 1.1rem;
  background: none;
  border: 1px solid var(--border-2);
  color: var(--text-2);
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: .08em;
  cursor: pointer;
  transition: all .15s;
}
.btn-secondary:hover    { border-color: var(--text-2); color: var(--text); }
.btn-secondary:disabled { opacity: .4; cursor: not-allowed; }

/* ── Backup list ──────────────────────────────── */
.backup-toolbar {
  display: flex;
  gap: .6rem;
  margin-bottom: 1rem;
}

.backup-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 340px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}

.backup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .7rem .9rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  gap: 1rem;
}

.backup-item-info {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex: 1;
  min-width: 0;
}

.backup-rank {
  font-size: 11px;
  color: var(--accent);
  flex-shrink: 0;
  width: 28px;
}

.backup-date {
  font-size: 11px;
  color: var(--text);
}

.backup-total {
  font-size: 10px;
  color: var(--text-3);
  margin-left: auto;
  flex-shrink: 0;
}

.btn-restore {
  padding: .3rem .7rem;
  background: none;
  border: 1px solid var(--border-2);
  color: var(--text-2);
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: .06em;
  cursor: pointer;
  flex-shrink: 0;
  transition: all .15s;
}
.btn-restore:hover { border-color: var(--accent); color: var(--accent); }

/* ═══════════════════════════════════════════════
   Scrollbar
   ═══════════════════════════════════════════════ */
::-webkit-scrollbar        { width: 4px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: var(--border-2); }

/* ═══════════════════════════════════════════════
   Mobile — max-width: 768px
   ═══════════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    width: 100%;
    height: calc(100vh - var(--header-h));
    z-index: 50;
    transform: translateX(0);
  }

  .sidebar.slide-out {
    transform: translateX(-100%);
  }

  .editor-zone {
    width: 100%;
  }

  .btn-back {
    display: flex;
  }

  .backup-item {
    flex-wrap: wrap;
    gap: .5rem;
  }

  .backup-item-info {
    flex-wrap: wrap;
    gap: .4rem;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .btn-primary,
  .btn-secondary {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .backup-toolbar {
    flex-direction: column;
  }
}

/* ═══════════════════════════════════════════════
   Selection
   ═══════════════════════════════════════════════ */
::selection {
  background: var(--accent-dim);
  color: var(--text);
}
