/* Company Links Dashboard — single light theme, no dependencies. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --accent-hover: #4338ca;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn-soft: #fffbeb;
  --warn-border: #fcd34d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.04);
  --shadow-lift: 0 8px 24px rgba(17, 24, 39, 0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

h1, h2 { margin: 0 0 6px; font-weight: 650; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 17px;
  white-space: nowrap;
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
}

.search-box {
  position: relative;
  flex: 1 1 240px;
  min-width: 180px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font: inherit;
  color: var(--text);
}

.search-box input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  background: var(--surface);
}

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

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  min-height: 40px;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 40px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Chips ---------- */

.chips-row {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.chip:hover { border-color: #d1d5db; }

.chip .count { color: var(--muted); font-weight: 450; margin-left: 3px; }

.chip-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: 1px;
}
.chip.active .chip-dot { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.55); }

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chip.active .count { color: #c7d2fe; }

.chips-manage { flex: 0 0 auto; }

/* ---------- Card grid ---------- */

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 20px 60px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.card {
  /* Fall back to the accent colour if a category colour is not set. */
  --cat-line: var(--accent);
  --cat-bg: var(--accent-soft);
  --cat-fg: var(--accent);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--cat-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 16px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow 0.15s, transform 0.15s;
}
.card:hover { box-shadow: var(--shadow-lift); }

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

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--cat-bg);
  color: var(--cat-fg);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Drag handle: touch-action none so a drag on the grip never scrolls the page. */
.drag-handle {
  width: 30px;
  height: 30px;
  min-width: 30px;
  border-radius: 8px;
  margin-left: -6px;
  cursor: grab;
  touch-action: none;
  color: #c3c7ce;
}
.drag-handle:active { cursor: grabbing; }
.drag-handle.drag-off { cursor: default; opacity: 0.35; }
.drag-handle.drag-off:hover { background: transparent; color: #c3c7ce; }

.card.dragging {
  opacity: 0.85;
  transform: scale(1.02);
  box-shadow: var(--shadow-lift);
  border-color: var(--accent);
}

.grid.is-dragging { user-select: none; }
.grid.is-dragging .card:not(.dragging) { transition: transform 0.18s ease; }

.card-tools { display: flex; gap: 2px; }
.card-tools .icon-btn { width: 32px; height: 32px; min-width: 32px; border-radius: 8px; }

.card-title {
  font-size: 17px;
  font-weight: 650;
  margin: 0;
  overflow-wrap: anywhere;
}
.card-title a { color: inherit; text-decoration: none; }
.card-title a:hover { color: var(--accent); }

.card-purpose {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 0;
}

.card-creds {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cred-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
}

.cred-label {
  flex: 0 0 74px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 550;
}

.cred-value {
  flex: 1 1 auto;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cred-value.masked { letter-spacing: 2px; color: var(--muted); }
.cred-none { color: var(--muted); font-size: 13px; font-style: italic; }

.cred-actions { display: flex; gap: 2px; }
.cred-actions .icon-btn { width: 32px; height: 32px; min-width: 32px; border-radius: 8px; }

.card-open {
  margin-top: 2px;
  width: 100%;
  background: var(--cat-bg);
  color: var(--cat-fg);
}
.card-open:hover { filter: brightness(0.96); }

/* ---------- Empty state ---------- */

.empty {
  text-align: center;
  padding: 70px 20px;
  color: var(--muted);
}
.empty-icon { color: #d1d5db; margin-bottom: 10px; }
.empty p { margin: 0 0 14px; font-size: 15px; }

/* ---------- Modals ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(17, 24, 39, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lift);
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 20px;
}

.modal-small { max-width: 380px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.modal-head h2 { margin: 0; font-size: 18px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

@media (max-width: 560px) {
  .overlay { align-items: flex-end; padding: 0; }
  .modal {
    max-width: none;
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
  }
}

/* ---------- Form fields ---------- */

.field { display: block; margin-bottom: 13px; }

.field > span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
}
.field > span em { color: var(--muted); font-weight: 450; font-style: normal; }

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
}

.field textarea { resize: vertical; }

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.pass-input { position: relative; }
.pass-input input { padding-right: 46px; }
.pass-input .icon-btn {
  position: absolute;
  right: 3px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  min-width: 36px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -4px 0 13px;
  font-size: 13.5px;
  color: var(--muted);
  cursor: pointer;
}
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- Category manager ---------- */

.cat-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }

.cat-item { display: flex; align-items: center; gap: 8px; }

.cat-item input {
  flex: 1 1 auto;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
}
.cat-item input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.cat-item .cat-count {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12.5px;
  min-width: 60px;
  text-align: right;
}

.cat-add { display: flex; gap: 8px; }
.cat-add input {
  flex: 1 1 auto;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
}
.cat-add input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: #1f2937;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 550;
  box-shadow: var(--shadow-lift);
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast.error { background: var(--danger); }

/* ---------- Auth + install pages ---------- */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 380px;
  padding: 28px;
}

.auth-card-wide { max-width: 460px; }

.auth-card h1 { margin-bottom: 4px; }
.auth-card > .muted { margin: 0 0 18px; font-size: 14px; }
.auth-card h2 { margin: 20px 0 10px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.auth-logo { font-size: 30px; margin-bottom: 8px; }

.notice-error {
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13.5px;
}

.notice-warn {
  background: var(--warn-soft);
  border: 1px solid var(--warn-border);
  color: #92400e;
  border-radius: 10px;
  padding: 10px 14px;
  margin: 10px 0;
  font-size: 13.5px;
}
