/* Cog UI — vanilla CSS */

/* Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #f5f5f5;
  --color-bg-muted: #dddddd;
  --color-surface: #ffffff;
  --color-primary: #0070f3;
  --color-primary-hover: #005cc5;
  --color-danger: #dc3545;
  --color-danger-hover: #c82333;
  --color-text: #1a1a1a;
  --color-text-muted: #666666;
  --color-border: #e0e0e0;
  --color-success: #28a745;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

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

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

/* Navbar */
.navbar {
  display: flex;
  align-items: center;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 1rem;
  height: 56px;
  box-shadow: var(--shadow);
  position: relative;
  z-index: 10;
}

.navbar-brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--color-text);
  margin-right: 1rem;
  white-space: nowrap;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.navbar-brand:hover {
  text-decoration: none;
}

.navbar-nav {
  display: flex;
  list-style: none;
  gap: 0.125rem;
  overflow: hidden;
  flex-shrink: 1;
  min-width: 0;
}

.navbar-nav a {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.5rem;
  border-radius: var(--radius);
  color: var(--color-text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.nav-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.navbar-nav a:hover {
  background: var(--color-bg);
  color: var(--color-text);
  text-decoration: none;
}

.navbar-nav a.active {
  color: var(--color-primary);
  font-weight: 500;
}

.navbar-search {
  position: relative;
  flex: 1;
  max-width: 280px;
  min-width: 0;
  margin: 0 0.5rem;
}

.search-input {
  height: 36px;
  padding: 0.25rem 0.75rem;
  font-size: 0.85rem;
}

.search-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  max-height: 400px;
  overflow-y: auto;
  z-index: 200;
  margin-top: 4px;
}

.navbar-search:focus-within .search-results:not(:empty) {
  display: block;
}

.search-section {
  padding: 0.4rem 0.75rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
}

.search-hit {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  color: var(--color-text);
  font-size: 0.85rem;
  cursor: pointer;
}

.search-hit:hover,
.search-hit-active {
  background: var(--color-bg);
  text-decoration: none;
}

.search-hit-name {
  font-weight: 500;
}

.search-hit-sub {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  margin-left: auto;
}

.search-empty {
  padding: 0.75rem;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.navbar-end {
  margin-left: auto;
  position: relative;
  flex-shrink: 0;
}

/* User dropdown */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--color-text);
}

.dropdown-toggle:hover {
  background: var(--color-bg);
}

.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  min-width: 160px;
  z-index: 100;
  overflow: hidden;
}

.dropdown:focus-within .dropdown-menu,
.dropdown-menu:hover {
  display: block;
}

.dropdown-menu a,
.dropdown-menu button {
  display: block;
  width: 100%;
  padding: 0.5rem 1rem;
  text-align: left;
  border: none;
  background: none;
  font-size: 0.9rem;
  color: var(--color-text);
  cursor: pointer;
}

.dropdown-menu a:hover,
.dropdown-menu button:hover {
  background: var(--color-bg);
  text-decoration: none;
}

.dropdown-divider {
  border-top: 1px solid var(--color-border);
  margin: 0.25rem 0;
}

/* Content area */
.content {
  max-width: 960px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 500;
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
}

.form-control {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.5;
  background: var(--color-surface);
  color: var(--color-text);
}

.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(0, 112, 243, 0.15);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.5;
  gap: 0.5rem;
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}
.btn-primary:hover {
  background: var(--color-primary-hover);
}

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

