/* ============================================================
   Design system — black & white, technical, sober.
   ============================================================ */

:root {
  /* Dark theme (default) */
  --bg: #000000;
  --bg-elev: #0d0d0d;
  --bg-hover: #1a1a1a;
  --border: #1f1f1f;
  --border-strong: #3a3a3a;
  --fg: #ffffff;
  --fg-dim: #888888;
  --fg-faint: #444444;
  --accent: #ffffff;
  --accent-fg: #000000;

  --mono: ui-monospace, "SF Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --radius: 2px;
  --t-fast: 120ms ease-out;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f7f7f7;
  --bg-hover: #ededed;
  --border: #e0e0e0;
  --border-strong: #b8b8b8;
  --fg: #000000;
  --fg-dim: #666666;
  --fg-faint: #bbbbbb;
  --accent: #000000;
  --accent-fg: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.dim { color: var(--fg-dim); }
.mono { font-family: var(--mono); font-size: 12px; }

/* ---- Buttons ---------------------------------------------------- */

button {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}

button:hover {
  background: var(--bg-hover);
  border-color: var(--fg);
}

button:focus {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 1px var(--fg);
}

button.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  font-weight: 600;
}

button.primary:hover {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}

button.danger {
  border-color: var(--border-strong);
  color: var(--fg);
}

button.danger:hover {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

button.icon-btn {
  padding: 6px 8px;
  font-size: 14px;
  line-height: 1;
}

/* ---- Inputs ----------------------------------------------------- */

input[type="text"], input[type="password"], textarea {
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 13px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 1px var(--fg);
}

textarea {
  resize: none;
  line-height: 1.6;
}

/* ---- Unlock overlay -------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.unlock-card {
  width: 380px;
  padding: 32px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}

.logo-large {
  width: 64px;
  height: 64px;
  display: block;
  margin: 0 auto 16px;
  filter: invert(1);
}

:root[data-theme="light"] .logo-large { filter: none; }

.unlock-card h1 {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.05em;
  text-align: center;
  margin: 0 0 4px;
}

.unlock-card .subtitle {
  text-align: center;
  color: var(--fg-dim);
  font-size: 12px;
  margin: 0 0 24px;
}

.unlock-card label {
  display: block;
  margin-bottom: 16px;
}

.unlock-card label span {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-dim);
  margin-bottom: 6px;
}

#unlock-btn {
  width: 100%;
  padding: 10px;
  margin-top: 8px;
}

.error {
  color: var(--fg);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  margin: 12px 0 0;
  min-height: 1em;
  padding-left: 12px;
  border-left: 2px solid var(--fg);
}

/* ---- App shell ------------------------------------------------- */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-strong);
  padding: 10px 16px;
  background: var(--bg-elev);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.logo-small {
  width: 18px;
  height: 18px;
  filter: invert(1);
  flex-shrink: 0;
}

:root[data-theme="light"] .logo-small { filter: none; }

.brand-name {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.db-path {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-dim);
  margin-left: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions { display: flex; gap: 6px; align-items: center; }

/* ---- Body layout ----------------------------------------------- */

.app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ---- Sidebar --------------------------------------------------- */

.sidebar {
  width: 300px;
  border-right: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-elev);
}

.sidebar-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
}

.note-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.note-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  border-left: 2px solid transparent;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast);
}

.note-item:hover {
  background: var(--bg-hover);
}

.note-item.selected {
  border-left-color: var(--fg);
  background: var(--bg-hover);
}

.note-item .preview {
  color: var(--fg);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item .meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-dim);
  margin-top: 4px;
}

/* ---- Editor ---------------------------------------------------- */

.editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.editor-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.editor-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
}

.editor-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

#editor-text {
  flex: 1;
  font-size: 14px;
}

.editor-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ---- Status bar ------------------------------------------------ */

.status-bar {
  border-top: 1px solid var(--border-strong);
  padding: 6px 16px;
  font-family: var(--mono);
  font-size: 11px;
  background: var(--bg-elev);
  min-height: 24px;
}

/* ---- Scrollbars ------------------------------------------------ */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--fg-dim); }

/* ============================================================
   Mobile / small screens
   ============================================================ */

