:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel-alt: #f8fafc;
  --primary: #4f46e5;
  --primary-soft: #eef2ff;
  --accent: #0ea5e9;
  --sidebar: #111827;
  --sidebar-soft: #1f2937;
  --text: #0f172a;
  --muted: #475569;
  --border: #e5e7eb;
  --danger: #ef4444;
  --success: #14b8a6;
  --light-text: #f8fafc;
  --login-bg: #0f172a;
  --login-card: #111827;
  --login-card-border: rgba(148, 163, 184, 0.2);
  --login-accent: #4f46e5;
  --login-accent-hover: #4338ca;
  --login-input: rgba(15, 23, 42, 0.8);
  --login-error-bg: rgba(239, 68, 68, 0.1);
  --login-error-text: #fecaca;
  --login-success: #22c55e;
  --shadow: rgba(15, 23, 42, 0.25);
}

body[data-theme="dark"] {
  --bg: #0b1220;
  --panel: #0f172a;
  --panel-alt: #111c2d;
  --primary: #8b5cf6;
  --primary-soft: rgba(139, 92, 246, 0.18);
  --accent: #38bdf8;
  --sidebar: #020b17;
  --sidebar-soft: #0f172a;
  --text: #e2e8f0;
  --muted: #a5b4cf;
  --border: rgba(148, 163, 184, 0.2);
  --danger: #f87171;
  --success: #34d399;
  --light-text: #f8fafc;
  --shadow: rgba(2, 6, 23, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: inherit; }

html, body {
  margin: 0;
  min-height: 100%;
  height: 100%;
}

body {
  display: block;
  background: var(--bg);
}

.app-shell {
  display: flex;
  width: 100%;
  min-height: 100vh;
  position: relative;
}

.sidebar {
  position: sticky;
  top: 0;
  width: 260px;
  min-width: 260px;
  height: 100vh;
  background: linear-gradient(180deg, var(--sidebar) 0%, #111827 100%);
  color: var(--light-text);
  padding: 1.3rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  box-shadow: 8px 0 24px rgba(15, 23, 42, 0.15);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: 1.2rem;
  font-weight: 800;
  padding: 0.5rem 0.6rem 0.7rem;
  letter-spacing: 0.01em;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  font-weight: 800;
  box-shadow: 0 12px 25px rgba(79, 70, 229, 0.45);
}

.nav {
  display: grid;
  gap: 0.5rem;
}

.nav a {
  color: #e2e8f0;
  text-decoration: none;
  padding: 0.8rem 0.9rem;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  background: transparent;
  font-weight: 600;
}

.nav a:hover {
  background: rgba(148, 163, 184, 0.08);
  transform: translateX(2px);
}

.nav a.active {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
}

.logout {
  margin-top: auto;
}

.logout button {
  width: 100%;
  border: none;
  border-radius: 12px;
  background: rgba(239, 68, 68, 0.14);
  color: #fecaca;
  padding: 0.85rem 1rem;
  font-weight: 700;
  cursor: pointer;
}

.content {
  flex: 1;
  padding: 2.2rem 2.2rem 3rem;
  min-width: 0;
  overflow: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-title {
  margin: 0;
  font-size: clamp(1.9rem, 2.5vw, 2.9rem);
  letter-spacing: -0.04em;
}

.user-pill {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.7rem 1rem;
  font-weight: 700;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: linear-gradient(180deg, #ffffff 0%, #f9fbff 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.2rem;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.03);
}

.stat-label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
    font-weight: 700;
}

.stat-value {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.stat-value.primary { color: var(--primary); }
.stat-value.accent { color: var(--accent); }
.stat-value.success { color: var(--success); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.04);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.3rem;
  border-bottom: 1px solid var(--border);
  background: rgba(248, 250, 255, 0.9);
}

.panel-title {
  font-size: 1.15rem;
  font-weight: 800;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 1rem 1.3rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 800;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: rgba(79, 70, 229, 0.02);
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.38rem 0.7rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 800;
  letter-spacing: 0.02em;
}

.message-box {
  margin: 1rem;
  border-radius: 10px;
}

.success-banner {
  padding: 0.75rem 1rem;
  background: rgba(20, 184, 166, 0.12);
  border: 1px solid rgba(20, 184, 166, 0.5);
  color: #0f766e;
}

.settings-form {
  display: grid;
  gap: 1.2rem;
  padding: 1.5rem;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.field-group {
  display: grid;
  gap: 0.5rem;
  color: var(--text);
  font-size: 0.95rem;
}

.field-group span {
  color: var(--muted);
  font-weight: 600;
}

.settings-form input,
.settings-form select,
.auth-form input,
.auth-form select {
  width: 100%;
  height: 44px;
  padding: 0.78rem 0.9rem;
  border-radius: 10px;
  border: 1px solid #c9d2df;
  background: linear-gradient(180deg, #f9fafb 0%, #eef2f7 100%);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.3;
  outline: none;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.settings-form input:focus,
.settings-form select:focus,
.auth-form input:focus,
.auth-form select:focus {
  border-color: #6d7ae8;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12), inset 0 1px 2px rgba(15, 23, 42, 0.04);
  background: #ffffff;
  transform: translateY(-1px);
}

.settings-form select,
.auth-form select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 2px), calc(100% - 12px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 2.4rem;
}

.checkbox-list {
  display: grid;
  gap: 0.6rem;
  margin-top: 0.4rem;
  padding: 0.4rem 0;
}

.check-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  color: var(--text);
}

.check-item input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary);
}

.muted-copy {
  color: var(--muted);
}

.primary-btn {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  background: linear-gradient(135deg, var(--primary), #5b4ae2);
  color: var(--light-text);
  border: none;
  border-radius: 12px;
  padding: 0.92rem 1.2rem;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(79, 70, 229, 0.22);
}

.primary-btn:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

.danger-btn {
  border: none;
  background: rgba(79, 70, 229, 0.08);
  color: var(--primary);
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}

.danger-btn:hover {
  background: rgba(79, 70, 229, 0.12);
}

.auth-page {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top, rgba(79, 70, 229, 0.3), transparent 40%), linear-gradient(135deg, #020617, var(--login-bg));
  color: var(--light-text);
  font-family: "Segoe UI", Arial, sans-serif;
}

.auth-card {
  width: min(92vw, 420px);
  background: var(--login-card);
  border: 1px solid var(--login-card-border);
  border-radius: 22px;
  padding: 2rem;
  box-shadow: 0 26px 60px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
}

.auth-card.wide {
  width: min(92vw, 520px);
}

.auth-card h1 {
  margin-top: 0;
  margin-bottom: 0.5rem;
  font-size: 2.1rem;
  letter-spacing: -0.04em;
}

.subtitle {
  color: #cbd5e1;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

.error {
  background: var(--login-error-bg);
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: var(--login-error-text);
  padding: 0.75rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
}

.auth-form {
  display: grid;
  gap: 1rem;
}

.auth-form label,
.auth-form .field-group {
  display: grid;
  gap: 0.45rem;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
}

.auth-form label {
  display: grid;
  gap: 0.45rem;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
}

.auth-form input {
  width: 100%;
  height: 44px;
  padding: 0.8rem 0.9rem;
  border-radius: 10px;
  border: 1px solid #c9d2df;
  background: linear-gradient(180deg, #f9fafb 0%, #eef2f7 100%);
  color: var(--text);
  font-size: 1rem;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

.auth-form button,
.primary-btn {
  margin-top: 0.5rem;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--login-accent), var(--login-accent-hover));
  color: var(--light-text);
  padding: 0.9rem 1.1rem;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(79, 70, 229, 0.24);
}

.auth-form button:hover,
.primary-btn:hover {
  background: var(--login-accent-hover);
}

.field-message {
  margin-top: 0.35rem;
  font-size: 0.8rem;
  line-height: 1.35;
}

.field-message.valid {
  color: #86efac;
}

.field-message.invalid {
  color: #fca5a5;
}

input.field-valid {
  border-color: var(--login-success);
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.35);
}

input.field-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.35);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 1000;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: min(760px, 92vw);
  max-height: 90vh;
  overflow: auto;
  background: var(--panel);
  border-radius: 22px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.24);
  border: 1px solid rgba(148, 163, 184, 0.35);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.close-modal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.floating-panel {
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.08);
  border-radius: 18px;
  overflow: hidden;
}

