/* =====================================================================
   IMWCRC — Islamabad Mind Wellness Clinic & Rehabilitation Centre
   Core stylesheet — white + dark teal (#0D6E6E) + light grey
   ===================================================================== */

:root {
    --teal: #0D6E6E;
    --teal-dark: #094f4f;
    --teal-light: #e4f3f3;
    --grey-bg: #f4f6f6;
    --grey-border: #dfe5e5;
    --text-dark: #1f2d2d;
    --text-muted: #647474;
    --white: #ffffff;
    --danger: #c0392b;
    --danger-bg: #fdecea;
    --success: #1e8a4c;
    --success-bg: #e7f7ee;
    --warning: #b7791f;
    --warning-bg: #fef6e7;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(13, 110, 110, 0.12);
    --sidebar-width: 250px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--grey-bg);
    color: var(--text-dark);
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { color: var(--teal-dark); margin: 0 0 12px; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }

/* ---------------------------------------------------------------- */
/* App shell layout                                                  */
/* ---------------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--teal-dark);
    color: #eafafa;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.12);
}

.sidebar-brand.has-logo-img { flex-direction: column; align-items: flex-start; }

.sidebar-brand .logo-box {
    width: 38px; height: 38px;
    background: var(--white);
    color: var(--teal-dark);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px;
}

.sidebar-brand .brand-text { font-size: 13px; line-height: 1.3; font-weight: 600; }

.sidebar-brand .logo-img { max-height: 44px; max-width: 100%; width: auto; height: auto; object-fit: contain; border-radius: 4px; }

.sidebar-section { padding: 14px 16px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #9fd4d4; }

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: #d7f0f0;
    font-size: 13.5px;
    border-left: 3px solid transparent;
}

.sidebar nav a:hover { background: rgba(255,255,255,0.08); text-decoration: none; }
.sidebar nav a.active { background: rgba(255,255,255,0.14); border-left-color: var(--white); color: var(--white); font-weight: 600; }

.sidebar-footer { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.12); font-size: 12px; color: #9fd4d4; }

.main-content { margin-left: var(--sidebar-width); flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    background: var(--white);
    border-bottom: 1px solid var(--grey-border);
    padding: 12px 24px;
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 50;
}

.topbar .page-title { font-size: 17px; font-weight: 600; color: var(--teal-dark); }
.topbar-right { display: flex; align-items: center; gap: 16px; font-size: 13px; color: var(--text-muted); }
.menu-toggle { display: none; background: none; border: none; font-size: 22px; color: var(--teal-dark); cursor: pointer; }

.content-area { padding: 24px; flex: 1; }

.card {
    background: var(--white);
    border: 1px solid var(--grey-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}

.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--grey-border);
}

/* ---------------------------------------------------------------- */
/* Forms                                                             */
/* ---------------------------------------------------------------- */
.form-group { margin-bottom: 14px; }
.form-row { display: flex; flex-wrap: wrap; gap: 16px; margin: 0 -8px; }
.form-row .form-group { flex: 1 1 220px; padding: 0 8px; min-width: 0; }

label { display: block; font-weight: 600; margin-bottom: 5px; font-size: 13px; color: var(--text-dark); }
label .req { color: var(--danger); }

input[type=text], input[type=password], input[type=date], input[type=number],
input[type=email], input[type=tel], select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--grey-border);
    border-radius: 6px;
    font-size: 14px;
    background: var(--white);
    color: var(--text-dark);
    font-family: inherit;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--teal);
    box-shadow: 0 0 0 3px var(--teal-light);
}

textarea { resize: vertical; min-height: 70px; }

.checkbox-group { display: flex; flex-wrap: wrap; gap: 10px 20px; }
.checkbox-item { display: flex; align-items: center; gap: 6px; font-weight: 400; font-size: 13.5px; }
.checkbox-item input { width: auto; }

fieldset { border: 1px solid var(--grey-border); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 16px; }
legend { font-weight: 700; color: var(--teal-dark); padding: 0 6px; font-size: 13.5px; }

.form-actions { display: flex; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--grey-border); }

