* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; overflow-x: hidden; }
html.dark {
  --bg: #0f1220; --bg2: #171b2e; --card: #1e2338; --card2: #262c47;
  --accent: #7c5cff; --accent2: #ff5c93; --text: #eef0fb; --muted: #9aa0c3;
  --danger: #ff4d6d; --border: rgba(255,255,255,0.08); --input-bg: #12162a;
}
html.light {
  --bg: #f4f5fb; --bg2: #eceef8; --card: #ffffff; --card2: #f1f2fa;
  --accent: #7c5cff; --accent2: #ff5c93; --text: #1c1e2e; --muted: #676c8a;
  --danger: #e0324f; --border: rgba(0,0,0,0.08); --input-bg: #f7f7fc;
}
:root { --radius: 16px; }
html { background: var(--bg); }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(160deg, var(--bg), var(--bg2));
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
}

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; min-height: 100dvh; padding: 20px; }
.login-card {
  background: var(--card); padding: 40px 28px; border-radius: var(--radius);
  width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
  border: 1px solid var(--border);
}
.login-card h1 { text-align: center; font-size: 26px; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 24px; font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.login-card label { font-size: 13px; color: var(--muted); margin-top: 8px; }
.login-card input {
  padding: 13px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--input-bg); color: var(--text); font-size: 16px; width: 100%;
}
.login-card button {
  margin-top: 18px; padding: 14px; border: none; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white; font-weight: 600; font-size: 16px; cursor: pointer;
}
.alert-error { background: rgba(255,77,109,0.15); color: var(--danger); padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; text-align: center; }

.app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; width: 100%; max-width: 100vw; overflow-x: hidden; }
.topbar {
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px 14px; background: var(--bg2);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30;
  width: 100%; max-width: 100vw;
}
.topbar-row1 { display: flex; align-items: center; justify-content: space-between; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.brand { font-weight: 700; font-size: 19px; }
.user-info { display: none; flex-direction: column; align-items: flex-start; gap: 8px; font-size: 14px; color: var(--muted); width: 100%; padding-top: 4px; border-top: 1px solid var(--border); }
.user-info.show { display: flex; }
.btn-mini {
  padding: 8px 14px; border-radius: 20px; background: var(--card);
  color: var(--text); text-decoration: none; font-size: 13px; border: 1px solid var(--border); cursor: pointer;
}
.btn-logout { color: var(--danger); }
.burger { background: var(--card); border: 1px solid var(--border); color: var(--text); font-size: 18px; cursor: pointer; border-radius: 10px; padding: 6px 12px; }

.search-wrap { position: relative; width: 100%; }
.search-wrap input {
  width: 100%; padding: 11px 14px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--input-bg); color: var(--text); font-size: 15px;
}
.search-results {
  display: none; position: absolute; top: 110%; left: 0; right: 0; background: var(--card);
  border: 1px solid var(--border); border-radius: 12px; max-height: 340px; overflow-y: auto;
  box-shadow: 0 12px 30px rgba(0,0,0,.25); z-index: 40;
}
.search-results.show { display: block; }
.search-results .sr-item { padding: 10px 14px; cursor: pointer; font-size: 13px; border-top: 1px solid var(--border); }
.search-results .sr-item:first-child { border-top: none; }
.search-results .sr-item:hover { background: var(--card2); }
.search-results .sr-meta { font-size: 11px; color: var(--muted); }

.tabs { display: flex; gap: 6px; padding: 10px 12px; overflow-x: auto; background: var(--bg2); border-bottom: 1px solid var(--border); -webkit-overflow-scrolling: touch; scrollbar-width: none; max-width: 100vw; }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn { position: relative; padding: 10px 16px; border: none; border-radius: 30px; background: var(--card); color: var(--muted); font-size: 13px; cursor: pointer; white-space: nowrap; flex-shrink: 0; }
.tab-btn.active { background: var(--accent); color: white; }
.badge { display: none; position: absolute; top: 2px; right: 2px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent2); }
.badge.show { display: inline-block; }

.content { flex: 1; padding: 16px; width: 100%; max-width: 1200px; margin: 0 auto; overflow-x: hidden; }
.tab-panel { display: none; animation: fade .3s ease; }
.tab-panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none;} }

.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.panel-header h2 { font-size: 20px; }
.rdv-view-toggle { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }

.btn-primary { padding: 11px 18px; border: none; border-radius: 10px; cursor: pointer; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: white; font-weight: 600; font-size: 14px; }
.btn-secondary { padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer; font-size: 13px; }
.btn-danger { background: var(--danger); color: white; border: none; padding: 6px 12px; border-radius: 8px; font-size: 12px; cursor: pointer; }
.btn-small { padding: 6px 12px; border-radius: 8px; font-size: 12px; border: 1px solid var(--border); background: var(--card2); color: var(--text); cursor: pointer; }

