:root {
  --color-1: #072044;
  --color-2: #064489;
  --color-3: #5790A8;
  --color-4: #8ECOBE;
  --color-5: #D0C7E1;
  --color-4-real: #8ec0be;
  --white: #ffffff;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-500: #64748b;
  --gray-700: #334155;
  --gray-900: #0f172a;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --sidebar-width: 260px;
  --topbar-height: 60px;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(7,32,68,.10);
  --shadow-lg: 0 8px 32px rgba(7,32,68,.18);
  --transition: .2s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Segoe UI', system-ui, sans-serif; background: var(--gray-100); color: var(--gray-900); font-size: 15px; }

/* ===================== LAYOUT ===================== */
.app-wrapper { display: flex; height: 100vh; overflow: hidden; }
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.content-area { flex: 1; overflow-y: auto; padding: 28px; }

/* ===================== SIDEBAR ===================== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-1);
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  transition: width var(--transition);
  z-index: 300;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}
.sidebar.collapsed { width: 64px; }
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,.10);
  min-height: 72px;
  flex-shrink: 0;
}
.logo-img { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: white; }
.logo-text { display: flex; flex-direction: column; overflow: hidden; }
.logo-main { font-size: 16px; font-weight: 800; color: var(--white); letter-spacing: 1px; }
.logo-sub { font-size: 10px; color: rgba(255,255,255,.65); line-height: 1.3; white-space: nowrap; }
.sidebar.collapsed .logo-text { display: none; }
.sidebar-nav { padding: 10px 0; flex: 1; }
.nav-group { margin-bottom: 4px; }
.nav-group-title {
  padding: 8px 16px 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--color-4-real);
  letter-spacing: .08em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar.collapsed .nav-group-title { display: none; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  color: rgba(255,255,255,.78);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
}
.nav-item:hover { background: rgba(255,255,255,.10); color: var(--white); }
.nav-item.active { background: var(--color-2); color: var(--white); }
.nav-item i { width: 20px; text-align: center; flex-shrink: 0; font-size: 15px; }
.nav-item.nav-sub { padding-left: 32px; font-size: 13px; }
.sidebar.collapsed .nav-item span { display: none; }
.sidebar.collapsed .nav-item { padding: 12px; justify-content: center; }
.sidebar.collapsed .nav-item.nav-sub { padding-left: 12px; }

/* Sidebar mobile overlay backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 299;
  backdrop-filter: blur(1px);
}
.sidebar-backdrop.active { display: block; }

/* ===================== TOPBAR ===================== */
.topbar {
  height: var(--topbar-height);
  background: var(--white);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--gray-200);
  box-shadow: var(--shadow);
  flex-shrink: 0;
  z-index: 50;
}
.sidebar-toggle {
  background: none;
  border: none;
  color: var(--color-1);
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius);
  transition: var(--transition);
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--gray-100); }
.page-title { font-size: 17px; font-weight: 700; color: var(--color-1); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--gray-700);
  font-size: 14px;
  flex-shrink: 0;
}
.topbar-user i { font-size: 20px; color: var(--color-2); }
.topbar-user > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.btn-logout {
  background: var(--danger);
  color: white;
  border: none;
  padding: 7px 13px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: var(--transition);
  flex-shrink: 0;
}
.btn-logout:hover { background: #b91c1c; }

/* ===================== CARDS ===================== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}
.card-title { font-size: 16px; font-weight: 700; color: var(--color-1); }

/* ===================== STATS ===================== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
  border-left: 4px solid var(--color-2);
}
.stat-card.c1 { border-color: var(--color-1); }
.stat-card.c2 { border-color: var(--color-2); }
.stat-card.c3 { border-color: var(--color-3); }
.stat-card.c4 { border-color: #16a34a; }
.stat-icon { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.stat-card.c1 .stat-icon { background: rgba(7,32,68,.1); color: var(--color-1); }
.stat-card.c2 .stat-icon { background: rgba(6,68,137,.1); color: var(--color-2); }
.stat-card.c3 .stat-icon { background: rgba(87,144,168,.1); color: var(--color-3); }
.stat-card.c4 .stat-icon { background: #f0fdf4; color: #16a34a; }
.stat-info { flex: 1; min-width: 0; }
.stat-value { font-size: 24px; font-weight: 800; color: var(--color-1); line-height: 1; }
.stat-label { font-size: 12px; color: var(--gray-500); margin-top: 4px; }

/* ===================== BUTTONS ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-primary { background: var(--color-2); color: white; }
.btn-primary:hover { background: var(--color-1); }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-300); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #b45309; }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-outline { background: transparent; border: 2px solid var(--color-2); color: var(--color-2); }
.btn-outline:hover { background: var(--color-2); color: white; }

/* ===================== TABLES ===================== */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }
table { width: 100%; border-collapse: collapse; min-width: 480px; }
th {
  background: var(--color-1);
  color: white;
  padding: 11px 14px;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
td { padding: 10px 14px; border-bottom: 1px solid var(--gray-200); font-size: 13px; vertical-align: middle; }
tr:hover td { background: var(--gray-50); }
.actions { display: flex; gap: 6px; flex-wrap: nowrap; }

/* ===================== BADGES ===================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-info { background: #eff6ff; color: #2563eb; }
.badge-gray { background: var(--gray-100); color: var(--gray-500); }
.badge-primary { background: rgba(6,68,137,.1); color: var(--color-2); }
.badge-purple { background: #f3e8ff; color: #7c3aed; }

/* ===================== FORMS ===================== */
.form-group { margin-bottom: 16px; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
select, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-300);
  border-radius: 8px;
  font-size: 14px;
  color: var(--gray-900);
  background: white;
  transition: var(--transition);
  outline: none;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M6 8L0 0h12z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
input:focus, select:focus, textarea:focus { border-color: var(--color-2); box-shadow: 0 0 0 3px rgba(6,68,137,.10); }
textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.form-check { display: flex; align-items: center; gap: 8px; }
.form-check input[type=checkbox] { width: 18px; height: 18px; }

/* ===================== ALERTS ===================== */
.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
}
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid #bbf7d0; }
.alert-danger { background: var(--danger-light); color: var(--danger); border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-light); color: var(--warning); border: 1px solid #fde68a; }
.alert-info { background: #eff6ff; color: #2563eb; border: 1px solid #bfdbfe; }

/* ===================== MODAL ===================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(7,32,68,.5);
  z-index: 900; display: none; backdrop-filter: blur(2px);
}
.modal-overlay.active { display: block; }
.modal {
  display: none;
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: white; border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 95%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  z-index: 1000; padding: 24px;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 10px; }
.modal-title { font-size: 16px; font-weight: 700; color: var(--color-1); }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--gray-500); transition: var(--transition); flex-shrink: 0; }
.modal-close:hover { color: var(--danger); }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--gray-200); flex-wrap: wrap; }

/* ===================== LOGIN ===================== */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--color-1) 0%, var(--color-2) 60%, var(--color-3) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: white;
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(7,32,68,.35);
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}
.login-logo { width: 90px; height: 90px; object-fit: contain; margin-bottom: 12px; }
.login-title { font-size: 19px; font-weight: 800; color: var(--color-1); margin-bottom: 4px; }
.login-subtitle { font-size: 13px; color: var(--gray-500); margin-bottom: 28px; }
.login-form .form-group { text-align: left; }
.login-form input { font-size: 15px; padding: 12px 16px; }
.login-btn { width: 100%; padding: 13px; font-size: 16px; margin-top: 6px; border-radius: 10px; }

