/* ============================================================
   HFMS v4.0 - Custom Stylesheet
   ============================================================ */

/* ── Root Variables ─────────────────────────────────────── */
:root {
  --sidebar-width: 250px;
  --sidebar-collapsed-width: 70px;
  --sidebar-bg: #1e2a38;
  --sidebar-hover: #2d3e52;
  --sidebar-active: #0d6efd;
  --topbar-height: 56px;
  --card-radius: .75rem;
}

/* ── Base ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background-color: #f4f6fb;
  color: #2c3e50;
  overflow-x: hidden;
}

/* ── Layout ──────────────────────────────────────────────── */
.wrapper {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  color: #cdd6e0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width .25s ease;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1040;
  overflow-x: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed .sidebar-label,
.sidebar.collapsed .sidebar-section-title,
.sidebar.collapsed .sidebar-footer-text {
  display: none;
}

.sidebar.collapsed .sidebar-link {
  justify-content: center;
  padding: .65rem 0;
}

.sidebar-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: var(--topbar-height);
}

.sidebar-logo {
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-logo span { color: #4da3ff; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: .5rem 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
}

.sidebar-section-title {
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6c8aab;
  padding: .9rem 1.25rem .3rem;
  white-space: nowrap;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .55rem 1.25rem;
  color: #bcc8d4;
  text-decoration: none;
  border-radius: 0;
  transition: background .18s, color .18s;
  white-space: nowrap;
  font-size: .9rem;
}

.sidebar-link i {
  font-size: 1.1rem;
  min-width: 22px;
  text-align: center;
}

.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar-link.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
}

.sidebar-footer {
  padding: .75rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.07);
  font-size: .8rem;
  color: #5a7a98;
}

/* ── Main Content ────────────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  transition: margin-left .25s ease;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.main-content.expanded {
  margin-left: var(--sidebar-collapsed-width);
}

.page-content {
  padding: 1.25rem;
  flex: 1;
}

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid #e9ecef;
  position: sticky;
  top: 0;
  z-index: 1030;
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

#topClock {
  font-size: .85rem;
  color: #6c757d;
  white-space: nowrap;
}

/* ── Stat Cards ──────────────────────────────────────────── */
.stat-card {
  border-radius: var(--card-radius);
  padding: 1.25rem;
  color: #fff;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
}

.stat-card .stat-icon {
  font-size: 1.8rem;
  opacity: .7;
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

.stat-card .stat-label {
  font-size: .82rem;
  opacity: .85;
  margin-top: .25rem;
}

/* ── Generic Cards ───────────────────────────────────────── */
.card {
  border: 1px solid #e8ecf0;
  border-radius: var(--card-radius);
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}

.card-header {
  background: #fff;
  border-bottom: 1px solid #edf0f3;
  font-weight: 600;
  font-size: .93rem;
  padding: .75rem 1rem;
}

/* ── Login Page ──────────────────────────────────────────── */
.login-wrapper {
  min-height: 100vh;
  background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  background: rgba(255,255,255,.97);
  border-radius: 1.2rem;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.login-logo {
  font-size: 2rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: .25rem;
}

/* ── Dashboard Clock Widget ──────────────────────────────── */
#clock-widget {
  text-align: center;
  padding: 1.5rem 1rem;
}

#clock-display {
  font-size: 3.5rem;
  font-weight: 700;
  line-height: 1;
  background: linear-gradient(135deg, #0d6efd, #6610f2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#date-display {
  font-size: 1rem;
  color: #495057;
  margin-top: .25rem;
}

#lunar-display {
  font-size: .82rem;
  color: #c0392b;
  margin-top: .1rem;
}

/* ── Weather Widget ──────────────────────────────────────── */
.weather-widget {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .75rem 1rem;
}

.weather-widget .weather-icon {
  font-size: 2.5rem;
}

.weather-widget .weather-temp {
  font-size: 2rem;
  font-weight: 700;
}

.weather-widget .weather-desc {
  font-size: .85rem;
  color: #6c757d;
  text-transform: capitalize;
}

/* ── Timetable Grid ──────────────────────────────────────── */
.timetable-table td, .timetable-table th {
  padding: .4rem .5rem;
  vertical-align: middle;
  font-size: .85rem;
}

