/* ===================================================
   Irodori Web App — Modern UI
   =================================================== */

:root {
  --red:     #e53e3e;
  --red-d:   #c53030;
  --red-l:   #fff5f5;
  --blue:    #3182ce;
  --green:   #38a169;
  --orange:  #dd6b20;
  --purple:  #805ad5;
  --gray-50: #f7fafc;
  --gray-100:#edf2f7;
  --gray-200:#e2e8f0;
  --gray-400:#a0aec0;
  --gray-600:#718096;
  --gray-800:#2d3748;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-md: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
  --shadow-lg: 0 20px 25px rgba(0,0,0,.1), 0 10px 10px rgba(0,0,0,.04);
  --radius:  .75rem;
  --radius-sm: .5rem;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f0f2f5;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--gray-800);
  font-size: .9rem;
}
img, svg, video, canvas, iframe { max-width: 100%; }
.min-w-0 { min-width: 0; }
.container-fluid.py-3 { flex: 1; padding: 1.5rem !important; max-width: 1400px; margin: 0 auto; }

/* ── Navbar ── */
.navbar {
  background: linear-gradient(135deg, #c0392b 0%, #e74c3c 100%) !important;
  box-shadow: 0 2px 12px rgba(192,57,43,.4);
  padding: .6rem 1.5rem;
}
.navbar-brand {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.navbar-brand .brand-icon {
  width: 32px; height: 32px;
  background: rgba(255,255,255,.2);
  border-radius: .5rem;
  display: flex; align-items: center; justify-content: center;
}
.nav-link {
  font-weight: 500;
  padding: .4rem .8rem !important;
  border-radius: .4rem;
  transition: background .15s;
}
.nav-link:hover { background: rgba(255,255,255,.15); }
.nav-link.active { background: rgba(255,255,255,.2); }
.admin-login-link {
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.14);
}
.admin-login-link:hover {
  background: rgba(255,255,255,.24);
}
.navbar-nav .dropdown-toggle::after { display: none; }
.navbar .badge { font-size: .65rem; padding: .2em .5em; }
.navbar-toggler:focus { box-shadow: 0 0 0 .15rem rgba(255,255,255,.35); }

/* ── Page header ── */
.page-header { margin-bottom: 1.5rem; }
.page-header h4 {
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--gray-800);
  margin: 0;
}
.page-header .breadcrumb { margin: 0; font-size: .8rem; }

/* ── Stat cards ── */
.stat-card {
  border-radius: var(--radius);
  border: none;
  overflow: hidden;
  transition: transform .2s, box-shadow .2s;
  cursor: default;
}
.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg) !important;
}
.stat-card .card-body {
  padding: 1.25rem;
  position: relative;
}
.stat-card .stat-icon {
  width: 52px; height: 52px;
  border-radius: .7rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}
