:root{
  --bg:#F0F2F6;
  --surface:#FFFFFF;
  --border:#E4E7EC;
  --text:#1B1D23;
  --text-muted:#6B7280;
  --accent:#4F46E5;
  --accent-soft:#EEF0FF;
  --danger:#DC2626;
  --danger-soft:#FEE2E2;
  --radius:10px;
  --shadow:0 1px 2px rgba(16,24,40,0.04), 0 2px 8px rgba(16,24,40,0.06);
  --font-display:'Space Grotesk', system-ui, sans-serif;
  --font-body:'Inter', system-ui, -apple-system, sans-serif;
}

:root[data-theme="dark"]{
  --bg:#15161B;
  --surface:#1D1F26;
  --border:#2B2E37;
  --text:#E7E9EE;
  --text-muted:#8B90A0;
  --accent:#8B87F0;
  --accent-soft:#2A2A45;
  --danger:#F87171;
  --danger-soft:#3A2020;
  --shadow:0 1px 2px rgba(0,0,0,0.25), 0 2px 8px rgba(0,0,0,0.3);
}

*{box-sizing:border-box;}

html,body{
  margin:0;
  padding:0;
  background:var(--bg);
  color:var(--text);
  font-family:var(--font-body);
  min-height:100vh;
  transition:background .15s ease, color .15s ease;
}

.topbar{
  position:sticky;
  top:0;
  z-index:20;
  display:flex;
  align-items:center;
  gap:14px;
  padding:9px 18px;
  background:var(--bg);
  border-bottom:1px solid var(--border);
}

.brand{
  display:flex;
  align-items:center;
  gap:7px;
  flex-shrink:0;
}
.brand-mark{
  color:var(--accent);
  font-size:18px;
}
.brand h1{
  font-family:var(--font-display);
  font-size:16px;
  font-weight:600;
  letter-spacing:-0.01em;
  margin:0;
}

.search-wrap{
  position:relative;
  flex:1;
  max-width:380px;
}
.search-icon{
  position:absolute;
  left:10px;
  top:50%;
  transform:translateY(-50%);
  color:var(--text-muted);
  pointer-events:none;
}
#search{
  width:100%;
  padding:6px 10px 6px 30px;
  border-radius:999px;
  border:1px solid var(--border);
  background:var(--surface);
  font-family:var(--font-body);
  font-size:13.5px;
  color:var(--text);
  outline:none;
  transition:box-shadow .15s ease, border-color .15s ease;
}
#search:focus{
  border-color:var(--accent);
  box-shadow:0 0 0 3px var(--accent-soft);
}

.topbar-actions{
  display:flex;
  align-items:center;
  gap:6px;
  margin-left:auto;
  flex-shrink:0;
}

.save-indicator{
  font-size:11.5px;
  color:var(--text-muted);
  min-width:50px;
  text-align:right;
}

.btn-primary, .btn-ghost{
  font-family:var(--font-body);
  font-size:12.5px;
  font-weight:500;
  border-radius:7px;
  padding:6px 10px;
  cursor:pointer;
  border:1px solid transparent;
  transition:background .15s ease, border-color .15s ease, transform .05s ease;
  white-space:nowrap;
}
.btn-primary{
  background:var(--accent);
  color:#fff;
}
.btn-primary:hover{ filter:brightness(0.92); }
.btn-ghost{
  background:transparent;
  color:var(--text);
  border-color:var(--border);
}
.btn-ghost:hover{ background:var(--surface); }
.btn-primary:active, .btn-ghost:active{ transform:scale(0.97); }

.icon-btn{
  display:flex;
  align-items:center;
  justify-content:center;
  width:30px;
  height:30px;
  padding:0;
  border-radius:7px;
  border:1px solid var(--border);
  background:transparent;
  color:var(--text);
  cursor:pointer;
  font-size:14px;
  flex-shrink:0;
}
.icon-btn:hover{ background:var(--surface); }

.column-count-control{
  display:flex;
  align-items:center;
  gap:4px;
  flex-shrink:0;
}
.column-count-control .icon-btn{ width:26px; height:26px; font-size:13px; }
.column-count-control span{
  font-size:12px;
  color:var(--text-muted);
  min-width:14px;
  text-align:center;
}

