:root {
  --bg-a: #f4f6f9;
  --bg-b: #dce8f2;
  --panel: #ffffff;
  --text: #10212b;
  --muted: #4f6877;
  --accent: #046f94;
  --accent-strong: #025874;
  --danger: #ad1f3f;
  --ring: rgba(4, 111, 148, 0.24);
  --border: #d1dee8;
  --shadow: 0 14px 32px rgba(10, 35, 52, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 10% 10%, #e9f6ff 0%, transparent 40%),
    radial-gradient(circle at 90% 15%, #f3fff6 0%, transparent 35%),
    linear-gradient(165deg, var(--bg-a), var(--bg-b));
}

.login-wrap {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-card h1 {
  margin-top: 0;
  margin-bottom: 8px;
}

.login-card p {
  margin-top: 0;
  color: var(--muted);
}

.error-box {
  margin: 12px 0;
  border-radius: 12px;
  padding: 10px;
  background: #ffdfe9;
  color: #7b1730;
}

.login-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  cursor: pointer;
}

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid var(--ring);
}

button {
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.brand {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}

.menu-toggle-btn {
  width: 44px;
  height: 40px;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  padding: 0 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  background: var(--accent);
}

.menu-toggle-btn span {
  display: block;
  width: 100%;
  height: 2px;
  background: #fff;
  border-radius: 4px;
}

.menu-toggle-btn:hover {
  background: var(--accent-strong);
}

.menu-toggle-btn:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

.refresh-btn {
  width: auto;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 0.95rem;
  font-weight: 500;
}

.refresh-btn:hover {
  background: var(--accent-strong);
}

.refresh-btn:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

.top-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 190px;
  display: grid;
  gap: 6px;
  padding: 8px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 25;
}

.menu-item {
  text-align: left;
  background: #f7fbfd;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 10px;
}

.menu-item-user {
  background: #dce8ef;
  color: #3a5a6e;
  border-color: #b8d0db;
  cursor: default;
  user-select: none;
}

.menu-item-user:hover {
  background: #dce8ef;
}

.menu-item:hover {
  background: #e9f3f7;
}

.menu-item.active {
  background: #2f7de1;
  color: #fff;
  border-color: #2466bd;
}

.menu-item-danger {
  background: #ffeef1;
  color: var(--danger);
  border-color: #f5cad2;
}

.menu-item-danger:hover {
  background: #ffdce4;
}

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

#searchInput {
  min-width: 260px;
}

.btn {
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
}

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

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

.btn-secondary:hover {
  background: #d8eaf4;
}

.btn-danger {
  background: var(--danger);
}

.btn-archive {
  background: #0d6efd;
}

.btn-archive:hover {
  background: #0a58ca;
}

.btn-archive:disabled {
  background: #8fb7ff;
  cursor: not-allowed;
}

.btn-archived-toggle {
  background: #2f7de1;
}

.btn-archived-toggle:hover {
  background: #2466bd;
}

.btn-archived-toggle.active {
  background: #1f4f90;
}

.filter-row {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-btn {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 999px;
  transition: box-shadow 0.15s ease, transform 0.1s ease;
}

.filter-btn.active {
  box-shadow: 0 0 0 3px rgba(16, 33, 43, 0.35);
  outline: 2px solid rgba(16, 33, 43, 0.75);
  outline-offset: 1px;
}

.reader-panel {
  margin-top: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  min-height: 70vh;
  max-height: 78vh;
  overflow-y: auto;
  overflow-x: hidden;
}

.reader-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.reader-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.reader-meta {
  color: var(--muted);
  margin-top: 6px;
}

.reader-content {
  margin-top: 14px;
  line-height: 1.6;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}

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

.priority-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.priority-btn {
  min-width: 38px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #f7fbfd;
  color: var(--text);
  border: 1px solid var(--border);
}

.priority-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: #f2f8fc;
  color: var(--text);
  border: 1px solid var(--border);
}

