:root {
  --bg: #f0f2f5;
  --surface: #fff;
  --border: #e8eaed;
  --border-input: #d8dce2;
  --text: #1a1d21;
  --text-secondary: #5f6b7a;
  --text-muted: #8b95a5;
  --green: #50965c;
  --green-hover: #458a51;
  --green-soft: #eef6ef;
  --green-border: #c5dfc9;
  --link: #2563eb;
  --red: #e5484d;
  --red-soft: #fff0f0;
  --red-border: #ffd4d4;
  --orange: #e5a000;
  --orange-soft: #fff8e6;
  --orange-border: #ffe8a3;
  --gray-soft: #f4f5f7;
  --sidebar-w: 72px;
  --header-h: 64px;
  --font: "Inter", system-ui, sans-serif;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* —— Login —— */
.login-page {
  display: flex;
  min-height: 100vh;
  width: 100%;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
}

.login-card h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 16px 0 8px;
}

.login-card .muted { margin-bottom: 20px; color: var(--text-secondary); }

.itgenio-logo {
  display: block;
  object-fit: contain;
}

.itgenio-logo--login {
  width: auto;
  max-width: 160px;
  height: 48px;
  margin: 0 auto 8px;
}

.itgenio-logo--sidebar {
  width: 44px;
  height: 44px;
  border-radius: 10px;
}

/* —— App shell —— */
.app-shell {
  display: flex;
  flex-direction: row;
  min-height: 100vh;
  width: 100%;
}

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  z-index: 100;
}

.sidebar-logo { margin-bottom: 20px; }

.nav-icons {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 0 10px;
}

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin: 0 auto;
  border-radius: 12px;
  color: var(--text-muted);
  text-decoration: none;
}

.nav-icon:hover { background: var(--gray-soft); color: var(--text-secondary); }

.nav-icon.active {
  background: var(--green-soft);
  color: var(--green);
  box-shadow: inset 0 0 0 1px var(--green-border);
}

.workspace {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: calc(100% - var(--sidebar-w));
}

.global-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.global-search {
  flex: 1;
  min-width: 0;
  max-width: 480px;
  position: relative;
}

.global-search svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.global-search input {
  width: 100%;
  height: 40px;
  padding: 0 16px 0 42px;
  border: 1px solid var(--border-input);
  border-radius: 999px;
  background: #fafbfc;
  font: inherit;
  font-size: 0.875rem;
}

.global-search input:disabled { opacity: 0.6; }

.header-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:disabled { opacity: 0.45; cursor: default; }

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 8px;
  margin-left: 4px;
}

.user-avatar-img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.user-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  min-width: 0;
}

.user-name {
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role { font-size: 0.75rem; color: var(--text-muted); }

.btn-text {
  border: none;
  background: none;
  font: inherit;
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px 12px;
  white-space: nowrap;
}

.btn-text:hover { color: var(--text); }

/* —— Page —— */
.page {
  padding: 24px;
  flex: 1;
}

.page-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 28px 20px;
  max-width: 1400px;
  position: relative;
}

.page-card.is-busy::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.55);
  border-radius: inherit;
  pointer-events: none;
  z-index: 20;
}

.page-card.is-busy::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border: 3px solid var(--green-border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  z-index: 21;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.page-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.title-icon {
  display: flex;
  color: var(--green);
  flex-shrink: 0;
}

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  margin-bottom: 20px;
}

.table-search {
  position: relative;
  flex: 0 1 280px;
  min-width: 200px;
}

.table-search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.table-search input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 36px;
  border: 1px solid var(--border-input);
  border-radius: 999px;
  font: inherit;
  font-size: 0.875rem;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1 1 auto;
  justify-content: flex-end;
  min-width: 0;
}

.chip {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.chip:hover { border-color: var(--green-border); color: var(--green); }

.chip.active {
  border-color: var(--green);
  color: var(--green);
  background: var(--green-soft);
}

/* —— Table —— */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
}

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