.board{
  padding:12px 14px 30px;
}

#board{
  display:flex;
  flex-direction:row;
  align-items:flex-start;
  gap:10px;
  overflow-x:auto;
}
.board-column{
  display:flex;
  flex-direction:column;
  align-items:flex-start;
  gap:10px;
  flex-shrink:0;
  min-height:400px;
  min-width:180px;
}

.category{
  width:236px;
  min-width:180px;
  max-width:420px;
  background:var(--surface);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  border:1px solid var(--border);
  display:flex;
  flex-direction:column;
  flex-shrink:0;
}

.category.drag-ghost{
  opacity:0.4;
}

.category-head{
  display:flex;
  align-items:center;
  gap:6px;
  padding:9px 8px 7px 7px;
  position:relative;
  border-bottom:1px solid var(--border);
}

.cat-handle{
  cursor:grab;
  color:var(--text-muted);
  opacity:0;
  transition:opacity .12s ease;
  font-size:12px;
  line-height:1;
}
.category-head:hover .cat-handle{ opacity:0.6; }
.cat-handle:active{ cursor:grabbing; }

.cat-title{
  font-family:var(--font-display);
  font-size:13.5px;
  font-weight:600;
  margin:0;
  flex:1;
  outline:none;
  border-radius:4px;
  padding:1px 4px;
  margin-left:-4px;
}
.cat-title:hover, .cat-title:focus{
  background:var(--accent-soft);
}
.cat-title[contenteditable="true"]{
  background:var(--accent-soft);
  cursor:text;
}

.cat-menu-wrap{ position:relative; }
.cat-menu-btn{
  background:none;
  border:none;
  color:var(--text-muted);
  font-size:15px;
  cursor:pointer;
  padding:1px 5px;
  border-radius:6px;
  line-height:1;
}
.cat-menu-btn:hover{ background:var(--bg); }

.cat-menu{
  display:none;
  position:absolute;
  right:0;
  top:24px;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:9px;
  box-shadow:var(--shadow);
  padding:6px;
  min-width:180px;
  z-index:30;
}
.cat-menu.open{ display:block; }
.cat-menu button{
  display:block;
  width:100%;
  text-align:left;
  background:none;
  border:none;
  font-family:var(--font-body);
  font-size:12.5px;
  padding:6px 7px;
  border-radius:6px;
  cursor:pointer;
  color:var(--text);
}
.cat-menu button:hover{ background:var(--bg); }
.cat-menu button.danger{ color:var(--danger); }
.cat-menu hr{ border:none; border-top:1px solid var(--border); margin:4px 0; }

.cat-menu-width{
  display:flex;
  align-items:center;
  gap:6px;
  padding:4px 7px;
  font-size:12px;
  color:var(--text-muted);
}
.cat-menu-width span:first-child{ flex:1; }
.cat-menu-width .cat-width-val{
  min-width:44px;
  text-align:center;
  color:var(--text);
  font-size:11.5px;
}
.cat-menu-width button{
  display:flex;
  align-items:center;
  justify-content:center;
  width:22px;
  height:22px;
  padding:0;
  border:1px solid var(--border);
  border-radius:6px;
  background:var(--bg);
  color:var(--text);
  cursor:pointer;
  font-size:13px;
}
.cat-menu-width button:hover{ border-color:var(--accent); color:var(--accent); }

.link-list{
  list-style:none;
  margin:0;
  padding:2px 4px 10px;
  min-height:6px;
}

.link-row{
  display:flex;
  align-items:center;
  gap:7px;
  padding:3px 5px;
  border-radius:7px;
  position:relative;
}
.link-row:hover{ background:var(--bg); }
.link-row.sortable-ghost{
  background:var(--accent-soft);
  opacity:0.7;
}

.link-handle{
  color:var(--text-muted);
  font-size:11px;
  opacity:0;
  cursor:grab;
  flex-shrink:0;
  transition:opacity .12s ease;
}
.link-row:hover .link-handle{ opacity:0.5; }

.link-favicon{
  flex-shrink:0;
  border-radius:3px;
  background:var(--bg);
}

.link-title{
  flex:1;
  min-width:0;
  display:flex;
  align-items:center;
  gap:7px;
  color:var(--text);
  text-decoration:none;
}
.link-title-text{
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  font-size:13px;
}
.link-title:hover .link-title-text{ color:var(--accent); text-decoration:underline; }

