:root {
  color-scheme: dark;
  --header-h: 48px;
  --toolbar-h: 52px;
  --layers-h: 38px;
  --bg: #07090b;
  --panel: #11161b;
  --panel-2: #171d23;
  --line: #2c343c;
  --text: #e1e6eb;
  --muted: #8e9aa5;
  --accent: #55a9e8;
  --yellow: #ffe45c;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
button { color: inherit; }
.protocol-warning { position: fixed; z-index: 100; left: 50%; top: 16px; translate: -50% 0; width: min(620px, calc(100vw - 24px)); padding: 12px 14px; border: 1px solid #b88a22; border-radius: 5px; background: #33270d; color: #ffe8a3; box-shadow: 0 10px 28px #000a; text-align: center; }

.login-screen {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 30%, #182631 0, #090d11 45%, #050708 100%);
}
.login-card {
  width: min(380px, 100%);
  padding: 30px;
  border: 1px solid #34414c;
  border-radius: 10px;
  background: #11171ddd;
  box-shadow: 0 24px 70px #000b;
}
.login-mark { color: var(--accent); font-size: 40px; line-height: 1; }
.login-card h1 { margin: 12px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 24px; color: var(--muted); }
.login-card label { display: grid; gap: 7px; margin-top: 14px; color: #b9c3cc; }
.login-card input {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border: 1px solid #394650;
  border-radius: 5px;
  outline: 0;
  background: #090d11;
  color: var(--text);
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px #55a9e822; }
.login-error { min-height: 20px; margin-top: 10px; color: #ff8585; }
.login-button {
  width: 100%;
  height: 40px;
  margin-top: 4px;
  border: 0;
  border-radius: 5px;
  background: #3286c4;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.login-button:hover:not(:disabled) { background: #3d98d9; }
.login-button:disabled { opacity: .55; cursor: wait; }
.current-user { color: #aab5be; }
.logout-button { padding: 5px 9px; border: 1px solid #35404a; border-radius: 4px; background: transparent; cursor: pointer; }
.logout-button:hover { background: #222a31; }

.user-panel { position: fixed; z-index: 900; inset: 0; display: grid; place-items: center; padding: 20px; background: #000b; }
.user-card { width: min(820px, 100%); max-height: min(720px, calc(100vh - 40px)); overflow: auto; padding: 22px; border: 1px solid #394650; border-radius: 9px; background: #11171d; box-shadow: 0 24px 80px #000d; }
.user-panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.user-panel-header h2 { margin: 0; font-size: 20px; }
.user-panel-header p { margin: 4px 0 0; color: var(--muted); }
.panel-close { width: 32px; height: 32px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 25px; cursor: pointer; }
.panel-close:hover { background: #252d35; color: var(--text); }
.create-user-form { display: grid; grid-template-columns: 1fr 1fr 140px auto; align-items: end; gap: 10px; margin-top: 20px; padding: 14px; border: 1px solid #2d3740; border-radius: 6px; background: #0c1115; }
.create-user-form label { display: grid; gap: 5px; color: var(--muted); }
.create-user-form input, .create-user-form select, .user-row input, .user-row select { height: 34px; min-width: 0; padding: 0 8px; border: 1px solid #394650; border-radius: 4px; background: #171e24; color: var(--text); }
.user-panel-message { min-height: 24px; padding: 6px 2px 0; color: #ffbd65; }
.user-list { display: grid; gap: 7px; }
.user-row { display: grid; grid-template-columns: minmax(130px, 1fr) 130px minmax(150px, 1fr) auto auto; align-items: center; gap: 9px; padding: 10px; border: 1px solid #29333b; border-radius: 5px; background: #151b21; }
.user-identity { min-width: 0; }
.user-name { overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.user-created { margin-top: 2px; color: var(--muted); font-size: 11px; }
.user-row button { height: 32px; padding: 0 10px; border: 1px solid #3a4650; border-radius: 4px; background: #202830; cursor: pointer; }
.user-row button:hover:not(:disabled) { border-color: #5694bd; }
.user-row .danger-button { color: #ff9696; }
.user-row button:disabled { opacity: .4; cursor: default; }

@media (max-width: 760px) {
  .create-user-form, .user-row { grid-template-columns: 1fr; }
  .user-row { gap: 7px; }
  .current-user { display: none; }
}

.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px 0 14px;
  background: #0e1318;
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 15px; font-weight: 700; white-space: nowrap; }
.search-box {
  width: min(440px, 40vw);
  height: 32px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  background: #191f25;
  border: 1px solid #303943;
  border-radius: 5px;
}
.search-box:focus-within { border-color: #4b8dbb; }
.search-box span { color: var(--muted); font-size: 18px; }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); }
.library-status { margin-left: auto; color: var(--muted); white-space: nowrap; }

.icon-button {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  font-size: 19px;
  cursor: pointer;
  color: inherit;
  text-decoration: none;
}
.icon-button:hover:not(:disabled) { background: #222a31; border-color: #35404a; }
.icon-button:disabled { color: #56616a; cursor: default; }
.icon-button.disabled { color: #56616a; pointer-events: none; }

.app-shell {
  --sidebar-w: 400px;
  height: calc(100% - var(--header-h));
  display: grid;
  grid-template-columns: var(--sidebar-w) 8px minmax(0, 1fr) 244px;
  min-width: 0;
}
.sidebar, .inspector { min-width: 0; background: var(--panel); }
.sidebar { min-height: 0; overflow: hidden; border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.inspector { border-left: 1px solid var(--line); overflow-y: auto; }
.app-shell.sidebar-collapsed .sidebar { visibility: hidden; overflow: hidden; }

.sidebar-resizer {
  position: relative;
  z-index: 4;
  border-right: 1px solid #263039;
  border-left: 1px solid #1a2229;
  background: #0c1115;
  cursor: col-resize;
  touch-action: none;
}
.sidebar-resizer:hover,
.sidebar-resizer.dragging { background: #17232c; }
.sidebar-resizer button {
  position: absolute;
  top: 46%;
  left: 50%;
  width: 20px;
  height: 52px;
  translate: -50% -50%;
  padding: 0;
  border: 1px solid #394650;
  border-radius: 3px;
  background: #172028;
  color: #9eabb5;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.sidebar-resizer button:hover { border-color: #5287aa; background: #20303b; color: #e7edf2; }
body.resizing-sidebar { cursor: col-resize; user-select: none; }

.view-tabs { display: grid; grid-template-columns: repeat(3, 1fr); height: 42px; border-bottom: 1px solid var(--line); }
.tab-button { border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); cursor: pointer; }
.tab-button.active { color: var(--text); border-bottom-color: var(--accent); }
.category-row { height: 42px; display: flex; align-items: center; gap: 8px; padding: 0 10px; border-bottom: 1px solid var(--line); color: var(--muted); }
.category-row select, .focus-control select {
  min-width: 0;
  height: 28px;
  border: 1px solid #36414a;
  border-radius: 4px;
  background: #171e24;
  color: var(--text);
}
.category-row select { flex: 1; }
.type-tabs { height: 34px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.type-button { border: 1px solid transparent; border-radius: 3px; background: transparent; color: var(--muted); cursor: pointer; }
.type-button:hover { background: #1a2229; }
.type-button.active { border-color: #394650; background: #222c34; color: var(--text); }

.board-list { min-height: 0; flex: 1; overflow-y: auto; padding: 4px 0; }
.board-item {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 8px;
  padding: 9px 10px;
  border: 0;
  border-bottom: 1px solid #20272d;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.board-item:hover { background: #171e24; }
.board-item.active { background: #1c2730; box-shadow: inset 3px 0 var(--accent); }
.board-item:disabled { opacity: .5; cursor: default; }
.board-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-count { color: var(--muted); font-size: 11px; }
.board-subtitle { grid-column: 1 / -1; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-empty { padding: 22px 14px; color: var(--muted); text-align: center; }

.tree-folder,
.tree-board {
  width: 100%;
  min-width: 0;
  display: grid;
  align-items: center;
  border: 0;
  background: transparent;
  text-align: left;
}

.tree-folder {
  grid-template-columns: 14px 18px minmax(0, 1fr) auto;
  gap: 3px;
  height: 28px;
  padding: 0 8px 0 calc(8px + var(--level) * 16px);
  color: #d7dee5;
  cursor: pointer;
}

.tree-folder:hover,
.tree-board:hover { background: #171e24; }

.tree-caret {
  width: 14px;
  color: #87939d;
  font-size: 11px;
  text-align: center;
}

.tree-folder-icon {
  width: 14px;
  height: 11px;
  position: relative;
  display: inline-block;
  border-radius: 2px;
  background: #f5bd20;
  box-shadow: inset 0 -1px 0 #c69014;
}

.tree-folder-icon::before {
  content: "";
  position: absolute;
  left: 1px;
  top: -3px;
  width: 8px;
  height: 4px;
  border-radius: 2px 2px 0 0;
  background: #ffd65a;
}

.tree-folder.expanded .tree-folder-icon { background: #ffca35; }
.tree-folder-name,
.tree-board-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree-folder-count,
.tree-board-meta {
  color: var(--muted);
  font-size: 11px;
}

.tree-board {
  grid-template-columns: 18px minmax(0, 1fr) auto;
  gap: 5px;
  min-height: 26px;
  padding: 3px 8px 3px calc(26px + var(--level) * 16px);
  color: #c8d0d8;
  cursor: pointer;
}

.tree-board.active {
  background: #243140;
  color: #fff;
  box-shadow: inset 3px 0 var(--accent);
}

.tree-board:disabled {
  color: #67727b;
  cursor: default;
}

.tree-file-icon {
  width: 13px;
  height: 15px;
  position: relative;
  display: inline-block;
  border: 1px solid #5fa8e8;
  border-radius: 2px;
  background: linear-gradient(180deg, #244b76, #173554);
}

.tree-file-icon::after {
  content: "";
  position: absolute;
  right: -1px;
  top: -1px;
  border-width: 0 0 5px 5px;
  border-style: solid;
  border-color: transparent transparent #78b9ed transparent;
}

.tree-file-icon.unavailable {
  border-color: #747d86;
  background: #2a3036;
}
.tree-file-icon.pdf { border-color: #d85d62; background: linear-gradient(180deg, #7b3034, #542126); }
.tree-file-icon.pdf::after { border-color: transparent transparent #f28a8e transparent; }

.reader { min-width: 0; display: grid; grid-template-rows: var(--toolbar-h) var(--layers-h) minmax(0, 1fr); background: #050607; }
.board-toolbar { display: flex; align-items: center; gap: 12px; padding: 0 10px 0 14px; background: #10161b; border-bottom: 1px solid var(--line); }
.board-heading { min-width: 0; display: flex; flex-direction: column; }
.board-heading strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.board-heading span { color: var(--muted); font-size: 11px; white-space: nowrap; }
.tool-actions { margin-left: auto; display: flex; align-items: center; gap: 5px; }
.focus-control { display: flex; align-items: center; gap: 6px; color: var(--muted); white-space: nowrap; }
.focus-control select { width: 112px; }
.layer-bar { display: flex; align-items: center; gap: 9px; padding: 0 10px; overflow-x: auto; background: #0e1419; border-bottom: 1px solid var(--line); white-space: nowrap; }
.layer-toggle { display: inline-flex; align-items: center; gap: 4px; color: #b9c2ca; cursor: pointer; font-size: 12px; }
.layer-toggle input { margin: 0; }
.layer-swatch { width: 9px; height: 9px; border-radius: 2px; }

.canvas-wrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#boardCanvas { display: block; width: 100%; height: 100%; cursor: grab; }
#boardCanvas.dragging { cursor: grabbing; }
.pdf-frame { width: 100%; height: 100%; display: block; border: 0; background: #252a2e; }
.document-mode-label { color: #aab5be; font-size: 12px; }
.empty-state, .loading-state, .pdf-protected-state { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 6px; background: #050607; color: var(--muted); }
.empty-state strong { color: #c6ced5; font-size: 15px; }
.pdf-protected-state { gap: 10px; padding: 24px; text-align: center; }
.pdf-protected-state strong { color: #dfe7ee; font-size: 17px; }
.pdf-protected-state .command-button { display: inline-flex; align-items: center; margin-top: 5px; color: #fff; text-decoration: none; }
.hidden { display: none !important; }

.inspector-section { padding: 13px 12px; border-bottom: 1px solid var(--line); }
.section-title { margin-bottom: 10px; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.selection-value { margin-bottom: 10px; color: var(--yellow); font-weight: 600; }
.detail-list { margin: 0; }
.detail-list div { min-height: 28px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border-bottom: 1px solid #20272d; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.edit-section label { display: grid; gap: 5px; margin: 9px 0; color: var(--muted); }
.edit-section input { width: 100%; height: 31px; padding: 0 8px; border: 1px solid #35404a; border-radius: 4px; background: #0c1115; color: var(--text); }
.command-button { height: 32px; padding: 0 14px; border: 1px solid #397aa8; border-radius: 4px; background: #1e6898; color: white; cursor: pointer; }

.toast { position: fixed; left: 50%; bottom: 22px; translate: -50% 0; padding: 9px 13px; border: 1px solid #45515b; border-radius: 5px; background: #20282f; box-shadow: 0 8px 24px #0009; z-index: 20; }
.mobile-only { display: none; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: var(--sidebar-w) 8px minmax(0, 1fr); }
  .inspector { display: none; }
}

@media (max-width: 720px) {
  .mobile-only { display: inline-grid; }
  .app-header { padding-left: 7px; gap: 6px; }
  .brand { display: none; }
  .search-box { width: auto; flex: 1; }
  .library-status { display: none; }
  .app-shell { display: block; position: relative; }
  .app-shell.sidebar-collapsed .sidebar { visibility: visible; }
  .sidebar { position: absolute; inset: 0 auto 0 0; width: min(86vw, 380px); z-index: 10; box-shadow: 12px 0 32px #000b; transform: translateX(-105%); transition: transform .18s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-resizer { display: none; }
  .reader { width: 100%; height: 100%; }
  .board-toolbar { padding-left: 9px; }
  .focus-control { display: none; }
  .board-heading span { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
}
