/* M2Lab PMS — application styles. Dark theme modelled on the previous Streamlit UI. */

:root {
  --bg: #0e1117;
  --bg-2: #262730;
  --bg-3: #31333f;
  --card: #161a22;
  --border: rgba(250, 250, 250, 0.14);
  --text: #fafafa;
  --muted: #a3a8b8;
  --primary: #ff4b4b;
  --primary-hover: #ff6c6c;
  --success: #21c354;
  --warning: #ffa421;
  --danger: #ff4b4b;
  --info: #3d9df3;
  --radius: 8px;
  --sidebar-w: 300px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.5; }
a { color: var(--info); }
a:hover { color: #6fb6ff; }
h1, h2, h3, h4 { margin: 0 0 0.5em; font-weight: 700; line-height: 1.2; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }
h4 { font-size: 1.05rem; }
p { margin: 0 0 0.75rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
hr, .divider { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
.section-label { color: var(--muted); font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.4rem; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); background: var(--bg-2); padding: 1.25rem 1rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .divider { margin: 0.75rem 0; }
.brand { font-size: 1.35rem; font-weight: 700; line-height: 1.25; }
.user-name { font-weight: 700; font-size: 1.05rem; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link { display: block; padding: 0.45rem 0.75rem; border-radius: var(--radius); color: var(--text); text-decoration: none; }
.nav-link:hover { background: var(--bg-3); color: var(--text); }
.nav-link.active { background: var(--primary); color: #fff; }
.main { flex: 1; min-width: 0; padding: 1.5rem 2.5rem 3rem; max-width: 1500px; }
.page-header { margin-bottom: 1rem; }
.footer { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; }
.sidebar-toggle { display: none; margin-bottom: 1rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; padding: 0.45rem 0.9rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg-2); color: var(--text); font: inherit; line-height: 1.3; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-danger { border-color: rgba(255, 75, 75, 0.5); }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.icon-btn { background: transparent; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: 1rem; }
.icon-btn:hover { color: var(--text); }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

/* Forms */
.field { margin-bottom: 1rem; }
.field label { display: block; margin-bottom: 0.3rem; font-weight: 600; font-size: 0.95rem; }
.req { color: var(--primary); margin-left: 2px; }
.form-control, .form-select, .form-file { width: 100%; padding: 0.5rem 0.7rem; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font: inherit; }
.form-control:focus, .form-select:focus, .form-file:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(255, 75, 75, 0.25); }
.form-control[disabled], .form-select[disabled] { opacity: 0.6; }
textarea.form-control { min-height: 120px; resize: vertical; }
.form-select[multiple] { min-height: 140px; }
.form-select option { background: var(--bg-2); color: var(--text); }
input[type="date"].form-control { color-scheme: dark; }
.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 500 !important; cursor: pointer; }
.form-check-input { width: 1.05rem; height: 1.05rem; accent-color: var(--primary); }
.form-check-list { list-style: none; margin: 0; padding: 0; }
.form-check-list li { margin-bottom: 0.25rem; }
.form-check-list label { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; }
.help { color: var(--muted); font-size: 0.85rem; margin-top: 0.25rem; }
.error { color: var(--danger); font-size: 0.85rem; margin-top: 0.25rem; }
.has-error .form-control, .has-error .form-select { border-color: var(--danger); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.form-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }
input[type="range"] { width: 100%; accent-color: var(--primary); }

/* Cards, metrics, grids */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1.1rem; }
.metric-label { color: var(--muted); font-size: 0.85rem; }
.metric-value { font-size: 2rem; font-weight: 700; line-height: 1.2; }

/* Tables */
.table-wrap { overflow-x: auto; padding: 0.5rem 0.75rem; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 0.6rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.table tr:last-child td { border-bottom: 0; }

/* Badges and status colours (same palette as the old charts) */
.badge { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; background: var(--bg-3); white-space: nowrap; }
.status-not-started { background: #adb5bd; color: #111; }
.status-in-progress { background: #1f77b4; color: #fff; }
.status-completed { background: #2ca02c; color: #fff; }
.status-delayed { background: #ff7f0e; color: #111; }
.status-on-hold { background: #ffbb78; color: #111; }
.status-cancelled { background: #d62728; color: #fff; }
.report-draft { background: #adb5bd; color: #111; }
.report-submitted { background: #1f77b4; color: #fff; }
.report-approved { background: #2ca02c; color: #fff; }
.priority-high { color: var(--danger); font-weight: 600; }
.priority-medium { color: var(--warning); font-weight: 600; }
.priority-low { color: var(--success); font-weight: 600; }
.badge-count { background: var(--primary); color: #fff; border-radius: 999px; padding: 0.1rem 0.5rem; font-size: 0.75rem; font-weight: 700; margin-left: 0.4rem; }

/* Alerts */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.alert-success { background: rgba(33, 195, 84, 0.15); border-color: rgba(33, 195, 84, 0.45); }
.alert-error { background: rgba(255, 75, 75, 0.15); border-color: rgba(255, 75, 75, 0.5); }
.alert-warning { background: rgba(255, 164, 33, 0.15); border-color: rgba(255, 164, 33, 0.5); }
.alert-info { background: rgba(61, 157, 243, 0.15); border-color: rgba(61, 157, 243, 0.5); }

/* Expanders (like the old st.expander) */
.expander { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 0.6rem; background: var(--card); }
.expander > summary { padding: 0.7rem 1rem; cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.expander > summary::-webkit-details-marker { display: none; }
.expander > summary::before { content: "▸"; color: var(--muted); transition: transform 0.15s; }
.expander[open] > summary::before { transform: rotate(90deg); }
.expander-body { padding: 0.25rem 1rem 1rem; border-top: 1px solid var(--border); }
.expander.highlight { border-left: 5px solid gold; background: rgba(255, 215, 0, 0.06); }

/* Progress */
.progress { height: 8px; background: var(--bg-3); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); }

/* Tabs */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; flex-wrap: wrap; }
.tab { padding: 0.5rem 0.9rem; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }

/* Notifications in the sidebar */
.notif-item { padding: 0.5rem 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.notif-item a { color: var(--text); }

/* Charts */
.chart { width: 100%; min-height: 380px; }

/* Auth pages */
.auth-main { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 440px; padding: 1.75rem; }
.auth-title { font-size: 1.5rem; }

/* Responsive */
@media (max-width: 1000px) {
  .cols-3, .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform 0.2s; z-index: 50; width: 280px; box-shadow: 0 0 30px rgba(0, 0, 0, 0.5); }
  .sidebar.open { transform: none; }
  .sidebar-toggle { display: inline-flex; }
  .main { padding: 1rem; }
}
@media (max-width: 600px) {
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
  h1 { font-size: 1.5rem; }
}

/* Tasks */
.prewrap { white-space: pre-wrap; word-break: break-word; }
.inline { display: inline; }
.task-title { font-weight: 700; }
.task-grid { grid-template-columns: 3fr 1fr; }
.chips > div { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; }
.chips label { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: 500; font-size: 0.92rem; }
.chips input[type="checkbox"] { accent-color: var(--primary); }
.comment { border-left: 3px solid var(--border); padding: 0.2rem 0.75rem; margin-bottom: 0.6rem; }
.comment blockquote { margin: 0.25rem 0 0; color: var(--muted); font-style: italic; }
.history-entry { padding: 0.3rem 0; border-bottom: 1px dashed var(--border); }
.history-entry ul { margin: 0.2rem 0 0 1rem; padding: 0; }
.history summary { cursor: pointer; }
@media (max-width: 900px) { .task-grid { grid-template-columns: 1fr; } }

/* Reports, documents, notifications */
.doc-card { display: flex; flex-direction: column; gap: 0.4rem; min-height: 300px; margin-bottom: 0; }
.doc-title { font-weight: 700; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-desc { flex: 1; background: rgba(255, 255, 255, 0.03); border-radius: 4px; padding: 0.5rem; }
.doc-actions { margin-top: auto; }
.card.highlight { border-left: 5px solid gold; }
.notif-row { display: flex; justify-content: space-between; gap: 1rem; padding: 0.6rem 0.25rem; border-bottom: 1px solid var(--border); }
.notif-row.unread { background: rgba(255, 75, 75, 0.06); }
.notif-main { min-width: 0; }
code { background: var(--bg-3); padding: 0.1rem 0.35rem; border-radius: 4px; font-size: 0.9em; }
@media (max-width: 700px) { .notif-row { flex-direction: column; } }