.btn-outline {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn-outline:hover {
  background: var(--color-bg);
}

.btn-secondary {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn-secondary:hover {
  background: var(--color-bg);
}

.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.btn-star {
  border: none;
  background: none;
  cursor: pointer;
  padding: 0 0.15rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}
.btn-star svg {
  fill: none;
  stroke: var(--color-text-muted);
}
.btn-star.active svg {
  fill: gold;
  stroke: gold;
}
.btn-star.active:hover svg {
  opacity: 0.8;
}

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.table th {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table tr:hover td {
  background: var(--color-bg);
}

/* Alerts */
.alert {
  padding: 0.75rem 2rem 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
  position: relative;
}

.alert-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.alert-error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.alert-dismiss {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  padding: 0 0.25rem;
}

.alert-dismiss:hover {
  opacity: 1;
}

/* Utilities */
.text-muted {
  color: var(--color-text-muted);
}
.text-right {
  text-align: right;
}
.mb-0 {
  margin-bottom: 0;
}
.mb-1 {
  margin-bottom: 0.5rem;
}
.mb-2 {
  margin-bottom: 1rem;
}
.mt-1 {
  margin-top: 0.5rem;
}
.mt-2 {
  margin-top: 1rem;
}
.flex {
  display: flex;
}
.items-center {
  align-items: center;
}
.justify-between {
  justify-content: space-between;
}
.gap-1 {
  gap: 0.5rem;
}

/* Login page */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 2rem;
}

.login-title {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
}

/* Checkbox */
.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-check input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-admin {
  background: #e3f2fd;
  color: #1565c0;
}

.badge-danger {
  background: #f8d7da;
  color: #721c24;
}

.badge-warn {
  background: #fff3cd;
  color: #856404;
}

.badge-overdue {
  background: #f8d7da;
  color: #721c24;
}

.badge-due-soon {
  background: #fff3cd;
  color: #856404;
}

/* Avatars */
.avatar-sm {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
}
.avatar-lg {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
}

/* App grid (dashboard) */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.app-card {
  text-align: center;
  padding: 1.5rem;
  color: var(--color-text);
  transition: border-color 0.15s;
}

.app-card:hover {
  border-color: var(--color-primary);
  text-decoration: none;
}

.app-icon svg {
  width: 36px;
  height: 36px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-card-label {
  font-weight: 600;
  font-size: 1.1rem;
}

/* Sidebar layout */
.sidebar-layout {
  display: flex;
  gap: 2rem;
}

.sidebar {
  flex-shrink: 0;
  width: 200px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-item {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.sidebar-item:hover {
  background: var(--color-bg);
  color: var(--color-text);
  text-decoration: none;
}

.sidebar-item.active {
  background: var(--color-bg);
  color: var(--color-primary);
  font-weight: 500;
}

.sidebar-content {
  flex: 1;
  min-width: 0;
}

/* Dropdown active */
.dropdown-menu a.active {
  color: var(--color-primary);
  font-weight: 500;
}

/* Text color utilities */
.text-danger {
  color: var(--color-danger);
}
.text-success {
  color: var(--color-success);
}

/* Sidebar text overflow gradient */
.sidebar-item-text {
  overflow: hidden;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
  mask-image: linear-gradient(to right, black calc(100% - 16px), transparent);
  -webkit-mask-image: linear-gradient(
    to right,
    black calc(100% - 16px),
    transparent
  );
}

/* Spinner for pending feeds */
.spinner-sm {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* RSS item styles */
.rss-item {
  transition: background 0.1s;
}
.rss-item-read {
  background-color: var(--color-bg-muted);
}

.rss-item-detail {
  padding: 1rem;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

.rss-item-preview-img {
  max-width: 200px;
  max-height: 150px;
  object-fit: cover;
  border-radius: var(--radius);
  float: right;
  margin: 0 0 0.5rem 1rem;
}

.rss-item-summary {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.rss-item-summary-line {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.rss-item-content {
  font-size: 0.9rem;
  line-height: 1.6;
  overflow: hidden;
  word-break: break-word;
}

.rss-item-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

/* Sidebar folders (collapsible) */
.sidebar-folder {
  margin: 0;
}

.sidebar-folder > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.25rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--color-text-muted);
  user-select: none;
}

.sidebar-folder > summary::-webkit-details-marker {
  display: none;
}

.sidebar-folder > summary::before {
  content: "\25B6";
  display: inline-block;
  font-size: 0.6rem;
  margin-right: 0.4rem;
  transition: transform 0.15s;
}

.sidebar-folder[open] > summary::before {
  transform: rotate(90deg);
}

.rss-item-active {
  border-left: 3px solid var(--color-primary);
}

/* Apps dropdown — hidden by default, shown at smallest breakpoint */
.navbar-apps-dropdown {
  display: none;
}

.apps-toggle {
  padding: 0.4rem;
  border: none;
  background: none;
}

.apps-toggle:hover {
  background: var(--color-bg);
  border-radius: var(--radius);
}

.apps-menu {
  min-width: 180px;
  left: 0;
  right: auto;
}

.apps-menu a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.apps-menu .nav-icon {
  width: 16px;
  height: 16px;
}

/* Navbar collapse stages — driven by JS based on item count + available width */

/* Stage 1: Labels below icons (compact) */
.navbar--compact .navbar-nav a {
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.7rem;
  padding: 0.35rem 0.4rem;
}
.navbar--compact .nav-label {
  font-size: 0.65rem;
}

/* Stage 2: Icons only */
.navbar.navbar--icon-only {
  padding: 0 0.5rem;
}
.navbar--icon-only .navbar-brand {
  margin-right: 0.5rem;
  font-size: 1rem;
}
.navbar--icon-only .navbar-nav {
  gap: 0;
}
.navbar--icon-only .navbar-nav a {
  flex-direction: row;
  padding: 0.5rem;
}
.navbar--icon-only .nav-label {
  display: none;
}
.navbar--icon-only .navbar-search {
  max-width: 140px;
  margin: 0 0.25rem;
}
.navbar--icon-only .dropdown-username {
  display: none;
}
.navbar--icon-only .dropdown-caret {
  display: none;
}

/* Stage 3: Apps dropdown replaces nav */
.navbar--collapsed .navbar-nav {
  display: none;
}
.navbar--collapsed .navbar-apps-dropdown {
  display: inline-block;
}
.navbar--collapsed .navbar-search {
  display: none;
}
.navbar--collapsed .brand-text {
  display: none;
}
.navbar--collapsed .dropdown-username {
  display: none;
}
.navbar--collapsed .dropdown-caret {
  display: none;
}

/* Guarantee icon-only at tablet sizes regardless of JS timing */
@media (max-width: 768px) {
  .navbar {
    padding: 0 0.5rem;
  }
  .navbar-brand {
    margin-right: 0.5rem;
    font-size: 1rem;
  }
  .navbar-nav {
    gap: 0;
  }
  .navbar-nav a {
    flex-direction: row;
    padding: 0.5rem;
  }
  .nav-label {
    display: none;
  }
  .navbar-search {
    max-width: 140px;
    margin: 0 0.25rem;
  }
  .dropdown-username {
    display: none;
  }
  .dropdown-caret {
    display: none;
  }
}

/* Guarantee at least icon-only at phone sizes regardless of JS timing.
   JS upgrades to collapsed when there are too many items to fit as icons. */
@media (max-width: 480px) {
  .navbar {
    padding: 0 0.5rem;
  }
  .navbar-nav {
    gap: 0;
  }
  .navbar-nav a {
    flex-direction: row;
    padding: 0.5rem;
  }
  .nav-label {
    display: none;
  }
  .navbar-search {
    display: none;
  }
  .brand-text {
    display: none;
  }
  .dropdown-username {
    display: none;
  }
  .dropdown-caret {
    display: none;
  }
}

/* Non-navbar mobile layout — still viewport-based */
@media (max-width: 768px) {
  .sidebar-layout {
    flex-direction: column;
    gap: 1rem;
  }
  .sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar::-webkit-scrollbar {
    display: none;
  }
  .sidebar-content {
    overflow-x: auto;
  }

  .content {
    padding: 0 0.75rem;
    margin: 1rem auto;
  }

  /* Compact dashboard app grid */
  .app-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding-bottom: 0.25rem;
  }
  .app-grid .app-card {
    flex-shrink: 0;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
  }
  .app-grid .app-card > div:first-child {
    margin-bottom: 0;
  }
  .app-icon svg {
    width: 20px;
    height: 20px;
  }

  /* Force widget grid to single column */
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Hide less-important columns */
  .hide-mobile {
    display: none;
  }
}

/* Share link */
.share-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Picker (user/group search) */
.picker {
  position: relative;
}
.picker-input {
  width: 100%;
}
.picker-results {
  position: absolute;
  z-index: 50;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: none;
}
.picker-results:not(:empty) {
  display: block;
}
.picker-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
}
.picker-option:hover,
.picker-option.active {
  background: var(--color-bg);
}
.picker-option-name {
  font-weight: 500;
}
.picker-option-sub {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}
.picker-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.25rem;
}
.picker-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.15rem 0.5rem;
  font-size: 0.85rem;
}
.picker-chip button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}

/* Notification badge */
.notif-badge {
  position: absolute;
  top: -4px;
  right: 0;
  background: var(--color-danger, #e53935);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* Modal overlay + content */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-content {
  background: var(--color-bg, #fff);
  border-radius: 8px;
  padding: 1.5rem;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

/* Thumbnail loading placeholder */
.thumb-loading {
  background: linear-gradient(
    110deg,
    var(--color-bg) 30%,
    var(--color-border) 50%,
    var(--color-bg) 70%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: zoom-in;
}
.lightbox.lightbox-full {
  overflow: auto;
  align-items: flex-start;
  justify-content: flex-start;
}
.lightbox.lightbox-full img {
  max-width: none;
  max-height: none;
  object-fit: initial;
  cursor: zoom-out;
}
.lightbox-close {
  position: fixed;
  top: 1rem;
  right: 1rem;
  background: rgba(0, 0, 0, 0.6);
  border: none;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  z-index: 1001;
}

/* Face box hover */
.face-box {
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 2px;
  pointer-events: auto;
  opacity: 0;
  transition: opacity 0.2s;
}
.face-container:hover .face-box {
  opacity: 1;
}

/* User scan banner */
.scan-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 1rem;
}