.year-groups { display: flex; flex-direction: column; gap: 24px; }
.year-block h3 { margin-bottom: 12px; font-size: 17px; color: var(--accent2); }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.media-card, .doc-card { background: var(--card); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); display: flex; flex-direction: column; }
.media-card img, .media-card video, .doc-card img { width: 100%; height: 140px; object-fit: cover; background: var(--card2); display: block; }
.doc-card.pdf-card { align-items: center; justify-content: center; padding: 30px 12px; }
.doc-card .pdf-icon { font-size: 46px; margin-bottom: 8px; }
.media-info { padding: 10px 12px; font-size: 13px; }
.media-info .title { font-weight: 600; margin-bottom: 4px; }
.media-info .meta { color: var(--muted); font-size: 11px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

.inline-form { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 140px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-size: 15px; }
.simple-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.idea-item { background: var(--card); padding: 14px; border-radius: 12px; border: 1px solid var(--border); }
.idea-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.idea-top .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.replies { margin-top: 12px; padding-left: 14px; border-left: 2px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.reply-item { background: var(--card2); padding: 8px 12px; border-radius: 10px; font-size: 13px; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.reply-item .meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.reply-form { display: flex; gap: 8px; margin-top: 10px; }
.reply-form input { flex: 1; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-size: 13px; }

.rdv-card { background: var(--card); border-radius: var(--radius); padding: 14px; border: 1px solid var(--border); }
.rdv-card.past { opacity: 0.5; }
.rdv-card h4 { margin-bottom: 6px; }
.rdv-card .meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; }

.cal-header { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 14px; }
.cal-header h3 { min-width: 140px; text-align: center; text-transform: capitalize; font-size: 15px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-daylabel { text-align: center; font-size: 10px; color: var(--muted); padding-bottom: 4px; }
.cal-day { background: var(--card); border: 1px solid var(--border); border-radius: 8px; min-height: 46px; padding: 4px; cursor: pointer; font-size: 11px; }
.cal-day.other-month { opacity: 0.25; }
.cal-day.today { border-color: var(--accent); border-width: 2px; }
.cal-day .num { font-weight: 600; margin-bottom: 3px; }
.cal-day .dot-row { display: flex; gap: 2px; flex-wrap: wrap; }
.cal-day .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent2); }
#calDayDetail { margin-top: 16px; }

.chat-box { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; height: 56vh; max-height: 480px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; -webkit-overflow-scrolling: touch; }
.chat-msg { max-width: 82%; padding: 9px 13px; border-radius: 14px; background: var(--card2); align-self: flex-start; word-break: break-word; }
.chat-msg.mine { align-self: flex-end; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: white; }
.chat-msg .who { font-size: 11px; opacity: .8; margin-bottom: 3px; font-weight: 600; }
.chat-msg .when { font-size: 10px; opacity: .6; margin-top: 3px; }
.chat-msg .del-btn { float: right; cursor: pointer; opacity: .7; margin-left: 8px; }

.hint { color: var(--muted); font-size: 13px; }

.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); align-items: flex-end; justify-content: center; z-index: 50; }
.modal.open { display: flex; }
.modal-box { background: var(--card); padding: 22px; border-radius: 20px 20px 0 0; width: 100%; max-width: 460px; border: 1px solid var(--border); max-height: 88vh; overflow-y: auto; }
.modal-box h3 { margin-bottom: 16px; }
.modal-box form { display: flex; flex-direction: column; gap: 10px; }
.modal-box label { font-size: 13px; color: var(--muted); }
.modal-box input, .modal-box textarea, .modal-box select { padding: 12px 13px; border-radius: 10px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-size: 16px; width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }

.stats-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.stats-bar .stat { background: var(--card); padding: 14px 18px; border-radius: 14px; text-align: center; min-width: 90px; border: 1px solid var(--border); flex: 1; }
.stats-bar .stat .num { font-size: 22px; font-weight: 700; color: var(--accent2); }
.stats-bar .stat .lbl { font-size: 11px; color: var(--muted); }
.admin-grid { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 16px; width: 100%; }
.admin-block { background: var(--card); padding: 18px; border-radius: var(--radius); border: 1px solid var(--border); width: 100%; max-width: 100%; overflow: hidden; }
.admin-block h2 { margin-bottom: 14px; font-size: 17px; }
.inline-form-col { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; width: 100%; }
.inline-form-col input, .inline-form-col select { padding: 12px 13px; border-radius: 10px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-size: 15px; width: 100%; max-width: 100%; }
#docForm, #userForm { width: 100%; max-width: 100%; }
#docForm input[type="file"] { width: 100%; max-width: 100%; font-size: 13px; }
#docForm input[type="text"] { width: 100%; margin-top: 8px; }
.table-scroll { overflow-x: auto; width: 100%; max-width: 100%; -webkit-overflow-scrolling: touch; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 480px; }
.admin-table th, .admin-table td { padding: 9px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.logs-box { max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.log-line { font-size: 12px; padding: 8px 10px; background: var(--card2); border-radius: 8px; word-break: break-word; }
.log-line .action { font-weight: 600; color: var(--accent2); }
.log-line .when { color: var(--muted); display: block; font-size: 10px; margin-top: 3px; }

@media (min-width: 769px) {
  .topbar { flex-direction: row; align-items: center; padding: 16px 24px; }
  .topbar-row1 { width: auto; }
  .burger { display: none; }
  .search-wrap { max-width: 320px; }
  .user-info { display: flex !important; flex-direction: row; width: auto; border-top: none; padding-top: 0; }
  .tabs { padding: 12px 24px; }
  .content { padding: 24px; }
  .admin-grid { grid-template-columns: 1fr 1fr; }
  .cal-day { min-height: 70px; font-size: 12px; }
  .cal-header h3 { min-width: 180px; }
}
