:root {
  --accent: #0a74da;
  --accent-dark: #085db0;
  --bg: #f4f6f8;
  --muted: #6b7280;
  --border: #d1d5db;
  --error: #b91c1c;
  --success: #047857;
}

* {
  box-sizing: border-box;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
  margin: 0;
  background: var(--bg);
  color: #111827;
  padding: 2rem 1rem 4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.topbar {
  width: min(720px, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.topbar h1 {
  margin: 0;
  font-size: 1.8rem;
}

.topbar .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease;
}

.topbar .btn:hover {
  background: rgba(10, 116, 218, 0.08);
}

main {
  width: min(720px, 100%);
  position: relative;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17, 24, 39, 0.55);
  padding: 1rem;
  z-index: 10;
}

.modal-inner {
  background: #fff;
  padding: 1.5rem;
  border-radius: 12px;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.3);
  width: min(360px, 100%);
}

.row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

input,
textarea,
button {
  width: 100%;
  padding: 0.65rem;
  margin: 0.35rem 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 1rem;
}

input:focus,
textarea:focus {
  outline: 2px solid rgba(10, 116, 218, 0.35);
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 140px;
}

button {
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

button.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

button.secondary:hover {
  background: rgba(10, 116, 218, 0.08);
}

button.secondary:disabled {
  color: var(--muted);
  border-color: var(--border);
  background: transparent;
}

.filebtn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.35rem 0 0.75rem;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.filebtn input {
  display: none;
}

#app-msg {
  min-height: 1.2rem;
  margin-top: 0.5rem;
  margin-bottom: 1.5rem;
}

#app-msg[data-tone="success"] {
  color: var(--success);
}

#app-msg[data-tone="error"] {
  color: var(--error);
}

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

#cloud-sync h2 {
  margin: 0;
}

.text-label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-weight: 600;
  color: #1f2937;
}

.text-label input {
  margin: 0;
}

small {
  font-size: 0.8rem;
}

#backup-modal .modal-inner {
  width: min(420px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.backup-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 240px;
  overflow-y: auto;
}

.backup-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  background: #f9fafb;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  cursor: pointer;
  transition: border 0.2s ease, background 0.2s ease;
}

.backup-item:hover {
  border-color: var(--accent);
}

.backup-item.selected {
  border-color: var(--accent);
  background: rgba(10, 116, 218, 0.12);
}

.backup-item strong {
  font-size: 1rem;
}

.backup-item span {
  font-size: 0.85rem;
  color: var(--muted);
}

#diff-modal .modal-inner {
  width: min(560px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.diff-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.diff-groups article {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 220px;
  overflow-y: auto;
}

.diff-groups h3 {
  margin: 0;
  font-size: 1rem;
}

.diff-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.diff-entry {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.diff-entry.error {
  border-color: rgba(185, 28, 28, 0.45);
}

.diff-entry.error strong {
  color: var(--error);
}

.diff-entry strong {
  font-size: 0.95rem;
}

.diff-entry span {
  font-size: 0.82rem;
  color: var(--muted);
}

.diff-entry .conflict-local {
  color: var(--accent);
}

.diff-entry .conflict-backup {
  color: var(--error);
}

#entries {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.empty {
  text-align: center;
  color: var(--muted);
  margin: 2rem 0;
}

.entry {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.entry-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
}

.entry-header h3 {
  margin: 0;
  font-size: 1.2rem;
}

.entry-header time {
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.entry-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  color: #1f2937;
  line-height: 1.5;
}

.entry-body img {
  border-radius: 10px;
  max-width: 100%;
  height: auto;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.15);
}

.entry-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.entry-actions button {
  width: auto;
  padding-inline: 1rem;
}

.entry-actions button[data-action="delete"] {
  background: #f87171;
}

.entry-actions button[data-action="delete"]:hover {
  background: #dc2626;
}

.entry-actions button[data-action="edit"] {
  background: var(--accent);
}

.entry-actions button[data-action="edit"]:hover {
  background: var(--accent-dark);
}

.entry.editing {
  border-color: var(--accent);
  box-shadow: 0 12px 28px rgba(10, 116, 218, 0.18);
}

.entry.error {
  border-color: rgba(185, 28, 28, 0.35);
  color: var(--error);
  background: rgba(254, 226, 226, 0.6);
}

@media (max-width: 480px) {
  body {
    padding: 1.5rem 1rem 3rem;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .entry-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
