/* Citadel – Castle Theme Styles */

:root {
  --blue-deep: #1a3a5c;
  --blue-mid: #2E5090;
  --blue-light: #4a7ab5;
  --gold: #e8b84a;
  --gold-dark: #d4a847;
  --stone: #dce3ed;
  --stone-light: #edf1f7;
  --bg: #f5f7fa;
  --white: #ffffff;
  --danger: #c0392b;
  --success: #27ae60;
  --text: #1a3a5c;
  --text-muted: #6b7a8d;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── The Gate (Login) ── */

.gate-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.gate-card {
  background: var(--white);
  border-radius: 16px;
  padding: 48px 40px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 4px 24px rgba(26, 58, 92, 0.1);
  border: 1px solid var(--stone);
}

.gate-card .gate-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 16px;
}

.gate-card h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--blue-deep);
  margin-bottom: 4px;
}

.gate-card .subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 32px;
}

/* ── Forms ── */

.form-group {
  margin-bottom: 16px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--blue-mid);
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--stone);
  border-radius: 8px;
  font-size: 15px;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--blue-mid);
}

.form-group input::placeholder {
  color: var(--text-muted);
}

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--blue-mid);
  color: var(--white);
  width: 100%;
}

.btn-primary:hover {
  background: var(--blue-deep);
}

.btn-gold {
  background: var(--gold);
  color: var(--blue-deep);
}

.btn-gold:hover {
  background: var(--gold-dark);
}

.btn-outline {
  background: transparent;
  color: var(--blue-mid);
  border: 2px solid var(--stone);
}

.btn-outline:hover {
  border-color: var(--blue-mid);
}

.btn-danger {
  background: var(--danger);
  color: var(--white);
}

.btn-danger:hover {
  opacity: 0.9;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 13px;
}

.btn-icon {
  padding: 8px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: 6px;
}

.btn-icon:hover {
  background: var(--stone-light);
  color: var(--blue-mid);
}

/* ── App Layout ── */

.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--blue-deep);
  color: var(--white);
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 0 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-header .logo {
  width: 36px;
  height: 36px;
}

.sidebar-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.sidebar-castle {
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-castle .castle-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--gold);
}

.sidebar-castle .castle-role {
  font-size: 12px;
  color: rgba(255,255,255,0.6);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.sidebar-section-title {
  padding: 12px 20px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.4);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 20px;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: rgba(255,255,255,0.08);
  color: var(--white);
}

.nav-item.active {
  background: rgba(255,255,255,0.12);
  color: var(--gold);
}

.nav-item .count {
  font-size: 11px;
  background: rgba(255,255,255,0.15);
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

/* ── Main Content ── */

.main-content {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
}

.page-header .secret-count {
  color: var(--text-muted);
  font-size: 14px;
  margin-left: 8px;
  font-weight: 400;
}

/* ── Cards ── */

.card {
  background: var(--white);
  border-radius: 12px;
  border: 1px solid var(--stone);
  padding: 20px;
  margin-bottom: 12px;
  transition: box-shadow 0.2s;
}

.card:hover {
  box-shadow: 0 2px 12px rgba(26, 58, 92, 0.08);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
}

.card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Secret Item ── */

.secret-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--white);
  border: 1px solid var(--stone);
  border-radius: 8px;
  margin-bottom: 4px;
  transition: box-shadow 0.2s;
}

.secret-item:hover {
  box-shadow: 0 2px 8px rgba(26, 58, 92, 0.06);
}