/* ── Timetable clickable grid ────────────────────────────── */
.tt-cell {
  cursor: pointer;
  vertical-align: middle;
  transition: background .12s;
  min-width: 90px;
}
.tt-cell:hover { background: #e8f4fd; }

.tt-cell-inner {
  min-height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  text-align: center;
  font-size: .8rem;
}
.tt-cell-inner.has-entry {
  background: linear-gradient(135deg, #e3f2fd, #bbdefb);
  color: #1565c0;
  font-weight: 500;
  border-left: 3px solid #42a5f5;
}
.tt-cell:hover .tt-cell-inner.has-entry {
  background: linear-gradient(135deg, #bbdefb, #90caf9);
}
.tt-cell-inner.empty-entry {
  opacity: .25;
  font-size: 1.1rem;
}
.tt-cell:hover .tt-cell-inner.empty-entry { opacity: .6; }

.tt-meta {
  font-size: .7rem;
  color: #1976d2;
  opacity: .85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ── Kanban (Plans) ──────────────────────────────────────── */
.kanban-col {
  background: #f1f3f5;
  border-radius: .75rem;
  padding: .75rem;
  min-height: 200px;
}

.kanban-col .kanban-header {
  font-weight: 600;
  font-size: .9rem;
  margin-bottom: .75rem;
  padding-bottom: .5rem;
  border-bottom: 2px solid;
}

.kanban-card {
  background: #fff;
  border-radius: .5rem;
  padding: .75rem;
  margin-bottom: .6rem;
  box-shadow: 0 2px 6px rgba(0,0,0,.07);
  cursor: pointer;
  transition: box-shadow .18s;
}

.kanban-card:hover {
  box-shadow: 0 4px 14px rgba(0,0,0,.13);
}

/* ── Warranty Progress Bar ───────────────────────────────── */
.warranty-bar .progress {
  height: 6px;
  border-radius: 3px;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c1c9d2; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #98a6b5; }

/* ── News Feed Widget ────────────────────────────────────── */
.news-src-btn {
  font-size: .72rem;
  padding: .2rem .55rem;
  border-radius: 20px;
  border: 1px solid #dee2e6;
  background: transparent;
  color: #6c757d;
  transition: all .2s;
  white-space: nowrap;
}
.news-src-btn:hover {
  background: #e9ecef;
  border-color: #adb5bd;
  color: #343a40;
}
.news-src-btn.active {
  background: #0d6efd;
  border-color: #0d6efd;
  color: #fff;
}
.news-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: .75rem;
}
.news-item {
  display: flex;
  gap: .6rem;
  align-items: flex-start;
  padding: .5rem .65rem;
  border-radius: .5rem;
  background: #f8f9fa;
  text-decoration: none;
  color: inherit;
  transition: background .15s;
  border: 1px solid transparent;
}
.news-item:hover {
  background: #e8f0fe;
  border-color: #c7d9fb;
  text-decoration: none;
  color: inherit;
}
.news-thumb {
  width: 72px;
  height: 54px;
  object-fit: cover;
  border-radius: .35rem;
  flex-shrink: 0;
  background: #dee2e6;
}
.news-thumb-placeholder {
  width: 72px;
  height: 54px;
  border-radius: .35rem;
  background: linear-gradient(135deg, #e3e8f0, #c8d3e0);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #9ba8b7;
  font-size: 1.3rem;
}
.news-title {
  font-size: .82rem;
  font-weight: 600;
  line-height: 1.35;
  color: #212529;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.news-meta {
  font-size: .7rem;
  color: #6c757d;
  margin-top: .2rem;
}
.news-spin {
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0 !important;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1039;
  }

  .sidebar-overlay.active { display: block; }

  #clock-display { font-size: 2.5rem; }

  .stat-card .stat-value { font-size: 1.5rem; }
}

@media (max-width: 576px) {
  .page-content { padding: .75rem; }
  .login-card { padding: 1.75rem 1.25rem; }
}

/* ── Utility Helpers ─────────────────────────────────────── */
.opacity-60 { opacity: .6; }
.cursor-pointer { cursor: pointer; }
.text-truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Alerts ──────────────────────────────────────────────── */
.alert {
  border-radius: .6rem;
  border-left: 4px solid transparent;
}
.alert-success { border-left-color: #198754; }
.alert-danger  { border-left-color: #dc3545; }
.alert-warning { border-left-color: #ffc107; }
.alert-info    { border-left-color: #0dcaf0; }

/* ── Toast notification ──────────────────────────────────── */
#toastContainer {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

/* ── Tables ──────────────────────────────────────────────── */
.table th {
  font-weight: 600;
  font-size: .88rem;
  white-space: nowrap;
}

.table td {
  vertical-align: middle;
  font-size: .88rem;
}

/* ── Blood pressure classification badges ────────────────── */
.bp-low           { background: #3498db; }
.bp-normal        { background: #2ecc71; }
.bp-pre-hyper     { background: #f39c12; }
.bp-hypertension  { background: #e74c3c; }

/* ── Avatar ──────────────────────────────────────────────── */
.avatar-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #dee2e6;
}

.avatar-circle-lg {
  width: 80px;
  height: 80px;
}

/* ── Print ───────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .btn, .modal, #toastContainer { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; }
}
