/* ===========================================================
   Design tokens
   =========================================================== */
:root{
  --sidebar-w: 264px;

  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-light: #ccfbf1;
  --primary-rgb: 13,148,136;

  --ink: #0f2a2e;
  --sidebar-bg-1: #0b3339;
  --sidebar-bg-2: #081f23;

  --surface: #eef4f4;
  --surface-card: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-soft: #94a3b8;
  --border: #e6edee;

  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #b45309;
  --warning-light: #fef3c7;
  --success: #15803d;
  --success-light: #dcfce7;

  --radius-lg: 18px;
  --radius: 14px;
  --radius-sm: 10px;

  --shadow-sm: 0 1px 2px rgba(15,23,42,.05), 0 1px 1px rgba(15,23,42,.04);
  --shadow-md: 0 8px 24px -6px rgba(15,42,46,.14);
  --shadow-lg: 0 20px 50px -12px rgba(15,42,46,.28);

  --bs-primary: var(--primary);
  --bs-primary-rgb: var(--primary-rgb);
  --bs-body-font-family: 'Inter', 'Segoe UI', Helvetica, Arial, sans-serif;
  --bs-link-color: var(--primary-dark);
  --bs-link-hover-color: var(--primary);
}

*{ -webkit-font-smoothing: antialiased; }

body{
  background: var(--surface);
  color: var(--text-main);
  font-family: 'Inter', 'Segoe UI', Helvetica, Arial, sans-serif;
}

a{ color: var(--primary-dark); }
a:hover{ color: var(--primary); }

.text-muted{ color: var(--text-muted) !important; }

/* ===========================================================
   Buttons
   =========================================================== */
.btn{
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: .875rem;
  padding: .55rem 1.1rem;
  letter-spacing: .1px;
}
.btn-primary{
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 6px 16px -4px rgba(var(--primary-rgb),.55);
}
.btn-primary:hover, .btn-primary:focus{
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}
.btn-outline-secondary{
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-outline-secondary:hover{
  background: var(--surface);
  color: var(--text-main);
  border-color: var(--border);
}
.btn-outline-danger{ --bs-btn-hover-bg: var(--danger); --bs-btn-hover-border-color: var(--danger); }
.btn-sm{ padding: .35rem .75rem; font-size: .8rem; border-radius: 8px; }
.btn-icon{
  width: 34px; height: 34px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9px;
}

/* ===========================================================
   App shell — fixed sidebar + main column
   =========================================================== */
.admin-shell{
  display: flex;
  min-height: 100vh;
}

.sidebar{
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface-card);
  border-right: 1px solid var(--border);
  color: var(--text-main);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 1030;
  transition: transform .25s ease;
}

.sidebar-brand{
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: 1.5rem 1.4rem 1.1rem;
  color: var(--ink);
  text-decoration: none;
}
.sidebar-brand .brand-logo, .user-topbar-brand .brand-logo{
  width: 80px; height: 80px;
  border-radius: 11px;
  object-fit: cover;
  flex-shrink: 0;
}
.sidebar-brand .label{
  font-weight: 700;
  font-size: .98rem;
  line-height: 1.15;
}
.sidebar-brand .label small{
  display: block;
  font-weight: 400;
  font-size: .72rem;
  color: var(--text-muted);
}

.sidebar-nav{
  flex: 1;
  padding: .5rem .9rem;
  overflow-y: auto;
}
.sidebar-nav .nav-section{
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-soft);
  padding: 1.1rem .6rem .4rem;
  font-weight: 700;
}
.sidebar-nav a{
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .62rem .75rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: .89rem;
  font-weight: 500;
  margin-bottom: 2px;
  transition: background .15s ease, color .15s ease;
}
.sidebar-nav a i{ font-size: 1.05rem; width: 20px; text-align: center; opacity: .85; }
.sidebar-nav a:hover{ background: var(--surface); color: var(--ink); }
.sidebar-nav a.active{
  background: var(--primary-light);
  color: var(--primary-dark);
}