.floating-form {
  padding: 1.5rem;
}

.file-upload-field {
  display: grid;
  gap: 0.55rem;
}

.upload-box {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 52px;
  padding: 0.35rem 0.6rem 0.35rem 0.35rem;
  border-radius: 12px;
  border: 1px solid #c9d2df;
  background: linear-gradient(180deg, #f9fafb 0%, #eef2f7 100%);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

.upload-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 130px;
  min-height: 38px;
  padding: 0.7rem 1rem;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #5b4ae2);
  color: var(--light-text);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 16px rgba(79, 70, 229, 0.18);
}

.upload-button:hover {
  filter: brightness(1.04);
}

.hidden-file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.upload-file-name {
  color: var(--muted);
  font-size: 0.96rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kanban-column {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #f8fafc;
  overflow: hidden;
}

.kanban-header {
  padding: 0.9rem 1rem;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  background: rgba(79, 70, 229, 0.05);
  color: var(--text);
}

.kanban-cards {
  display: grid;
  gap: 0.75rem;
  min-height: 110px;
  padding: 0.9rem;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.kanban-cards.drag-over {
  background: rgba(79, 70, 229, 0.05);
  border: 1px dashed rgba(79, 70, 229, 0.35);
  border-radius: 12px;
}

.kanban-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 0.9rem;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
  cursor: grab;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.kanban-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.08);
}

.kanban-card.dragging {
  opacity: 0.5;
}

.kanban-card-main {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 0.75rem;
  min-width: 0;
  margin: 0;
}

.site-name {
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.site-url {
  font-size: 0.85rem;
  color: var(--muted);
  word-break: break-word;
  overflow-wrap: anywhere;
}

.kanban-card-actions {
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}

.kanban-empty {
  color: var(--muted);
  padding: 0.6rem 0.2rem;
  font-size: 0.92rem;
}

.password-rules {
  display: grid;
  gap: 0.3rem;
  margin-top: 0.55rem;
  font-size: 0.8rem;
}

.rule {
  color: #cbd5e1;
}

.rule.valid {
  color: #86efac;
}

.rule.invalid {
  color: #fca5a5;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.password-note {
  margin-top: -0.1rem;
  font-size: 0.8rem;
  color: #cbd5e1;
}

.link-row {
  margin-top: 1rem;
  color: #cbd5e1;
  text-align: center;
  font-size: 0.95rem;
}

.link-row a {
  color: #ddd6fe;
  text-decoration: none;
  font-weight: 700;
}

.hint {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: #cbd5e1;
  text-align: center;
}

.user-home-page {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  max-width: 900px;
  margin: 0 auto;
  padding: 2.5rem 1rem 3rem;
}

.user-welcome-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.82) 0%, rgba(248,250,252,0.96) 100%);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 2rem;
  box-shadow: 0 20px 46px var(--shadow);
}