@media (max-width: 768px) {
  /* Larger touch targets */
  button {
    padding: 10px 14px;
    font-size: 13px;
    min-height: 40px;
  }

  button.icon-btn {
    padding: 10px;
    min-height: 40px;
    min-width: 40px;
  }

  input[type="text"], input[type="password"], textarea {
    padding: 10px 12px;
    font-size: 14px;
  }

  /* Unlock card fills the screen on mobile */
  .unlock-card {
    width: 100%;
    max-width: 100%;
    padding: 24px 20px;
    border: none;
    border-radius: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .logo-large {
    width: 72px;
    height: 72px;
    margin-bottom: 20px;
  }

  .unlock-card h1 {
    font-size: 22px;
  }

  /* App header: more compact, wrap actions */
  .app-header {
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .brand {
    flex: 1 1 auto;
    min-width: 0;
  }

  .brand-name {
    font-size: 12px;
  }

  .db-path {
    display: none; /* too noisy on mobile */
  }

  .actions {
    flex: 0 0 100%;
    justify-content: flex-end;
    gap: 4px;
    flex-wrap: wrap;
  }

  /* Body: switch from side-by-side to stacked layout */
  .app-body {
    flex-direction: column;
  }

  /* Sidebar full width on top */
  .sidebar {
    width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border-strong);
    flex: 0 0 auto;
  }

  /* Editor fills the rest */
  .editor {
    flex: 1 1 auto;
    min-height: 0;
  }

  .editor-active {
    padding: 12px;
    gap: 8px;
  }

  /* Editor textarea bigger for typing on phone */
  #editor-text {
    font-size: 15px;
    line-height: 1.7;
  }

  /* Note items bigger */
  .note-item {
    padding: 14px;
  }

  .note-item .preview {
    font-size: 14px;
  }

  .note-item .meta {
    font-size: 12px;
  }

  /* Status bar smaller */
  .status-bar {
    padding: 4px 12px;
    font-size: 10px;
  }
}

/* Very small screens (older phones) */
@media (max-width: 480px) {
  .brand-name {
    display: none; /* just the logo */
  }

  .editor-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
}


/* ---- Search bar ------------------------------------------------- */

.search-bar {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}

.search-bar input[type="search"] {
  flex: 1;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-family: var(--mono);
  font-size: 12px;
}

.search-bar input[type="search"]:focus {
  outline: none;
  border-color: var(--fg);
}

.search-bar input[type="search"]::placeholder {
  color: var(--fg-dim);
}

.search-bar input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

@media (max-width: 768px) {
  .search-bar input[type="search"] {
    font-size: 14px;
    padding: 8px 12px;
  }
}


/* ---- History panel --------------------------------------------- */

.history-panel {
  margin-top: 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-elev);
  max-height: 40%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.history-title {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--fg-dim);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
}

.history-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.history-item .version-info {
  flex: 1;
  min-width: 0;
}

.history-item .version-label {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--fg);
}

.history-item .version-date {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-dim);
  margin-top: 2px;
}

.history-item .version-preview {
  font-size: 12px;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 4px;
}

.history-item button.restore {
  flex-shrink: 0;
  font-size: 11px;
  padding: 4px 8px;
}


/* ---- Status panel ---------------------------------------------- */




















.unlock-info {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-dim);
  line-height: 1.5;
  margin: 8px 0 16px 0;
}


/* Maschera i caratteri per input password (senza type="password") */
.masked-input {
  -webkit-text-security: disc;
  -moz-text-security: disc;
  text-security: disc;
}


/* ---- Status panel (compact, mono, B/W) -------------------------- */

.status-panel {
  margin-top: 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.status-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}

.status-title {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--fg-dim);
}

.status-body {
  padding: 8px;
}

.status-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.metric {
  border: 1px solid var(--border);
  padding: 4px 2px;
  text-align: center;
}

.metric-label {
  font-family: var(--mono);
  font-size: 8px;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric-value {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--fg);
  margin-top: 2px;
}

#status-chart {
  width: 100%;
  height: 80px;
  display: block;
  background: var(--bg);
  border: 1px solid var(--border);
}




/* Fix scroll bloccato nel textarea */
#editor-text {
  overscroll-behavior: contain;
  max-height: 100%;
  overflow-y: auto;
}

/* Fix scroll nel body */
body, html {
  overscroll-behavior: none;
}


/* ---- Toast notification (stile app) ---------------------------- */

.toast {
  position: fixed;
  top: 16px;
  right: 16px;
  max-width: 320px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  z-index: 1000;
  transition: opacity 200ms ease-out, transform 200ms ease-out;
}

.toast.hidden {
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
}

.toast-icon {
  color: var(--accent);
  font-size: 10px;
  flex-shrink: 0;
  margin-top: 1px;
}

.toast-message {
  flex: 1;
  line-height: 1.4;
  word-break: break-word;
}

/* ---- File paths in Status ------------------------------------- */

.file-paths {
  margin-top: 12px;
  padding: 8px;
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--fg-dim);
}

.file-paths-title {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  color: var(--fg-dim);
}

.file-path {
  margin-top: 4px;
  word-break: break-all;
}

.file-path-label {
  color: var(--fg-dim);
}

.file-path-value {
  color: var(--fg);
}


/* ---- File location (unlock screen) ----------------------------- */

.file-location {
  margin: 12px 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--fg-dim);
  text-align: left;
}

.file-location-title {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
  color: var(--fg-dim);
}

.file-location-path {
  color: var(--fg);
  word-break: break-all;
}