.stat-card .stat-value {
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.02em;
}
.stat-card .stat-label {
  font-size: .78rem;
  font-weight: 500;
  opacity: .75;
  margin-top: .2rem;
}
/* Gradient variants */
.stat-red    { background: linear-gradient(135deg, #e53e3e 0%, #fc8181 100%); color: #fff; }
.stat-blue   { background: linear-gradient(135deg, #3182ce 0%, #63b3ed 100%); color: #fff; }
.stat-green  { background: linear-gradient(135deg, #38a169 0%, #68d391 100%); color: #fff; }
.stat-orange { background: linear-gradient(135deg, #dd6b20 0%, #f6ad55 100%); color: #fff; }
.stat-purple { background: linear-gradient(135deg, #805ad5 0%, #b794f4 100%); color: #fff; }
.stat-dark   { background: linear-gradient(135deg, #2d3748 0%, #4a5568 100%); color: #fff; }
.stat-card .stat-icon { background: rgba(255,255,255,.2); }

/* ── Cards ── */
.card {
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s;
}
.card:hover { box-shadow: var(--shadow); }
.card-header {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  padding: .9rem 1.25rem;
  font-weight: 600;
  border-radius: var(--radius) var(--radius) 0 0 !important;
}
.card-body { padding: 1.25rem; }
.card-footer {
  background: var(--gray-50);
  border-top: 1px solid var(--gray-200);
  padding: .75rem 1.25rem;
  border-radius: 0 0 var(--radius) var(--radius) !important;
}

/* ── Lesson cards ── */
.lesson-card {
  border-radius: var(--radius) !important;
  transition: transform .2s, box-shadow .2s !important;
  overflow: hidden;
}
.lesson-card:hover {
  transform: translateY(-5px) !important;
  box-shadow: var(--shadow-md) !important;
}
.lesson-card .lesson-num-badge {
  width: 44px; height: 44px;
  border-radius: .6rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  font-weight: 800;
  flex-shrink: 0;
}

/* ── Level tabs ── */
.level-tabs { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.level-tab {
  padding: .5rem 1.2rem;
  border-radius: 2rem;
  border: 2px solid var(--gray-200);
  background: #fff;
  font-weight: 600;
  font-size: .85rem;
  cursor: pointer;
  text-decoration: none;
  color: var(--gray-600);
  transition: all .15s;
  white-space: nowrap;
}
.level-tab:hover { border-color: var(--red); color: var(--red); }
.level-tab.active { background: var(--red); border-color: var(--red); color: #fff; }
.level-tab .jlpt-badge {
  display: inline-block;
  font-size: .65rem;
  padding: .1em .4em;
  border-radius: .3rem;
  margin-right: .3rem;
}

/* ── Audio player panel ── */
.player-bar {
  background: linear-gradient(135deg, #1a202c, #2d3748);
  border-radius: var(--radius-sm);
  padding: 1rem;
  color: #fff;
  margin-bottom: .75rem;
}
.player-bar .track-name { font-size: .85rem; font-weight: 600; margin-bottom: .1rem; }
.player-bar .track-type { font-size: .7rem; opacity: .6; }
.audio-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .6rem;
  border-radius: .4rem;
  cursor: pointer;
  transition: background .12s;
}
.audio-item:hover { background: var(--gray-100); }
.audio-item.active {
  background: #fff0f0;
  border-left: 3px solid var(--red);
}
.audio-item .play-btn {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem;
  flex-shrink: 0;
  border: none;
  cursor: pointer;
  transition: transform .1s;
}
.audio-item:hover .play-btn { transform: scale(1.1); }
.audio-item .file-label { font-size: .78rem; flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.audio-item .seq-badge { font-size: .65rem; color: var(--gray-400); flex-shrink: 0; }

/* Activity group headers */
.activity-group { margin-bottom: .5rem; }
.activity-group-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  background: var(--gray-50);
  border-radius: .4rem;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 600;
  color: var(--gray-700);
  border: none;
  width: 100%;
  text-align: left;
  transition: background .12s;
}
.activity-group-header:hover { background: var(--gray-100); }
.activity-group-header .group-icon {
  width: 24px; height: 24px;
  border-radius: .35rem;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem;
  flex-shrink: 0;
}
.activity-group-header .count-badge {
  margin-left: auto;
  font-size: .7rem;
  padding: .15em .5em;
  border-radius: .3rem;
  font-weight: 700;
}
.activity-group-header .chevron {
  font-size: .7rem;
  transition: transform .2s;
  opacity: .5;
}
.activity-group-header.open .chevron { transform: rotate(180deg); }
.activity-group-body { padding: .25rem 0; }

/* Accordion override */
.accordion-item { border-radius: var(--radius-sm) !important; margin-bottom: .4rem; overflow: hidden; }
.accordion-button { font-size: .82rem; font-weight: 600; padding: .6rem .9rem; }
.accordion-button:not(.collapsed) { background: #fff8f8; color: var(--red); box-shadow: none; }
.accordion-button:focus { box-shadow: none; }
.accordion-body { padding: .3rem .2rem; }

/* ── Tables ── */
.table { font-size: .85rem; }
.table th { font-weight: 600; color: var(--gray-600); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.table td { vertical-align: middle; }
.table-hover tbody tr:hover { background: var(--gray-50); }
.table-responsive { -webkit-overflow-scrolling: touch; }

/* ── Buttons ── */
.btn { font-weight: 600; border-radius: .5rem; font-size: .85rem; }
.btn-danger { background: linear-gradient(135deg, #e53e3e, #c53030); border: none; }
.btn-danger:hover { background: linear-gradient(135deg, #c53030, #9b2c2c); border: none; }
.btn-sm { font-size: .78rem; padding: .3rem .7rem; }
.btn-lg { padding: .75rem 1.5rem; font-size: .95rem; }

/* ── Badges ── */
.badge { font-weight: 600; letter-spacing: .01em; }

/* ── Forms ── */
.form-control, .form-select {
  border-radius: .5rem;
  border: 1.5px solid var(--gray-200);
  font-size: .85rem;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(229,62,62,.15);
}
.input-group-text { background: var(--gray-50); border: 1.5px solid var(--gray-200); border-radius: .5rem 0 0 .5rem; }

/* ── Nav tabs (lesson page) ── */
.nav-tabs { border-bottom: 2px solid var(--gray-200); }
.nav-tabs .nav-link {
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  color: var(--gray-600);
  padding: .6rem 1rem;
  font-weight: 600;
  font-size: .85rem;
  margin-bottom: -2px;
}
.nav-tabs .nav-link:hover { color: var(--red); border-color: transparent; }
.nav-tabs .nav-link.active { color: var(--red); border-bottom-color: var(--red); background: none; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ── Login page ── */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #e53e3e 50%, #dd6b20 100%);
}
.login-card {
  width: 100%;
  max-width: 420px;
  border-radius: 1.25rem;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.login-card .card-top {
  background: linear-gradient(135deg, #c53030, #e53e3e);
  padding: 2rem;
  text-align: center;
  color: #fff;
}
.login-card .card-top .logo-ring {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1rem;
  font-size: 2rem;
  backdrop-filter: blur(4px);
}

.mobile-only { display: none !important; }

/* ── Alert ── */
.alert { border-radius: var(--radius-sm); border: none; font-size: .85rem; }

/* ── Progress bar ── */
.progress { border-radius: 2rem; height: 8px; background: var(--gray-200); }
.progress-bar { border-radius: 2rem; }

/* ── Responsive ── */
@media (max-width: 768px) {
  body { font-size: .88rem; background: #f6f7f9; }
  .container-fluid.py-3 {
    width: 100%;
    padding: .75rem !important;
  }
  .navbar { padding: .55rem .75rem; }
  .navbar > .container-fluid {
    padding-left: 0;
    padding-right: 0;
  }
  .navbar-brand {
    min-width: 0;
    max-width: calc(100vw - 72px);
    font-size: 1rem;
  }
  .navbar-brand .brand-icon {
    width: 30px;
    height: 30px;
  }
  .navbar-collapse {
    margin-top: .65rem;
    padding-top: .65rem;
    border-top: 1px solid rgba(255,255,255,.2);
  }
  .navbar-nav { gap: .25rem; }
  .navbar-nav .nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: .65rem .75rem !important;
  }
  .navbar-nav.ms-auto {
    margin-top: .35rem;
    align-items: stretch !important;
  }
  .navbar-nav .dropdown-menu {
    width: 100%;
    margin-top: .25rem;
  }
  .page-header,
  .d-flex.align-items-center.justify-content-between.mb-4,
  .d-flex.align-items-center.justify-content-between.mb-3 {
    align-items: flex-start !important;
  }
  .page-header h4,
  h4.fw-bold,
  h4.mb-0 {
    font-size: 1.05rem;
    line-height: 1.25;
  }
  .card { border-radius: .65rem; }
  .card-header {
    padding: .75rem .9rem;
    gap: .5rem;
  }
  .card-body { padding: .9rem; }
  .card-footer { padding: .65rem .9rem; }
  .stat-card:hover,
  .lesson-card:hover,
  .hover-lift:hover {
    transform: none !important;
  }
  .stat-card .card-body {
    padding: .85rem;
    gap: .65rem !important;
  }
  .stat-card .stat-icon {
    width: 40px;
    height: 40px;
    font-size: 1.15rem;
  }
  .stat-card .stat-value { font-size: 1.5rem; }
  .stat-card .stat-label { font-size: .72rem; }
  .level-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: .1rem .05rem .45rem;
    margin: 0 -.05rem 1rem;
    scrollbar-width: none;
  }
  .level-tabs::-webkit-scrollbar { display: none; }
  .level-tab {
    flex: 0 0 auto;
    padding: .55rem .9rem;
    font-size: .8rem;
  }
  .lesson-card .lesson-num-badge {
    width: 38px;
    height: 38px;
    margin-bottom: .75rem !important;
  }
  .lesson-card .card-footer .btn,
  .card-footer .btn.px-5 {
    width: 100%;
    padding-left: .75rem !important;
    padding-right: .75rem !important;
  }
  .btn {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: normal;
  }
  .btn-sm {
    min-height: 36px;
    padding: .38rem .62rem;
  }
  .btn-lg {
    min-height: 48px;
    padding: .75rem 1rem;
  }
  .form-control,
  .form-select,
  .input-group-text {
    min-height: 42px;
    font-size: 16px;
  }
  .table {
    min-width: 720px;
    font-size: .82rem;
  }
  .table th,
  .table td {
    white-space: nowrap;
  }
  .modal-dialog { margin: .75rem; }
  #roleCards {
    flex-direction: column;
  }
  #roleCards .role-card {
    min-height: 64px;
  }
  footer {
    padding-left: .75rem;
    padding-right: .75rem;
  }
  .mobile-only { display: initial !important; }
  .desktop-only { display: none !important; }
}

@media (max-width: 576px) {
  .row-cols-2 > * { width: 100%; }
  .card-header.d-flex,
  .card-body.d-flex {
    flex-wrap: wrap;
  }
  .audio-item {
    min-height: 44px;
    padding: .55rem .6rem;
  }
  .audio-item .play-btn {
    width: 34px;
    height: 34px;
  }
  .audio-item .file-label { font-size: .82rem; }
  .player-bar { padding: .85rem; }
  .login-bg {
    align-items: stretch;
    padding: .75rem;
  }
  .login-card {
    max-width: none;
    align-self: center;
    border-radius: 1rem;
  }
  .login-top { padding: 1.5rem 1rem; }
  .login-body { padding: 1.2rem; }
}

/* ── Utility ── */
.text-truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.hover-lift { transition: transform .2s, box-shadow .2s; }
.hover-lift:hover { transform: translateY(-3px); box-shadow: var(--shadow-md) !important; }
.bg-gradient-red { background: linear-gradient(135deg, #e53e3e, #c53030); }
.separator { height: 1px; background: var(--gray-200); margin: 1rem 0; }