.new-note-panel {
  margin-top: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.new-note-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.new-note-head-main {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.new-note-head h3 {
  margin: 0;
}

.new-note-form {
  display: grid;
  gap: 10px;
}

.compact-field-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.compact-field-label {
  font-weight: 600;
}

.compact-field-row input,
.compact-field-row select {
  width: 100%;
}

.attachment-section {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: #f9fcfe;
  display: grid;
  gap: 8px;
}

.attachment-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.attachment-upload-status {
  color: var(--muted);
  font-size: 0.85rem;
}

.attachment-upload-status.error {
  color: #8c1d3a;
}

.attachment-drop-zone {
  border: 2px dashed #9cc4d6;
  border-radius: 12px;
  background: #eef8fc;
  min-height: 74px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 10px;
  color: #1f5367;
  cursor: pointer;
}

.attachment-drop-zone p {
  margin: 0;
}

.attachment-drop-zone.dragover {
  border-color: var(--accent);
  background: #e3f2fa;
}

.attachment-drop-zone.disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.attachments-list {
  display: grid;
  gap: 8px;
}

.attachments-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.attachment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
}

.attachment-main {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.attachment-main strong,
.attachment-main span {
  overflow-wrap: anywhere;
}

@media (max-width: 640px) {
  .compact-field-row {
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 8px;
  }
}

.attachment-main span {
  color: var(--muted);
  font-size: 0.8rem;
}

.attachment-download-btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f3f9fc;
  color: var(--text);
  padding: 7px 10px;
  white-space: nowrap;
}

.attachment-download-btn:hover {
  background: #e3f2fa;
}

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

.attachment-preview-btn {
  border: 1px solid #b9d8e4;
  border-radius: 10px;
  background: #eef8fc;
  color: #1a5063;
  padding: 7px 10px;
  white-space: nowrap;
}

.attachment-preview-btn:hover {
  background: #e0f1f8;
}

.attachment-delete-btn {
  border: 1px solid #f2c5cf;
  border-radius: 10px;
  background: #fff1f4;
  color: var(--danger);
  padding: 7px 10px;
  white-space: nowrap;
}

.attachment-delete-btn:hover {
  background: #ffe1e8;
}

.attachment-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
}

.attachment-preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 33, 43, 0.45);
}

.attachment-preview-dialog {
  position: relative;
  width: min(1180px, calc(100vw - 32px));
  max-height: min(82vh, 760px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 50px rgba(10, 35, 52, 0.28);
  overflow: hidden;
}

.attachment-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: #f8fbfd;
}

.attachment-preview-head h4 {
  margin: 0;
}

.attachment-preview-body {
  padding: 16px;
  overflow: auto;
}

.attachment-preview-loading,
.attachment-preview-fallback {
  margin: 0;
  color: var(--muted);
}

.attachment-preview-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.9rem;
}

.attachment-preview-image {
  display: block;
  max-width: 100%;
  max-height: 65vh;
  margin: 0 auto;
}

.priority-inline-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
}

.priority-inline-label span {
  font-weight: 600;
}

.priority-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.priority-option {
  min-width: 40px;
  padding: 8px 12px;
  border-radius: 10px;
  background: #f7fbfd;
  color: var(--text);
  border: 1px solid var(--border);
}

.priority-option.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.editor-primary-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.upload-progress-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 70;
}

.upload-progress-modal.hidden {
  display: none;
}

.upload-progress-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 33, 43, 0.45);
}

.upload-progress-dialog {
  position: relative;
  width: min(400px, calc(100vw - 32px));
  display: grid;
  grid-template-rows: auto 1fr;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 50px rgba(10, 35, 52, 0.28);
  overflow: hidden;
}

.upload-progress-head {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}

.upload-progress-head h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.upload-progress-body {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.upload-progress-body p {
  margin: 0;
  font-size: 13px;
  color: var(--text);
  overflow-wrap: break-word;
  word-break: break-word;
}

.progress-bar-container {
  width: 100%;
  height: 8px;
  background: #e8eef5;
  border-radius: 8px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #2d8fcb);
  border-radius: 8px;
  transition: width 0.2s ease;
}

.notes-count {
  margin-top: 14px;
  margin-bottom: 8px;
  color: var(--muted);
  font-weight: 600;
}

.note-list {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}

.note-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(15, 31, 41, 0.08);
}

.note-card:hover {
  transform: translateY(-1px);
}

.note-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.note-card.archived {
  background: #e0e0e0;
}

.note-card h3 {
  margin-top: 0;
  margin-bottom: 8px;
}

.note-snippet {
  color: var(--muted);
  margin: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.note-meta {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.empty-state {
  grid-column: 1 / -1;
  background: #fff;
  border: 1px dashed var(--border);
  padding: 16px;
  border-radius: 14px;
  color: var(--muted);
}

.hidden {
  display: none;
}

@media (max-width: 880px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  #searchInput {
    width: 100%;
    min-width: 100%;
  }

  #newNoteBtn {
    justify-self: end;
  }

  .reader-panel {
    min-height: 58vh;
    max-height: 68vh;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 12px;
  }

  .note-list {
    grid-template-columns: 1fr;
  }

  .reader-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .priority-buttons {
    justify-content: flex-start;
  }

  .attachment-item {
    flex-direction: column;
    align-items: stretch;
  }

  .attachment-actions {
    justify-content: flex-end;
  }
}
