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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #232736;
  --border: #2a2e3d;
  --text: #e4e6ed;
  --text-muted: #8b8fa3;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --success: #22c55e;
  --danger: #ef4444;
  --danger-hover: #f87171;
  --warning: #f59e0b;
  --radius: 8px;
  --sidebar-w: 220px;
  --sidebar-collapsed: 56px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── LOGIN ─────────────────────────────── */
.login-container { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 40px; width: 100%; max-width: 400px; }
.login-box h1 { font-size: 1.5rem; margin-bottom: 8px; }
.login-box p { color: var(--text-muted); margin-bottom: 24px; font-size: 0.9rem; }

/* ── FORMS ─────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 5px; font-weight: 500; }
.form-group small { display: block; font-size: 0.72rem; color: var(--text-muted); margin-top: 3px; }
input[type="text"], input[type="password"], input[type="email"], input[type="url"], input[type="tel"], select, textarea {
  width: 100%; padding: 9px 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.88rem; outline: none;
  transition: border-color 0.2s; font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 72px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-divider {
  font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted);
  margin: 18px 0 14px; display: flex; align-items: center; gap: 10px;
}
.form-divider::before, .form-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── BUTTONS ───────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px; border: none;
  border-radius: var(--radius); font-size: 0.85rem; cursor: pointer; transition: background 0.15s, opacity 0.15s;
  color: #fff; font-family: inherit; font-weight: 500; white-space: nowrap; flex-shrink: 0;
}
.btn svg { pointer-events: none; }
.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: 0.85; }
.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover { opacity: 0.85; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.btn-xs { padding: 4px 7px; font-size: 0.72rem; }
.btn-icon { padding: 5px; width: 30px; height: 30px; }
.btn-icon-sm { padding: 4px; width: 26px; height: 26px; border-radius: 6px; }

/* ── LAYOUT ────────────────────────────── */
.app { display: flex; min-height: 100vh; }
.main-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.main { flex: 1; padding: 28px 32px; overflow-y: auto; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 1.25rem; font-weight: 700; }

/* ── SIDEBAR ───────────────────────────── */
.sidebar {
  width: var(--sidebar-collapsed); background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; transition: width 0.2s ease; flex-shrink: 0; overflow: hidden;
}
.sidebar:hover { width: var(--sidebar-w); }

.sidebar-header {
  padding: 14px 12px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; min-height: 52px; flex-shrink: 0;
}
.sidebar-logo {
  width: 28px; height: 28px; border-radius: 8px; background: var(--primary);
  display: flex; align-items: center; justify-content: center; font-size: 0.78rem;
  font-weight: 700; flex-shrink: 0; color: #fff;
}
.sidebar-title { font-size: 0.88rem; font-weight: 600; white-space: nowrap; overflow: hidden; transition: opacity 0.2s; }
.sidebar:not(:hover) .sidebar-title { opacity: 0; width: 0; }

