:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2733;
  --muted: #6b7a89;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #b91c1c;
  --border: #dde3ea;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* hidden attribute must always win over class display rules */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.2; }

/* ----- auth card ----- */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2.25rem;
  width: min(420px, 92vw);
  box-shadow: 0 10px 30px rgba(20, 35, 60, .08);
}

.auth-card h1 { margin-top: 0; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: .65rem 1.25rem;
}

.brand {
  font-weight: 700;
  color: var(--text);
  font-size: 1.05rem;
}
.brand:hover { text-decoration: none; }

nav { display: flex; align-items: center; gap: 1rem; }
nav a { color: var(--muted); font-weight: 500; }
nav a.active { color: var(--accent); }

#view { max-width: 860px; margin: 1.5rem auto; padding: 0 1rem; }

.page { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; }

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

/* ----- forms & buttons ----- */

label { display: block; margin: 1rem 0 .25rem; font-weight: 500; }

input[type="text"], input[type="password"] {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: .55rem 1.1rem;
  cursor: pointer;
}
button:hover { background: var(--accent-dark); }
button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button.secondary:hover { background: rgba(37, 99, 235, .08); }
button.linklike {
  background: none;
  color: var(--accent);
  padding: 0;
  border-radius: 0;
}
button.linklike:hover { text-decoration: underline; background: none; }

.btn-row { display: flex; gap: .75rem; margin-top: 1.25rem; }

/* ----- notes layout ----- */

.notes-page { padding: 0; overflow: hidden; }
.notes-layout {
  display: grid;
  grid-template-columns: 220px 260px 1fr;
  min-height: 60vh;
}
.sidebar {
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
}
.side-section h4 {
  margin: .75rem 0 .25rem;
  font-size: .8rem;
  text-transform: uppercase;
  color: var(--muted);
}
.side-list { list-style: none; margin: 0; padding: 0; }
.side-list li {
  padding: .25rem .5rem;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  font-size: .95rem;
}
.side-list li:hover { background: var(--bg); }
.side-list li.active { background: rgba(37, 99, 235, .12); color: var(--accent); }
.side-list li .count { color: var(--muted); font-size: .85rem; }
.inline-form { display: flex; gap: .35rem; margin-top: .35rem; }
.inline-form input { flex: 1; padding: .3rem .5rem; font-size: .85rem; }

button.mini { padding: .3rem .7rem; font-size: .85rem; }
button.primary { background: var(--accent); }
button.danger { background: var(--danger); }
button.danger:hover { background: #991b1b; }

.search-box { margin-bottom: .5rem; font-size: .9rem; }

.note-list-col { border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.note-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.note-list li {
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.note-list li:hover { background: var(--bg); }
.note-list li.active { background: rgba(37, 99, 235, .1); }
.note-list .nt { font-weight: 500; display: block; }
.note-list .nm { color: var(--muted); font-size: .8rem; }

.editor-pane { display: flex; flex-direction: column; }
.editor-toolbar {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.editor-toolbar input[type="text"],
.editor-toolbar select {
  width: 100%;
}
.editor-actions {
  display: flex;
  gap: .6rem;
}
#note-title {
  width: 100%;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  padding: .4rem .6rem;
  font-size: 1rem;
  color: var(--text);
}
.mini-select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .35rem .5rem;
  font-size: .85rem;
  background: var(--panel);
  color: var(--text);
}
input.tags-input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .35rem .5rem;
  font-size: .85rem;
  background: var(--panel);
  color: var(--text);
}
#note-title:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.editor-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 1;
  min-height: 55vh;
}
#note-body {
  border: none;
  resize: none;
  padding: 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .9rem;
  line-height: 1.6;
  border-right: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}
#note-body:focus { outline: none; }
.preview { padding: 1rem 1.25rem; overflow-y: auto; background: #fff; }

/* markdown rendering */
.md-body h1, .md-body h2, .md-body h3 { margin: .8em 0 .4em; }
.md-body pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: .75rem 1rem;
  border-radius: 8px;
  overflow-x: auto;
}
.md-body code { background: #eef2f7; border-radius: 4px; padding: .1em .35em; font-size: .9em; }
.md-body pre code { background: none; padding: 0; }
.md-body blockquote {
  margin: .6em 0; padding: .2em 1em; border-left: 4px solid var(--border); color: var(--muted);
}
.md-body img { max-width: 100%; }
.md-body table { border-collapse: collapse; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: .35rem .6rem; }

@media (max-width: 900px) {
  .notes-layout { grid-template-columns: 1fr; }
  .sidebar, .note-list-col { border-right: none; }
  .editor-split { grid-template-columns: 1fr; }
}

/* ----- files page ----- */

.files-page { padding: 1.5rem; }
.files-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.kind-tabs { display: flex; gap: .4rem; }
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.upload-btn {
  background: var(--accent);
  color: #fff;
  padding: .45rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
}
.upload-btn:hover { background: var(--accent-dark); }

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}
.file-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  position: relative;
}
.file-card:hover { border-color: var(--accent); }
.file-card img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  display: block;
  background: #e5e9f0;
}
.file-card .pdf-badge {
  height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  background: #fdf1f0;
  color: var(--danger);
}
.file-card .fc-name {
  padding: .5rem .7rem;
  font-size: .85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.file-card .fc-meta {
  padding: 0 .7rem .5rem;
  color: var(--muted);
  font-size: .75rem;
  display: flex;
  justify-content: space-between;
}
.file-card .fc-del {
  position: absolute;
  top: .4rem;
  right: .4rem;
  background: rgba(0,0,0,.55);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: .15rem .5rem;
  font-size: .75rem;
  display: none;
}
.file-card:hover .fc-del { display: block; }

.viewer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 25, .82);
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: 2.5rem 2rem 1rem;
}
.viewer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  margin-bottom: .75rem;
}
#viewer-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-actions { display: flex; gap: .5rem; }
#viewer-img {
  max-width: 100%;
  max-height: calc(100vh - 8rem);
  margin: 0 auto;
  background: #fff;
}
#viewer-pdf {
  background: #fff;
  margin: 0 auto;
  max-height: calc(100vh - 9rem);
  box-shadow: 0 4px 30px rgba(0,0,0,.5);
}
.pdf-nav { text-align: center; color: #fff; margin-top: .75rem; }
.pdf-nav button { margin: 0 .5rem; }

/* ----- misc ----- */

.muted { color: var(--muted); font-weight: 400; }

.msg {
  max-width: 860px;
  margin: 1rem auto;
  padding: .6rem 1rem;
  border-radius: 8px;
  display: none;
}
.msg.error { display: block; background: #fee2e2; color: var(--danger); }
.msg.ok { display: block; background: #dcfce7; color: #166534; }

.pk-table {
  width: 100%;
  border-collapse: collapse;
  margin: .5rem 0 1rem;
}
.pk-table th, .pk-table td {
  text-align: left;
  padding: .5rem .6rem;
  border-bottom: 1px solid var(--border);
  font-size: .95rem;
}
.pk-table th { color: var(--muted); font-weight: 600; }