/* Link Menu */
.link-menu-wrap {
  position: relative;
  flex-shrink: 0;
}
.link-menu-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  padding: 1px 6px;
  border-radius: 5px;
  opacity: 0;
  transition: opacity .12s ease, background .12s ease;
  line-height: 1;
}
.link-row:hover .link-menu-btn { opacity: 1; }
.link-menu-btn:hover { background: var(--surface); color: var(--text); }

.link-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 140px;
  z-index: 30;
}
.link-menu.open { display: block; }
.link-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font-family: var(--font-body);
  font-size: 12.5px;
  padding: 6px 7px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}
.link-menu button:hover { background: var(--bg); }
.link-menu button.danger { color: var(--danger); }
.link-menu hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

.link-row.editing .link-title { display:none; }
.link-row.editing .link-menu-wrap,
.link-row.editing .link-handle,
.link-row.editing .link-favicon { display:none; }

.edit-inputs{
  display:none;
  flex-direction:column;
  gap:4px;
  flex:1;
  min-width:0;
}
.link-row.editing .edit-inputs{ display:flex; }
.edit-inputs input{
  width:100%;
  min-width:0;
  font-size:12.5px;
  font-family:var(--font-body);
  border:1px solid var(--border);
  border-radius:6px;
  padding:4px 6px;
  outline:none;
  background:var(--surface);
  color:var(--text);
}
.edit-inputs input:focus{ border-color:var(--accent); }

/* Icon-search popover */
.icon-search-popover{
  position:absolute;
  top:100%;
  left:0;
  right:0;
  margin-top:4px;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:10px;
  box-shadow:var(--shadow);
  padding:8px;
  z-index:40;
  min-width:250px;
}
.icon-search-popover input{
  width:100%;
  padding:5px 8px;
  font-size:12.5px;
  border:1px solid var(--border);
  border-radius:6px;
  outline:none;
  background:var(--bg);
  color:var(--text);
  margin-bottom:6px;
}
.icon-search-popover input:focus{ border-color:var(--accent); }
.icon-search-results{
  display:grid;
  grid-template-columns:repeat(6, 1fr);
  gap:4px;
  max-height:140px;
  overflow-y:auto;
}
.icon-search-results button{
  display:flex;
  align-items:center;
  justify-content:center;
  padding:4px;
  border:1px solid var(--border);
  border-radius:6px;
  background:var(--bg);
  cursor:pointer;
}
.icon-search-results button:hover{ border-color:var(--accent); }
.icon-search-results img{ width:18px; height:18px; }
.icon-search-status{ font-size:11.5px; color:var(--text-muted); padding:4px 2px; }
.icon-search-reset{
  display:block;
  width:100%;
  text-align:center;
  margin-top:6px;
  font-size:11.5px;
  color:var(--text-muted);
  background:none;
  border:none;
  cursor:pointer;
  padding:4px;
}
.icon-search-reset:hover{ color:var(--accent); }

.category.new-category input.cat-title-input{
  font-family:var(--font-display);
  font-size:13.5px;
  font-weight:600;
  border:none;
  outline:none;
  width:100%;
  background:transparent;
  color:var(--text);
}

.link-row.is-hidden, .category.is-hidden{ display:none !important; }

/* ---------- Icon-grid view mode (per category) ---------- */

.category.icon-mode .link-list{
  display:flex;
  flex-wrap:wrap;
  gap:12px;
  padding:14px;
  justify-content:center;
}
.category.icon-mode .link-row{
  width:56px;
  height:56px;
  padding:0;
  justify-content:center;
  cursor:grab;
}
.category.icon-mode .link-handle{ display:none; }
.category.icon-mode .link-favicon{ width:44px; height:44px; }
.category.icon-mode .link-title{ display:flex; }
.category.icon-mode .link-title-text{ display:none; }

.category.icon-mode .link-menu-wrap {
  position: absolute;
  top: -6px;
  right: -6px;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.category.icon-mode .link-row:hover .link-menu-wrap {
  opacity: 1;
}
.category.icon-mode .link-menu-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 5px;
  border-radius: 5px;
  font-size: 13px;
}
.category.icon-mode .link-menu {
  top: 24px;
  right: -6px;
}