.secret-icon {
  width: 32px;
  height: 32px;
  background: var(--stone-light);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.secret-info {
  flex: 1;
  min-width: 0;
}

.secret-name {
  font-weight: 600;
  font-size: 14px;
}

.secret-username {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

.secret-url {
  font-size: 12px;
  color: var(--blue-light);
  text-decoration: none;
  margin-top: 2px;
  display: inline-block;
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.secret-url:hover {
  text-decoration: underline;
  color: var(--blue-mid);
}

.secret-access-info {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.member-badge {
  font-size: 11px;
  background: var(--stone-light);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.member-role {
  font-size: 10px;
  color: var(--gold-dark);
  font-weight: 600;
}

.secret-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ── Password Field ── */

.password-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.password-dots {
  font-family: monospace;
  letter-spacing: 3px;
  color: var(--text-muted);
}

.password-revealed {
  font-family: 'Courier New', monospace;
  font-size: 14px;
  background: var(--stone-light);
  padding: 4px 8px;
  border-radius: 4px;
  word-break: break-all;
}

/* ── Modal ── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 58, 92, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--white);
  border-radius: 16px;
  padding: 32px;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(26, 58, 92, 0.2);
}

.modal h2 {
  font-size: 20px;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* ── Castle Selector (landing) ── */

.castle-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin-top: 24px;
  justify-content: center;
}

.castle-card {
  background: var(--white);
  border: 2px solid var(--stone);
  border-radius: 16px;
  padding: 32px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  width: 240px;
  flex-shrink: 0;
}

.castle-card:hover {
  border-color: var(--gold);
  box-shadow: 0 4px 20px rgba(232, 184, 74, 0.15);
  transform: translateY(-2px);
}

.castle-card .castle-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
}

.castle-card h3 {
  font-size: 18px;
  margin-bottom: 4px;
}

.castle-card .castle-meta {
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Master Key Prompt ── */

.masterkey-prompt {
  text-align: center;
  max-width: 400px;
  margin: 80px auto;
}

.masterkey-prompt .key-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
}

.masterkey-prompt h2 {
  margin-bottom: 8px;
}

.masterkey-prompt p {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 14px;
}

/* ── Global Search ── */

.sidebar-search {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  position: relative;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrapper .search-icon {
  position: absolute;
  left: 10px;
  color: rgba(255,255,255,0.4);
  pointer-events: none;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 60px 8px 32px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  outline: none;
}

.sidebar-search input:focus {
  background: rgba(255,255,255,0.12);
  border-color: var(--gold);
}

.sidebar-search input::placeholder {
  color: rgba(255,255,255,0.4);
}

.search-kbd {
  position: absolute;
  right: 8px;
  font-size: 10px;
  color: rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.08);
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}

.search-results {
  position: absolute;
  top: calc(100% - 4px);
  left: 12px;
  right: 12px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  max-height: 400px;
  overflow-y: auto;
  z-index: 60;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid #edf1f7;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover,
.search-result-item.active {
  background: #edf1f7;
}

.search-result-info {
  flex: 1;
  min-width: 0;
}

.search-result-name {
  font-size: 14px;
  font-weight: 600;
  color: #1a3a5c;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-url {
  font-size: 12px;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-vault {
  font-size: 11px;
  background: #edf1f7;
  color: #666;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
}

.search-no-results {
  padding: 16px;
  text-align: center;
  color: #888;
  font-size: 13px;
}

@media (max-width: 768px) {
  .search-kbd { display: none; }
}

.masterkey-warning {
  background: #fef3cd;
  border: 1px solid #ffc107;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 13px;
  color: #664d03;
  text-align: left;
  line-height: 1.5;
}

.text-error {
  color: #dc3545;
  font-size: 13px;
  margin-bottom: 12px;
}

/* ── Toast Notifications ── */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--blue-deep);
  color: var(--white);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  animation: slideIn 0.3s ease;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Utility ── */

.text-muted { color: var(--text-muted); }
.text-gold { color: var(--gold); }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }

.link {
  color: var(--blue-mid);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}

.link:hover {
  text-decoration: underline;
}

.divider {
  height: 1px;
  background: var(--stone);
  margin: 16px 0;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 15px;
  margin-bottom: 16px;
}


/* ── User Menu ── */

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.user-menu-item:hover {
  background: var(--stone-light);
}

/* ── Responsive ── */

/* ── Mobile: tablets and small laptops ── */
@media (max-width: 768px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    padding: 12px 0;
  }

  .sidebar-nav {
    display: flex;
    overflow-x: auto;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar-section-title {
    display: none;
  }

  .nav-item {
    padding: 8px 16px;
    white-space: nowrap;
  }

  .main-content {
    padding: 16px;
  }

  .castle-grid {
    flex-direction: column;
    align-items: center;
  }

  .castle-card {
    width: 100%;
    max-width: 300px;
  }

  .page-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .page-header h1 {
    font-size: 20px;
    width: 100%;
  }

  .modal {
    padding: 20px;
    margin: 10px;
    max-height: 85vh;
  }

  .modal-overlay {
    padding: 10px;
  }

  .secret-item {
    flex-wrap: wrap;
    padding: 10px 12px;
  }

  .secret-actions {
    width: 100%;
    justify-content: flex-end;
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid var(--stone);
  }

  .toast-container {
    left: 16px;
    right: 16px;
    bottom: 16px;
  }

  .toast {
    width: 100%;
  }
}

/* ── Mobile: phones ── */
@media (max-width: 480px) {
  .gate-container {
    padding: 12px;
  }

  .gate-card {
    padding: 24px 20px;
  }

  .gate-card h1 {
    font-size: 24px;
  }

  .form-group input,
  .form-group select {
    font-size: 16px;
    padding: 10px 12px;
  }

  .form-group textarea {
    font-size: 16px !important;
  }

  .btn {
    padding: 10px 16px;
    font-size: 14px;
  }

  .modal {
    padding: 16px;
    border-radius: 12px;
  }

  .sidebar-castle {
    padding: 10px 14px !important;
  }

  .sidebar-header {
    padding: 0 14px 14px;
  }

  .sidebar-header h2 {
    font-size: 16px;
  }

  .main-content {
    padding: 12px;
  }

  .page-header {
    margin-bottom: 16px;
  }

  .secret-url {
    max-width: 180px;
  }

  .empty-state {
    padding: 24px 16px;
  }
}