body[data-theme="dark"] .user-welcome-card {
  background: linear-gradient(180deg, rgba(15,23,42,0.96) 0%, rgba(17,24,39,0.96) 100%);
}

.user-welcome-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.user-welcome-card h1 {
  margin: 0;
  font-size: clamp(2rem, 3vw, 3rem);
  letter-spacing: -0.06em;
  color: var(--text);
}

.role-badge {
  display: inline-flex;
  align-items: center;
  margin-top: 0.8rem;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 800;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.welcome-copy {
  margin: 0.8rem 0 1.4rem;
  color: var(--muted);
  font-size: 1rem;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-alt);
  color: var(--text);
  padding: 0.7rem 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.theme-toggle:hover {
  transform: translateY(-1px);
  border-color: rgba(79, 70, 229, 0.35);
}

.site-section {
  background: rgba(148, 163, 184, 0.04);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  margin-top: 1rem;
}

.site-section-header {
  display: flex;
  align-items: center;
  padding: 0.9rem 1rem;
  background: rgba(79, 70, 229, 0.06);
  border-bottom: 1px solid var(--border);
  font-weight: 800;
  color: var(--text);
}

.group-sites {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  padding: 1rem;
}

.site-link-card {
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
  width: fit-content;
  min-width: 220px;
  max-width: 100%;
  text-decoration: none;
  background: linear-gradient(135deg, var(--primary-soft), rgba(255,255,255,0.08));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.8rem 1rem;
  color: var(--text);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.site-link-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.1);
}

.site-link-card span {
  display: grid;
  gap: 0.2rem;
  line-height: 1.2;
}

.site-link-card strong {
  font-size: 1rem;
}

.site-link-card small {
  color: var(--muted);
  font-size: 0.74rem;
}

.site-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.3);
}

.empty-group-sites {
  color: var(--muted);
  padding: 1rem;
}

.inline-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

.inline-actions form {
  margin: 0;
  width: 100%;
}

.inline-actions .primary-btn {
  min-width: 160px;
  width: 100%;
  margin-top: 0;
}

body[data-theme="dark"] .site-link-card {
  background: linear-gradient(135deg, rgba(139,92,246,0.12), rgba(15,23,42,0.85));
}

@media (max-width: 640px) {
  .user-welcome-card {
    padding: 1.4rem;
  }

  .user-welcome-top {
    flex-direction: column;
    align-items: stretch;
  }

  .theme-toggle {
    align-self: flex-start;
  }

  .group-sites {
    display: grid;
    grid-template-columns: 1fr;
  }

  .site-link-card {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 900px) {
  body {
    flex-direction: column;
  }

  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    position: static;
    width: 100%;
    min-width: 100%;
    height: auto;
  }

  .stats {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .grid {
    grid-template-columns: 1fr;
  }
}