th {
  text-align: left;
  padding: 12px 14px;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

tbody tr:hover td { background: #fafbfc; }

.student-cell {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 200px;
}

.student-photo {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--gray-soft);
}

.student-info strong {
  display: block;
  font-weight: 500;
  font-size: 0.9375rem;
  margin-bottom: 2px;
}

.student-info span {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.date-cell .sub {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge.ok { background: var(--green-soft); color: #3d7345; border: 1px solid var(--green-border); }
.badge.ok::before { background: var(--green); }
.badge.expired { background: var(--red-soft); color: #c41e1e; border: 1px solid var(--red-border); }
.badge.expired::before { background: var(--red); }
.badge.off { background: var(--gray-soft); color: var(--text-secondary); border: 1px solid var(--border); }
.badge.off::before { background: var(--text-muted); }
.badge.payment { background: var(--orange-soft); color: #9a6700; border: 1px solid var(--orange-border); }
.badge.payment::before { background: var(--orange); }

.link-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 220px;
}

.link-url {
  font-size: 0.8125rem;
  color: var(--link);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-url:hover { text-decoration: underline; }

.icon-copy {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-copy:hover {
  border-color: var(--green);
  color: var(--green);
  background: var(--green-soft);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  position: relative;
  z-index: 2;
}

.btn-menu {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  flex-shrink: 0;
  position: relative;
  z-index: 3;
}

.btn-menu:hover { background: var(--gray-soft); }

.link-text {
  font-size: 0.8125rem;
  color: var(--link);
  word-break: break-all;
}

.row-menu {
  position: fixed;
  z-index: 10000;
  min-width: 220px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14);
}

.row-menu.hidden { display: none; }

.row-menu button {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font: inherit;
  font-size: 0.875rem;
  color: var(--text);
  cursor: pointer;
}

.row-menu button:hover { background: var(--gray-soft); }

.row-menu button.danger { color: var(--red); }

.row-menu button.danger:hover { background: var(--red-soft); }

.row-menu button.hidden { display: none; }

.field-hint {
  display: block;
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.slug-preview {
  display: block;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--gray-soft);
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.field-readonly { margin-bottom: 12px; }

/* —— Mobile cards —— */
.cards-mobile { display: none; }

.access-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  background: #fff;
}

.access-card-head {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.access-card-meta {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.access-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

/* —— Footer —— */
.table-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding-top: 20px;
  margin-top: 12px;
  border-top: 1px solid var(--border);
}

.showing-range {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin: 0;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.page-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}

.page-btn:hover:not(:disabled) { background: var(--gray-soft); }

.page-btn.active {
  background: var(--green-soft);
  border-color: var(--green-border);
  color: var(--green);
  font-weight: 600;
}

.page-btn:disabled { opacity: 0.35; cursor: default; }

.per-page {
  display: flex;
  justify-content: flex-end;
}

.per-page select {
  width: auto;
  height: 36px;
  padding: 0 32px 0 12px;
  border-radius: 8px;
  font-size: 0.875rem;
}

.empty-state {
  padding: 48px 16px;
  text-align: center;
  color: var(--text-muted);
}

.flash {
  margin: 0 24px 16px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--green-soft);
  border: 1px solid var(--green-border);
  color: #3d7345;
  font-size: 0.875rem;
}

.flash.is-err {
  background: var(--red-soft);
  border-color: var(--red-border);
  color: #c41e1e;
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 10px;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-primary {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

.btn-primary:hover { background: var(--green-hover); }

.btn-outline {
  background: #fff;
  border-color: var(--border-input);
  color: var(--text);
}

.btn-outline:hover { background: var(--gray-soft); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
}

.btn-sm { padding: 7px 14px; font-size: 0.8125rem; border-radius: 8px; }

.btn-block { width: 100%; }

/* —— Form / dialog —— */
input, select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  background: #fff;
  color: var(--text);
}

input:focus, select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b95a5' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.field { display: block; margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.muted { color: var(--text-secondary); }
.err { color: var(--red); font-size: 0.875rem; margin-top: 8px; }

dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  max-width: 440px;
  width: calc(100vw - 32px);
  max-height: min(90vh, 640px);
  overflow-y: auto;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.18);
  position: fixed;
  inset: 0;
  margin: auto;
}

dialog:not([open]) { display: none !important; }

dialog::backdrop { background: rgba(26, 29, 33, 0.45); }

.modal-form h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 20px;
}

.duration-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.duration-presets button {
  padding: 6px 12px;
  font: inherit;
  font-size: 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-secondary);
  cursor: pointer;
}

.duration-presets button.selected,
.duration-presets button:hover {
  border-color: var(--green);
  color: var(--green);
  background: var(--green-soft);
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field-advanced { margin-bottom: 16px; font-size: 0.85rem; color: var(--text-secondary); }
.field-advanced summary { cursor: pointer; margin-bottom: 8px; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}

/* —— Responsive —— */
@media (max-width: 1100px) {
  .filter-chips { justify-content: flex-start; }
  .table-footer { grid-template-columns: 1fr; text-align: center; }
  .per-page { justify-content: center; }
  .showing-range { text-align: center; }
}

@media (max-width: 900px) {
  .user-meta { display: none; }
  .global-search { max-width: none; }
  .header-tools .icon-btn:nth-child(1) { display: none; }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .workspace { margin-left: 0; }
  .global-header { padding: 0 16px; gap: 8px; }
  .page { padding: 12px; }
  .page-card { padding: 16px; border-radius: 12px; }
  .page-top { margin-bottom: 16px; }
  .page-top .btn-primary {
  width: 100%;
  justify-content: center;
  position: relative;
  z-index: 5;
  cursor: pointer;
}
  .table-desktop { display: none; }
  .cards-mobile { display: block; }
  .filter-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .chip { flex-shrink: 0; }
  .table-search { flex: 1 1 100%; }
  .btn-text { display: none; }
  .flash { margin: 0 12px 12px; }
}

@media (max-width: 480px) {
  .row-2 { grid-template-columns: 1fr; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .btn { width: 100%; }
}