/* ---------------------------------------------------------------- */
/* Buttons                                                           */
/* ---------------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 18px; border-radius: 6px; border: 1px solid transparent;
    font-size: 13.5px; font-weight: 600; cursor: pointer; text-decoration: none;
    background: var(--grey-bg); color: var(--text-dark);
}
.btn:hover { text-decoration: none; opacity: 0.92; }
.btn-primary { background: var(--teal); color: var(--white); }
.btn-primary:hover { background: var(--teal-dark); }
.btn-secondary { background: var(--white); border-color: var(--grey-border); color: var(--text-dark); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------------------------------------------------------------- */
/* Tables                                                             */
/* ---------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--grey-border); }
th { background: var(--teal-light); color: var(--teal-dark); font-weight: 700; white-space: nowrap; }
tbody tr:hover { background: #fafefe; }
.table-compact th, .table-compact td { padding: 6px 8px; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.badge-teal { background: var(--teal-light); color: var(--teal-dark); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-grey { background: var(--grey-bg); color: var(--text-muted); }

/* ---------------------------------------------------------------- */
/* Alerts / flash messages                                           */
/* ---------------------------------------------------------------- */
.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 13.5px; border: 1px solid transparent; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: #bfe8cf; }
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: #f4c6c0; }
.alert-info { background: var(--teal-light); color: var(--teal-dark); border-color: #bfe2e2; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: #f2dfab; }

.field-error { color: var(--danger); font-size: 12px; margin-top: 4px; }

/* ---------------------------------------------------------------- */
/* Dashboard stat cards                                              */
/* ---------------------------------------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--white); border: 1px solid var(--grey-border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat-card .stat-value { font-size: 26px; font-weight: 700; color: var(--teal-dark); }
.stat-card .stat-label { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }

/* ---------------------------------------------------------------- */
/* Patient profile                                                   */
/* ---------------------------------------------------------------- */
.profile-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 16px; }
.profile-name { font-size: 20px; font-weight: 700; color: var(--teal-dark); }
.profile-meta { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.module-nav { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0; }
.module-nav a { background: var(--white); border: 1px solid var(--grey-border); border-radius: 20px; padding: 7px 14px; font-size: 12.5px; font-weight: 600; color: var(--teal-dark); }
.module-nav a:hover { background: var(--teal-light); text-decoration: none; }
.module-nav a.has-data { border-color: var(--teal); }

.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 20px; }
.info-item .info-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.info-item .info-value { font-size: 14px; margin-top: 2px; }

/* ---------------------------------------------------------------- */
/* Patient picker (when a module needs a patient first)              */
/* ---------------------------------------------------------------- */
.patient-picker { max-width: 480px; }

/* ---------------------------------------------------------------- */
/* Login page                                                        */
/* ---------------------------------------------------------------- */
.login-body { background: linear-gradient(135deg, var(--teal-dark), var(--teal)); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-wrapper { width: 100%; max-width: 380px; }
.login-card { background: var(--white); border-radius: 12px; padding: 32px 28px; box-shadow: 0 10px 40px rgba(0,0,0,0.2); }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-logo { width: 56px; height: 56px; background: var(--teal); color: var(--white); border-radius: 12px; display: flex; align-items: center; justify-content: center; font-weight: 700; margin: 0 auto 12px; font-size: 15px; }
.login-logo-img { max-height: 80px; max-width: 100%; width: auto; height: auto; object-fit: contain; margin: 0 auto 12px; display: block; }
.login-brand h1 { font-size: 15px; line-height: 1.35; }
.login-subtitle { color: var(--text-muted); font-size: 12.5px; margin-top: 4px; }
.login-footer { text-align: center; color: #d7f0f0; font-size: 12px; margin-top: 16px; }

/* ---------------------------------------------------------------- */
/* Utilities                                                         */
/* ---------------------------------------------------------------- */
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.d-flex { display: flex; }
.gap-8 { gap: 8px; }
.flex-wrap { flex-wrap: wrap; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

/* ---------------------------------------------------------------- */
/* Responsive                                                        */
/* ---------------------------------------------------------------- */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.2); }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }
    .content-area { padding: 16px; }
    .sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 99; }
    .sidebar-backdrop.show { display: block; }
}

@media (max-width: 520px) {
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .card { padding: 14px; }
    .topbar { padding: 10px 14px; }
}

/* ---------------------------------------------------------------- */
/* Print letterhead — hidden on screen, shown only when printing     */
/* ---------------------------------------------------------------- */
.print-letterhead {
    display: none;
    align-items: center;
    gap: 14px;
    padding-bottom: 14px;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--teal);
}
.print-letterhead img { max-height: 72px; max-width: 260px; width: auto; height: auto; object-fit: contain; }
.print-letterhead-name { font-size: 16px; font-weight: 700; color: var(--teal-dark); }
.print-letterhead-tagline { font-size: 11.5px; color: var(--text-muted); font-style: italic; }
.print-letterhead-detail { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ---------------------------------------------------------------- */
/* Print                                                             */
/* ---------------------------------------------------------------- */
@media print {
    .sidebar, .topbar, .form-actions, .no-print, .module-nav, .menu-toggle { display: none !important; }
    .main-content { margin-left: 0 !important; }
    body { background: var(--white); }
    .content-area { padding: 0; }
    .card { box-shadow: none; border: none; padding: 0; }
    a[href]:after { content: ""; }
    .print-letterhead { display: flex; }
}