.sidebar-user{
  margin: .75rem;
  padding: .8rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: .65rem;
}
.sidebar-user .avatar{
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: .82rem;
  flex-shrink: 0;
}
.sidebar-user .who{ min-width: 0; flex: 1; }
.sidebar-user .name{
  font-size: .84rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user .role{ font-size: .7rem; color: var(--text-muted); text-transform: capitalize; }
.sidebar-user .logout-link{
  color: var(--text-muted);
  flex-shrink: 0;
  font-size: 1.05rem;
  padding: 4px;
}
.sidebar-user .logout-link:hover{ color: var(--ink); }

.sidebar-backdrop{
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(8,20,22,.55);
  z-index: 1020;
}

/* main column */
.admin-main{
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar{
  display: flex;
  align-items: center;
  gap: .9rem;
  padding: 1rem 1.75rem;
  background: transparent;
}
.topbar .menu-toggle{
  display: none;
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-card);
  align-items: center; justify-content: center;
  flex-shrink: 0;
}
.topbar .page-title{
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
}
.topbar .page-subtitle{ font-size: .85rem; color: var(--text-muted); }

.admin-content{
  padding: 0 1.75rem 2.5rem;
  flex: 1;
}

/* ===========================================================
   User-role dashboard — sidebar-free shell
   =========================================================== */
.user-shell{
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.user-topbar{
  background: var(--surface-card);
  border-bottom: 1px solid var(--border);
}
.user-topbar-inner{
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  padding: 1rem 1.75rem;
}
.user-topbar-brand{
  display: flex;
  align-items: center;
  gap: .65rem;
}
.user-topbar-brand .label{
  font-weight: 700;
  font-size: .98rem;
  line-height: 1.15;
  color: var(--ink);
}
.user-topbar-brand .label small{
  display: block;
  font-weight: 400;
  font-size: .72rem;
  color: var(--text-muted);
}
.user-topbar-account{
  display: flex;
  align-items: center;
  gap: .65rem;
}
.user-topbar-account .avatar-btn{
  border: none;
  background: none;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  line-height: 0;
}
.user-topbar-account .avatar-btn:focus-visible{
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.user-topbar-account .avatar{
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: .8rem;
  flex-shrink: 0;
  transition: box-shadow .15s ease;
}
.user-topbar-account .avatar-btn:hover .avatar{ box-shadow: 0 0 0 3px var(--primary-light); }
.user-topbar-account .name{ font-size: .85rem; font-weight: 600; color: var(--ink); text-align: right; }
.user-topbar-account .role{ font-size: .7rem; color: var(--text-muted); text-transform: capitalize; text-align: right; }

.user-content{
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.75rem 3rem;
  flex: 1;
}

/* ===========================================================
   Cards / tiles
   =========================================================== */
.card{
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card .card-body{ padding: 1.6rem 1.7rem; }
.card h2.h5{ font-weight: 700; color: var(--ink); letter-spacing: -.01px; }

.stat-tile{
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-card);
  padding: 1.1rem 1.3rem;
  display: flex;
  align-items: center;
  gap: .9rem;
  box-shadow: var(--shadow-sm);
}
.stat-tile .icon{
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
  background: var(--primary-light);
  color: var(--primary-dark);
  flex-shrink: 0;
}
.stat-tile .value{ font-size: 1.3rem; font-weight: 800; color: var(--ink); line-height: 1.1; }
.stat-tile .label{ font-size: .78rem; color: var(--text-muted); }

.project-tile{
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  transition: transform .15s ease, box-shadow .15s ease;
}
.project-tile:hover{
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}
.project-tile .icon{
  width: 150px;
  height: auto;
  border-radius: 11px;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  margin-bottom: .7rem;
  overflow: hidden;
}
.project-tile .icon img{
  width: 100%;
  height: auto;
  object-fit: contain;
}

/* ===========================================================
   Forms
   =========================================================== */
.form-label{ font-weight: 600; font-size: .82rem; color: var(--ink); }
.form-control, .form-select{
  border-radius: var(--radius-sm);
  border-color: var(--border);
  padding: .55rem .8rem;
  font-size: .9rem;
}
.form-control:focus, .form-select:focus{
  border-color: var(--primary);
  box-shadow: 0 0 0 .2rem rgba(var(--primary-rgb),.15);
}
.form-check-input:checked{ background-color: var(--primary); border-color: var(--primary); }
.form-check-input:focus{ box-shadow: 0 0 0 .2rem rgba(var(--primary-rgb),.15); }

.checkbox-pills{ display: flex; flex-wrap: wrap; gap: .5rem; }
.checkbox-pills label{
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .4rem .9rem .4rem .6rem;
  font-size: .82rem;
  font-weight: 500;
  display: flex; align-items: center; gap: .4rem;
  background: var(--surface-card);
  cursor: pointer;
}
.checkbox-pills label:has(input:checked){
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* ===========================================================
   Tables
   =========================================================== */
.table{ margin-bottom: 0; font-size: .88rem; }
.table thead th{
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  border-bottom-width: 1px;
  font-weight: 700;
  padding-bottom: .7rem;
}
.table td{ vertical-align: middle; padding-top: .8rem; padding-bottom: .8rem; color: var(--text-main); }
.table-hover > tbody > tr:hover > *{ background-color: var(--surface); }

.avatar-sm{
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary-dark);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: .74rem;
  margin-right: .55rem;
}

.badge{ font-weight: 600; font-size: .7rem; padding: .38em .7em; border-radius: 999px; letter-spacing: .02em; }
.badge-role-admin{ background: var(--warning-light); color: var(--warning); }
.badge-role-user{ background: var(--primary-light); color: var(--primary-dark); }

/* ===========================================================
   Alerts
   =========================================================== */
.alert{ border: none; border-radius: var(--radius-sm); font-size: .875rem; }
.alert-danger{ background: var(--danger-light); color: var(--danger); }
.alert-success{ background: var(--success-light); color: var(--success); }

/* ===========================================================
   Login page
   =========================================================== */
.auth-body{
  background: radial-gradient(1200px 700px at 15% 10%, #124a52 0%, transparent 60%),
              linear-gradient(160deg, var(--sidebar-bg-1) 0%, var(--sidebar-bg-2) 100%);
  min-height: 100vh;
}
.auth-shell{
  min-height: 100vh;
  display: flex;
  align-items: stretch;
  justify-content: center;
}
.auth-panel{
  display: none;
  flex-direction: column;
  justify-content: center;
  color: #eafafa;
  padding: 4rem 3.5rem;
  max-width: 480px;
}
.auth-panel .mark{
  width: 56px; height: 56px;
  border-radius: 16px;
  background: rgba(255,255,255,.1);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 1.4rem;
  margin-bottom: 1.75rem;
}
.auth-panel h1{ font-size: 1.9rem; font-weight: 800; line-height: 1.25; }
.auth-panel p{ color: #9dc7c7; font-size: .95rem; margin-top: .6rem; }
.auth-panel .feature{
  display: flex; align-items: center; gap: .65rem;
  font-size: .86rem; color: #cfe9e9;
  margin-top: .9rem;
}
.auth-panel .feature i{ color: var(--primary-light); }

.auth-form-wrap{
  flex: 1;
  max-width: 460px;
  display: flex;
  align-items: center;
  padding: 2rem 1.25rem;
}
.auth-card{
  width: 100%;
  background: var(--surface-card);
  border-radius: 22px;
  padding: 2.75rem;
  box-shadow: var(--shadow-lg);
}
.auth-card .auth-icon{
  width: 52px; height: 52px;
  border-radius: 15px;
  background: var(--primary-light);
  color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  margin-bottom: 1.1rem;
}
.auth-card h1{ font-size: 1.5rem; font-weight: 800; color: var(--ink); }
.auth-card .hint{ color: var(--text-muted); font-size: .87rem; }

.input-affix{ position: relative; }
.input-affix i{
  position: absolute; left: .85rem; top: 50%; transform: translateY(-50%);
  color: var(--text-soft); font-size: .95rem; pointer-events: none;
}
.input-affix .form-control{ padding-left: 2.5rem; }
.input-affix .toggle-visibility{
  position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
  border: none; background: none; color: var(--text-soft); padding: .3rem .5rem;
}

@media (min-width: 992px){
  .auth-panel{ display: flex; }
}

/* ===========================================================
   Responsive — collapse sidebar under lg
   =========================================================== */
@media (max-width: 991.98px){
  .sidebar{ transform: translateX(-100%); }
  body.sidebar-open .sidebar{ transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop{ display: block; }
  .admin-main{ margin-left: 0; }
  .topbar .menu-toggle{ display: inline-flex; }

  .topbar{ padding: 15px; }
  .admin-content{ padding: 15px; }
  .user-topbar-inner{ padding: 15px; }
  .user-content{ padding: 15px; }
  .user-topbar-account .who{ display: none; }

  .card .card-body{ padding: 1.1rem 1.15rem; }

  /* Tables squish/wrap illegibly on narrow screens by default — force each
     row onto one line and let .table-responsive scroll sideways instead. */
  .table td, .table th{ white-space: nowrap; }
  .table-responsive{ -webkit-overflow-scrolling: touch; }
  .avatar-sm{ margin-right: .4rem; }

  /* Keep action button pairs (e.g. Admin tools) on one row instead of stacking */
  .admin-tools-actions{ flex-wrap: nowrap; }
  .admin-tools-actions .btn{
    flex: 1 1 0;
    min-width: 0;
    padding-left: .5rem;
    padding-right: .5rem;
    font-size: .8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