.category.icon-mode .edit-inputs{ display:none !important; }
.category.icon-mode .link-row.editing{ width:auto; height:auto; }
.category.icon-mode .link-row.editing .edit-inputs{ display:flex !important; }
.category.icon-mode .link-row.editing .link-favicon{ display:none; }

/* ---------- Widgets ---------- */

.widget-card{ width:250px; }
.widget-body{ padding:10px 12px 14px; font-size:13px; }

.weather-main-link{
  display:flex;
  align-items:center;
  gap:10px;
  text-decoration:none;
  color:var(--text);
}
.weather-main-link:hover .weather-temp{ color:var(--accent); }
.weather-body img.weather-icon{ width:44px; height:44px; }
.weather-body .weather-temp{ font-size:26px; font-weight:600; font-family:var(--font-display); line-height:1; transition:color .1s ease; }
.weather-body .weather-desc{ color:var(--text-muted); font-size:12px; text-transform:capitalize; }
.weather-body .weather-meta{ margin-top:8px; color:var(--text-muted); font-size:11.5px; display:flex; gap:10px; flex-wrap:wrap; }

.weather-row-label{ font-size:10.5px; color:var(--text-muted); margin:10px 0 4px; text-transform:uppercase; letter-spacing:.03em; }
.weather-hourly, .weather-daily{
  display:flex;
  gap:8px;
  overflow-x:auto;
  padding-bottom:2px;
}
.weather-hourly::-webkit-scrollbar, .weather-daily::-webkit-scrollbar{ height:4px; }
.wh-item, .wd-item{
  flex-shrink:0;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:2px;
  min-width:36px;
  font-size:10.5px;
  color:var(--text-muted);
}
.wh-item img, .wd-item img{ width:22px; height:22px; }
.wh-item span:last-child, .wd-item span:last-child{ font-size:11px; color:var(--text); font-weight:500; }

.weather-set-city{
  display:flex; gap:6px; margin-top:8px;
}
.weather-set-city input{
  flex:1; padding:5px 7px; font-size:12px; border:1px solid var(--border); border-radius:6px; outline:none; background:var(--bg); color:var(--text);
}
.weather-set-city button{
  border:none; background:var(--accent); color:#fff; border-radius:6px; padding:5px 9px; font-size:12px; cursor:pointer;
}
.weather-status{ color:var(--text-muted); font-size:12px; }

.notes-body textarea{
  width:100%;
  min-height:150px;
  resize:vertical;
  border:1px solid var(--border);
  border-radius:8px;
  padding:8px;
  font-family:var(--font-body);
  font-size:12.5px;
  outline:none;
  background:var(--bg);
  color:var(--text);
}
.notes-body textarea:focus{ border-color:var(--accent); }

/* ---------- Admin ---------- */

.admin-modal-backdrop{
  position:fixed; inset:0;
  background:rgba(0,0,0,0.35);
  display:flex; align-items:center; justify-content:center;
  z-index:100;
}
.admin-modal{
  background:var(--surface);
  border-radius:12px;
  padding:20px;
  width:280px;
  box-shadow:var(--shadow);
}
.admin-modal h3{ margin:0 0 10px; font-size:14px; font-family:var(--font-display); }
.admin-modal input{
  width:100%;
  padding:7px 9px;
  font-size:13px;
  border:1px solid var(--border);
  border-radius:7px;
  outline:none;
  background:var(--bg);
  color:var(--text);
  margin-bottom:8px;
}
.admin-modal input:focus{ border-color:var(--accent); }
.admin-modal .admin-modal-actions{ display:flex; gap:8px; justify-content:flex-end; }
.admin-modal .admin-error{ color:var(--danger); font-size:12px; margin-bottom:6px; min-height:14px; }

.add-link-modal .admin-modal{ width:300px; }
.add-link-modal select{
  width:100%;
  padding:7px 9px;
  font-size:13px;
  border:1px solid var(--border);
  border-radius:7px;
  outline:none;
  background:var(--bg);
  color:var(--text);
  margin-bottom:8px;
}

@media (max-width:480px){
  .topbar{ flex-wrap:wrap; }
  .search-wrap{ order:3; max-width:none; width:100%; }
  .category{ width:100%; }
}