.sidebar nav { flex: 1; padding: 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; color: var(--text-muted);
  text-decoration: none; border-radius: var(--radius); font-size: 0.87rem; margin-bottom: 2px;
  transition: all 0.15s; cursor: pointer; border: none; background: none; width: 100%; white-space: nowrap;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-icon { width: 18px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.nav-label { overflow: hidden; transition: opacity 0.2s; }
.sidebar:not(:hover) .nav-label { opacity: 0; width: 0; pointer-events: none; }

/* Sidebar footer — user info + logout */
.sidebar-footer { padding: 8px; border-top: 1px solid var(--border); flex-shrink: 0; }
.sidebar-user-info {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px 2px; white-space: nowrap;
}
.sidebar-user-info .avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: #fff;
  font-size: 0.72rem; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sidebar-user-info .sidebar-username {
  font-size: 0.82rem; font-weight: 600; color: var(--text); overflow: hidden;
  transition: opacity 0.2s; white-space: nowrap;
}
.sidebar:not(:hover) .sidebar-username { opacity: 0; width: 0; }

.sidebar-logout-btn {
  color: var(--danger) !important;
}
.sidebar-logout-btn:hover { background: rgba(239,68,68,.1) !important; color: var(--danger-hover) !important; }

/* ── TOPBAR (mobile) ───────────────────── */
.topbar {
  display: none; align-items: center; justify-content: space-between;
  padding: 0 16px; height: 52px; background: var(--surface); border-bottom: 1px solid var(--border);
  flex-shrink: 0; position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-logo { font-size: 0.95rem; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.user-menu { position: relative; }
.user-menu-btn {
  display: flex; align-items: center; gap: 7px; padding: 5px 10px 5px 6px;
  background: var(--surface-hover); border: 1px solid var(--border);
  border-radius: 20px; color: var(--text); font-size: 0.82rem; cursor: pointer; white-space: nowrap;
}
.user-menu-btn .avatar {
  width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: #fff;
  font-size: 0.68rem; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); min-width: 160px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3); display: none; z-index: 200; overflow: hidden;
}
.user-dropdown.open { display: block; }
.user-dropdown-name { padding: 9px 14px; font-size: 0.78rem; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.user-dropdown button { width: 100%; padding: 9px 14px; background: none; border: none; color: var(--danger); font-size: 0.85rem; text-align: left; cursor: pointer; font-family: inherit; }
.user-dropdown button:hover { background: var(--surface-hover); }

.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 90; }
.sidebar-overlay.active { display: block; }

/* ── FILTER BAR ────────────────────────── */
.filter-bar {
  display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap;
}
.filter-bar select {
  width: auto; padding: 6px 10px; font-size: 0.82rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); cursor: pointer;
}
.filter-bar select:focus { border-color: var(--primary); outline: none; }
.filter-count { font-size: 0.78rem; color: var(--text-muted); margin-left: auto; }

/* ── TABLES ────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th {
  padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.73rem; text-transform: uppercase; letter-spacing: 0.05em;
  font-weight: 600; background: var(--surface); white-space: nowrap; user-select: none;
}
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text); }
th .sort-icon { display: inline-block; margin-left: 4px; font-size: 0.65rem; opacity: 0.4; }
th.sort-asc .sort-icon { opacity: 1; }
th.sort-desc .sort-icon { opacity: 1; }
td {
  padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 0.86rem;
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
td.td-actions { overflow: visible; white-space: nowrap; max-width: none; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-hover); }
.td-actions { display: flex; gap: 4px; align-items: center; }

/* Clickable status badge in table */
.badge-toggle { cursor: pointer; transition: opacity 0.15s; }
.badge-toggle:hover { opacity: 0.75; }

/* ── BADGES ────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 600; white-space: nowrap; }
.badge-success { background: rgba(34,197,94,.15); color: var(--success); }
.badge-danger { background: rgba(239,68,68,.15); color: var(--danger); }
.badge-info { background: rgba(99,102,241,.15); color: var(--primary); }
.badge-muted { background: var(--surface-hover); color: var(--text-muted); }
.badge-warning { background: rgba(245,158,11,.15); color: var(--warning); }

/* ── MODAL ─────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: center;
  justify-content: center; z-index: 200; opacity: 0; pointer-events: none; transition: opacity 0.15s; padding: 16px;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; width: 100%; max-width: 540px; max-height: 90vh; display: flex; flex-direction: column; }
.modal-lg { max-width: 680px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-header h2 { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.1rem; cursor: pointer; padding: 3px 7px; border-radius: 4px; line-height: 1; }
.modal-close:hover { color: var(--text); background: var(--surface-hover); }
.modal-body { padding: 18px 22px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; flex-shrink: 0; }

/* Access search */
.access-search-wrap { margin-bottom: 12px; }
.access-search-wrap input { padding: 7px 10px; font-size: 0.84rem; }

/* Access / project check lists */
.check-list { display: flex; flex-direction: column; gap: 6px; max-height: 340px; overflow-y: auto; }
.check-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: border-color 0.15s; flex-shrink: 0;
}
.check-item:hover { border-color: var(--primary); }
.check-item input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--primary); flex-shrink: 0; margin: 0; }
.check-item-main { font-size: 0.88rem; font-weight: 600; }
.check-item-sub { font-size: 0.75rem; color: var(--text-muted); }
.check-item.dimmed { opacity: 0.5; }

/* ── ALERTS ────────────────────────────── */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 0.87rem; }
.alert-error { background: rgba(239,68,68,.12); color: var(--danger); border: 1px solid rgba(239,68,68,.25); }
.alert-success { background: rgba(34,197,94,.12); color: var(--success); border: 1px solid rgba(34,197,94,.25); }

/* ── EMPTY STATE ───────────────────────── */
.empty-state { text-align: center; padding: 52px 20px; color: var(--text-muted); font-size: 0.88rem; }

/* ── VIEW TOGGLE ───────────────────────── */
.view-toggle { display: flex; gap: 3px; }
.view-toggle .btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── PROJECT CARDS ──────────────────────── */
.projects-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 18px;
}
.project-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; transition: border-color 0.2s;
  display: flex; flex-direction: column;
}
.project-card:hover { border-color: var(--primary); }
.project-card-thumb {
  height: 168px; background: var(--surface-hover); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 2rem; overflow: hidden; position: relative;
}
.project-card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-badges { position: absolute; top: 8px; right: 8px; display: flex; gap: 5px; }
.project-card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; flex: 1; }
.project-card-title {
  font-size: 0.92rem; font-weight: 600; margin-bottom: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.project-card-desc {
  font-size: 0.82rem; color: var(--text-muted); margin-bottom: 14px; flex: 1;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.project-card-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.project-card-actions { display: flex; gap: 5px; margin-top: auto; }
.project-card-link { color: var(--primary); text-decoration: none; font-weight: 500; font-size: 0.88rem; margin-top: auto; }
.project-card-link:hover { text-decoration: underline; }

/* ── DASHBOARD (client) ─────────────────── */
.dashboard-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 32px; border-bottom: 1px solid var(--border);
}
.dashboard-header h1 { font-size: 1.2rem; }
.client-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 24px;
  padding: 32px;
}

/* ── RESPONSIVE ────────────────────────── */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: -100%; top: 0; bottom: 0; z-index: 100; transition: left 0.2s, width 0.2s; width: var(--sidebar-w) !important; }
  .sidebar.mobile-open { left: 0; }
  .topbar { display: flex; }
  .main { padding: 18px 16px; }
  .form-grid-2 { grid-template-columns: 1fr; }
  .client-grid { padding: 16px; gap: 16px; }
}