/* ===================== FILTER BAR ===================== */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filter-bar input, .filter-bar select { max-width: 220px; width: auto; min-width: 130px; }
.search-input { flex: 1; max-width: 320px !important; min-width: 150px !important; }

/* ===================== PAGINATION ===================== */
.pagination { display: flex; gap: 6px; justify-content: center; padding: 14px 0; flex-wrap: wrap; }
.page-btn {
  padding: 7px 13px; border: 1.5px solid var(--gray-300); border-radius: 8px;
  background: white; cursor: pointer; font-size: 13px; color: var(--gray-700);
  text-decoration: none; transition: var(--transition);
}
.page-btn:hover, .page-btn.active { background: var(--color-2); color: white; border-color: var(--color-2); }

/* ===================== EMPTY STATE ===================== */
.empty-state { text-align: center; padding: 40px 20px; color: var(--gray-500); }
.empty-state i { font-size: 48px; color: var(--gray-300); margin-bottom: 14px; }
.empty-state h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }

/* ===================== STEPPER ===================== */
.stepper { display: flex; gap: 0; margin-bottom: 24px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.step {
  flex: 1;
  min-width: 100px;
  text-align: center;
  padding: 10px 6px;
  background: var(--gray-100);
  border-bottom: 3px solid var(--gray-300);
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
}
.step.active { background: rgba(6,68,137,.08); border-color: var(--color-2); color: var(--color-2); }
.step.done { background: var(--success-light); border-color: var(--success); color: var(--success); }
.step-num { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; background: var(--gray-300); color: white; font-size: 11px; margin-right: 5px; }
.step.active .step-num { background: var(--color-2); }
.step.done .step-num { background: var(--success); }

/* ===================== PHOTO GRID ===================== */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-top: 10px; }
.photo-item { position: relative; border-radius: 8px; overflow: hidden; aspect-ratio: 1; background: var(--gray-100); border: 2px solid var(--gray-200); }
.photo-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-item .remove-photo { position: absolute; top: 4px; right: 4px; background: var(--danger); color: white; border: none; border-radius: 50%; width: 22px; height: 22px; cursor: pointer; font-size: 11px; display: flex; align-items: center; justify-content: center; }

