/* ============================================================
   49G-Tech System — Dorm Management
   UI based on uploaded reference design
   ============================================================ */
:root {
  --bg:           #f4f6f9;
  --panel:        #ffffff;
  --ink:          #1f2937;
  --sub:          #6b7280;
  --line:         #e5e7eb;
  --brand:        #2563eb;
  --brand-dark:   #1d4ed8;
  --brand-light:  #eff6ff;
  --ok:           #16a34a;
  --ok-bg:        #ecfdf5;
  --warn:         #d97706;
  --warn-bg:      #fffbeb;
  --danger:       #dc2626;
  --danger-bg:    #fef2f2;
  --radius:       10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: Arial, Tahoma, "Leelawadee UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}

button, input, select, textarea { font-family: inherit; }

/* ── App layout ── */
.app { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: 230px;
  background: #2d3748;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding-bottom: 16px;
}
.brand {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  padding: 22px 20px 10px;
  letter-spacing: 0.01em;
}
.branch-badge {
  margin: 0 16px 14px;
  font-size: 12.5px;
  color: #93c5fd;
  background: rgba(147,197,253,.12);
  padding: 5px 12px;
  border-radius: 20px;
  display: inline-block;
}
.sidebar select {
  margin: 0 16px 14px;
  width: calc(100% - 32px);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.1);
  color: #fff;
}
.sidebar select option { background: #2d3748; color: #fff; }
.sidebar nav { display: flex; flex-direction: column; flex: 1; }
.sidebar nav a {
  color: #cbd5e1;
  text-decoration: none;
  padding: 11px 20px;
  font-size: 14.5px;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
  display: block;
}
.sidebar nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar nav a.active {
  background: rgba(255,255,255,.12);
  border-left-color: #60a5fa;
  color: #fff;
  font-weight: 700;
}
.sidebar-footer {
  padding: 14px 20px 0;
  border-top: 1px solid rgba(255,255,255,.1);
  margin-top: 10px;
}
.admin-name  { font-size: 13px; color: #e2e8f0; margin-bottom: 6px; }
.logout-link { color: #f87171; font-size: 13px; text-decoration: none; }
.logout-link:hover { text-decoration: underline; }
.brand-credit { color: #64748b; font-size: 11px; margin-top: 10px; }

/* ── Content ── */
.content { flex: 1; padding: 26px 30px; overflow-x: hidden; }

h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--ink);
}
h2 { font-size: 16px; font-weight: 700; margin-bottom: 12px; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.page-header h1 { margin: 0; }

/* ── Toast notification ── */
.flash {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  min-width: 260px; max-width: 380px;
  padding: 14px 18px;
  border-radius: 10px;
  font-size: 14.5px; font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  animation: toastIn .25s ease, toastOut .4s ease 3.6s forwards;
  pointer-events: none;
}
.flash-success { background: #166534; color: #fff; }
.flash-error   { background: #991b1b; color: #fff; }
.flash-info    { background: #1e40af; color: #fff; }

@keyframes toastIn  { from { opacity:0; transform:translateY(16px); } to { opacity:1; transform:translateY(0); } }
@keyframes toastOut { from { opacity:1; } to { opacity:0; pointer-events:none; } }

/* ── Dashboard cards ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--brand);
}
.stat-card.ok::before    { background: var(--ok); }
.stat-card.warn::before  { background: var(--warn); }
.stat-card.danger::before{ background: var(--danger); }
.stat-card .label { font-size: 12.5px; color: var(--sub); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 26px; font-weight: 800; margin-top: 4px; color: var(--brand); }
.stat-card.ok    .value { color: var(--ok); }
.stat-card.warn  .value { color: var(--warn); }
.stat-card.danger .value { color: var(--danger); }
.stat-card .sub-value { font-size: 12.5px; color: var(--sub); margin-top: 2px; }

/* ── Panel/Card ── */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}

/* ── Tables ── */
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.table-wrap table { border: none; }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
table th, table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
table th {
  background: #f9fafb;
  color: var(--sub);
  font-weight: 700;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
table tr:last-child td { border-bottom: none; }
table tbody tr:hover td { background: #f9fafb; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }
label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--sub);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
input[type=text], input[type=number], input[type=password], input[type=date],
input[type=email], input[type=tel], input[type=month], input[type=file],
select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #d1d5db;
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}
textarea { resize: vertical; min-height: 70px; }
.text-muted { color: var(--sub); font-size: 12.5px; margin-top: 4px; }

/* ── Buttons ── */
.btn {
  display: inline-block;
  padding: 9px 18px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 700;
  text-decoration: none;
  border: none;
  cursor: pointer;
  background: var(--brand);
  color: #fff;
  transition: background 0.15s, transform 0.1s;
}
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: scale(.98); }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-secondary:hover { background: #f3f4f6; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.active { background: var(--brand); color: #fff; }
.chk-col { width: 40px; text-align: center; }
input[type=checkbox] { width: 18px; height: 18px; cursor: pointer; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-ok:hover { background: #15803d; }
.btn-ok:disabled { opacity: .6; cursor: wait; }
.btn-danger { background: var(--danger); color: #fff; border: none; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-lg { padding: 12px 26px; font-size: 15px; }

/* ── Badges ── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.badge-vacant, .badge-paid, .badge-active  { background: var(--ok-bg); color: #166534; }
.badge-occupied, .badge-unpaid             { background: var(--danger-bg); color: #991b1b; }
.badge-reserved, .badge-partial            { background: var(--warn-bg); color: #92400e; }
.badge-maintenance, .badge-ended, .badge-terminated { background: #f3f4f6; color: #374151; }
.overdue-badge { background: var(--danger-bg); color: #991b1b; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; }

/* ── Penalty row ── */
.penalty-row { color: var(--danger); font-weight: 700; }

/* ── Login ── */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: #2d3748;
}
.login-box {
  background: #fff;
  padding: 40px 36px;
  border-radius: 14px;
  width: 380px;
  max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-box h1 { text-align: center; font-size: 20px; margin-bottom: 8px; }
.login-box .login-sub { text-align: center; color: var(--sub); font-size: 13px; margin-bottom: 24px; }

/* ── Misc ── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--sub); font-size: 14.5px; }
.actions a, .actions button { margin-right: 6px; }
.section-title {
  font-size: 12px; font-weight: 700; color: var(--sub);
  text-transform: uppercase; letter-spacing: .06em;
  margin: 20px 0 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}
.readonly-notice {
  background: var(--warn-bg); border: 1px solid #fde68a;
  border-radius: 8px; padding: 10px 16px;
  font-size: 13.5px; color: #92400e; margin-bottom: 16px;
}

/* ── Tooltip ── */
.tooltip-wrap { position: relative; display: inline-flex; align-items: center; margin-left: 8px; }
.tooltip-icon {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--brand-light); color: var(--brand);
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; cursor: help;
}
.tooltip-text {
  visibility: hidden; opacity: 0;
  position: absolute; left: 0; top: 26px;
  background: #1f2937; color: #fff;
  padding: 10px 14px; border-radius: 8px;
  font-size: 13px; font-weight: 400;
  width: 280px; z-index: 30;
  transition: opacity 0.15s ease; line-height: 1.6;
}
.tooltip-text ol, .tooltip-text ul { margin: 4px 0 0; padding-left: 18px; }
.tooltip-wrap:hover .tooltip-text { visibility: visible; opacity: 1; }

/* ── Modal ── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff; border-radius: var(--radius);
  padding: 26px 28px; width: 440px; max-width: 92vw;
}
.modal-box h3 { margin: 0 0 18px; font-size: 17px; }
.modal-check { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; font-size: 14px; }
.modal-check input { margin-top: 3px; width: auto; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }

/* ── Dashboard mini bar chart ── */
.mini-bar-wrap { display: flex; align-items: flex-end; gap: 6px; height: 64px; margin-top: 8px; }
.mini-bar {
  flex: 1; border-radius: 4px 4px 0 0;
  background: var(--brand); opacity: .85;
  transition: opacity .2s;
  position: relative;
}
.mini-bar:hover { opacity: 1; }
.mini-bar.warn { background: var(--warn); }
.mini-bar-label { font-size: 10.5px; color: var(--sub); text-align: center; margin-top: 4px; }
.mini-bar-group { text-align: center; flex: 1; }

/* ── Print ── */
@media print {
  .sidebar, .no-print { display: none !important; }
  .content { padding: 0; }
  table th, table td { font-size: 12.5px; padding: 7px 10px; }
}