/* ===================== PRINT ===================== */
.tarja-print { display: none; }
@media print {
  .sidebar, .topbar, .card-header .btn, .actions, .no-print { display: none !important; }
  .main-content { margin: 0 !important; }
  .content-area { padding: 0 !important; }
  .tarja-print { display: block; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}

/* ===================== RESPONSIVE — TABLET (≤1024px) ===================== */
@media (max-width: 1024px) {
  :root { --sidebar-width: 220px; }
  .content-area { padding: 20px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===================== RESPONSIVE — MOBILE (≤768px) ===================== */
@media (max-width: 768px) {
  /* Sidebar: slide-in drawer */
  .sidebar {
    position: fixed;
    left: -280px;
    width: 260px !important;
    height: 100vh;
    z-index: 300;
    transition: left .25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,.3);
  }
  .sidebar.mobile-open { left: 0; }
  .sidebar.collapsed { left: -280px; }

  /* No more desktop collapse on mobile */
  .sidebar.collapsed .logo-text,
  .sidebar.collapsed .nav-group-title,
  .sidebar.collapsed .nav-item span { display: flex !important; }
  .sidebar.collapsed .nav-item { padding: 11px 20px !important; justify-content: flex-start !important; }
  .sidebar.collapsed .nav-item.nav-sub { padding-left: 32px !important; }

  /* Topbar */
  .topbar { padding: 0 12px; gap: 8px; }
  .page-title { font-size: 15px; }
  .topbar-user > span { display: none; }
  .topbar-user i { font-size: 18px; }

  /* Content */
  .content-area { padding: 14px; }

  /* Cards */
  .card { padding: 14px; }
  .card-header { margin-bottom: 14px; }

  /* Stats 2 col on small mobile */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; gap: 10px; }
  .stat-icon { width: 38px; height: 38px; font-size: 16px; border-radius: 8px; }
  .stat-value { font-size: 20px; }

  /* Tables - horizontal scroll */
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 8px; }
  table { min-width: 540px; }
  th, td { padding: 9px 12px; font-size: 12px; }

  /* Filter bar - full width */
  .filter-bar { flex-direction: column; gap: 8px; }
  .filter-bar input, .filter-bar select, .search-input { max-width: 100% !important; width: 100% !important; min-width: unset !important; }

  /* Buttons */
  .btn { font-size: 13px; padding: 8px 14px; }
  .btn-sm { font-size: 11px; padding: 5px 9px; }

  /* Form */
  .form-row { grid-template-columns: 1fr; gap: 12px; }

  /* Modal */
  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 95vh;
    border-radius: 16px 16px 0 0;
    top: auto;
    bottom: 0;
    left: 0;
    transform: none;
    padding: 20px 16px;
  }
  .modal-footer { justify-content: stretch; }
  .modal-footer .btn { flex: 1; justify-content: center; }

  /* Stepper - scrollable */
  .stepper { gap: 2px; }
  .step { min-width: 80px; font-size: 11px; padding: 8px 4px; }
  .step-num { width: 18px; height: 18px; font-size: 10px; margin-right: 3px; }
}

/* ===================== RESPONSIVE — SMALL MOBILE (≤480px) ===================== */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 12px; gap: 8px; }
  .stat-value { font-size: 18px; }
  .stat-label { font-size: 11px; }
  .login-card { padding: 28px 20px; }
  .content-area { padding: 10px; }
  .card { padding: 12px; }
}
