@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Poppins:wght@500;600&family=Hind:wght@400;500;600&display=swap');

:root {
    color-scheme: light;
    --font-body: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-heading: "Poppins", "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-hindi: "Hind", "Noto Sans Devanagari", Mangal, "Nirmala UI", sans-serif;

    --color-primary: #0A7C5F;
    --color-primary-hover: #086b52;
    --color-primary-active: #075b46;

    /* Legacy aliases */
    --brand-color: #0A7C5F;
    --page-bg: #f8fafc;
    --text-color: #0f172a;

    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;
    --color-text: #0f172a;
    --color-muted: #475569;
    --color-divider: #e5e7eb;
    --shadow-soft: 0 10px 30px rgba(15, 23, 42, 0.08);
    --focus-ring: 0 0 0 3px rgba(10, 124, 95, 0.18);

    --topbar-height: 56px;
    --search-height: 26px;
    --global-search-height: var(--search-height);
}

.theme-dark {
    color-scheme: dark;
    --color-bg: #0f172a;
    --color-surface: #111827;
    --color-border: #1f2937;
    --color-text: #e5e7eb;
    --color-muted: #cbd5e1;
    --color-divider: #1f2937;
    --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.35);
}

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

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-body);
    line-height: 1.6;
    font-size: 16px;
    text-rendering: optimizeLegibility;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color 0.2s ease, opacity 0.2s ease;
}

a:hover { color: var(--color-primary-hover); }
a:active { color: var(--color-primary-active); }

button,
input,
select,
textarea {
    font: inherit;
    font-family: var(--font-body);
}

h1, h2, h3, h4, h5, h6 {
    margin: 0 0 12px;
    line-height: 1.25;
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--color-text);
}
h1 { font-size: 36px; }
h2 { font-size: 28px; }
h3 { font-size: 22px; }
h4 { font-size: 18px; }
h5 { font-size: 16px; }
h6 { font-size: 14px; }

.devanagari, [lang="hi"], .hi-text, [data-lang="hi"] {
    font-family: var(--font-hindi);
}

.container {
    width: min(1100px, 100% - 32px);
    margin: 0 auto;
}

.safe-area {
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 640px) {
    body { font-size: 15px; }
    h1 { font-size: 30px; }
    h2 { font-size: 24px; }
    h3 { font-size: 20px; }
    h4 { font-size: 18px; }
    h5 { font-size: 16px; }
    h6 { font-size: 14px; }
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Cards & surfaces */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: var(--shadow-soft);
    padding: 16px;
    color: var(--color-text);
}

.page-note { color: var(--color-muted); margin: 0 0 16px; }
.page-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0 0 8px;
}

/* Buttons */
.btn {
    background: var(--color-primary);
    color: #fff;
    padding: 10px 14px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: background 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
}
.btn:hover { background: var(--color-primary-hover); }
.btn:active { background: var(--color-primary-active); transform: translateY(1px); }
.btn.secondary {
    background: #e2e8f0;
    color: var(--color-text);
}
.btn.secondary:hover { background: #cbd5e1; }
.btn.secondary:active { background: #c7ccd5; }
.btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* Form controls */
input, select, textarea {
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 10px;
    font-size: 15px;
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--focus-ring);
}

/* Topbar */
body.has-global-topbar { padding-top: calc(var(--topbar-height) + 10px); }
body.has-global-topbar.has-global-search { padding-top: calc(var(--topbar-height) + var(--global-search-height) + 12px); }

.global-topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 1000;
    background: var(--color-primary);
    box-shadow: 0 16px 40px -28px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(10px);
    color: #fff;
}
.global-topbar-inner {
    width: min(1100px, 100% - 20px);
    margin: 0 auto;
    min-height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.home-btn {
    border: 1px solid rgba(255,255,255,0.25);
    background: rgba(255,255,255,0.12);
    color: #fff;
    border-radius: 10px;
    width: 38px;
    height: 38px;
    display: inline-grid;
    place-items: center;
    cursor: pointer;
    transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease, background 0.2s ease;
}
.home-btn:hover {
    background: rgba(255,255,255,0.2);
}
.home-btn:active {
    transform: scale(0.98);
}
.topbar-title {
    font-weight: 700;
    letter-spacing: 0.15px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar-actions {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    position: relative;
}

.icon-btn, .dots-btn, .notif-btn, .theme-toggle-btn {
    min-width: 38px;
    height: 38px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.25);
    background: rgba(255,255,255,0.12);
    display: inline-grid;
    place-items: center;
    cursor: pointer;
    color: #fff;
    transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease, background 0.2s ease;
}
.icon-btn:hover, .dots-btn:hover, .notif-btn:hover, .theme-toggle-btn:hover {
    background: rgba(255,255,255,0.2);
}
.icon-btn:active, .dots-btn:active, .notif-btn:active, .theme-toggle-btn:active {
    transform: scale(0.98);
}
.dots-btn span {
    width: 4px;
    height: 4px;
    background: #fff;
    border-radius: 50%;
    display: block;
}
.dots-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    min-width: 190px;
    padding: 6px;
    box-shadow: var(--shadow-soft);
    opacity: 0;
    transform: translateY(-6px);
    pointer-events: none;
    transition: opacity 150ms ease, transform 150ms ease;
    color: var(--color-text);
}
.topbar-actions.is-open .dots-menu {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}
.dots-menu button {
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    padding: 10px 10px;
    border-radius: 10px;
    font-weight: 600;
    color: var(--color-text);
    cursor: pointer;
}
.dots-menu button:hover,
.dots-menu button:focus-visible {
    background: rgba(10, 124, 95, 0.12);
    outline: none;
}

.home-hindi-btn {
    border: 1px solid rgba(255,255,255,0.25);
    background: rgba(255,255,255,0.18);
    color: #fff;
    padding: 9px 12px;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
}
.home-hindi-btn:focus-visible {
    outline: none;
    border-color: rgba(255,255,255,0.4);
    box-shadow: 0 0 0 3px rgba(255,255,255,0.25);
}

/* Notifications */
.notif-menu {
    position: absolute;
    right: 42px;
    top: calc(100% + 8px);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    min-width: 240px;
    max-height: 320px;
    overflow-y: auto;
    box-shadow: var(--shadow-soft);
    display: none;
    color: var(--color-text);
}
.notif-menu.is-open { display: block; }
.notif-item {
    padding: 10px;
    border-bottom: 1px solid var(--color-divider);
    font-size: 14px;
    line-height: 1.4;
}
.notif-title { font-weight: 700; display: block; margin-bottom: 4px; }
.notif-meta { color: var(--color-muted); font-size: 12px; }

.theme-toggle-btn { font-size: 16px; }
.theme-toggle-btn[data-theme="dark"] { background: rgba(255,255,255,0.25); }

/* Global search */
.global-search {
    position: fixed;
    top: var(--topbar-height);
    left: 0; right: 0;
    z-index: 999;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 12px 36px -26px rgba(0, 0, 0, 0.35);
}
.global-search-inner {
    width: min(1100px, 100% - 20px);
    margin: 0 auto;
    min-height: var(--search-height);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px 0;
    position: relative;
}
.global-search-form {
    width: 100%;
    display: grid;
    grid-template-columns: 32px 1fr 96px;
    gap: 8px;
    align-items: center;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 14px;
    padding: 4px 7px;
}
.global-search-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--color-muted);
}
.global-search-input {
    width: 100%;
    border: none;
    background: transparent;
    font-size: 15px;
    color: var(--color-text);
    outline: none;
}
.global-search-button {
    border: none;
    background: var(--color-primary);
    color: #fff;
    font-weight: 700;
    padding: 6px 9px;
    border-radius: 9px;
    cursor: pointer;
    transition: transform 120ms ease, box-shadow 120ms ease, background 0.2s ease;
    font-size: 15px;
}
.global-search-button:hover { background: var(--color-primary-hover); }
.global-search-button:active { transform: scale(0.98); background: var(--color-primary-active); }
.global-search-button:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.global-search-suggestions {
    position: absolute;
    left: 0; right: 0;
    top: calc(100% - 4px);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: var(--shadow-soft);
    padding: 4px;
    display: none;
    max-height: 360px;
    overflow-y: auto;
    z-index: 1000;
}
.global-search-suggestions.is-visible { display: block; }
.global-search-suggestion {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    text-decoration: none;
    color: var(--color-text);
    cursor: pointer;
}
.global-search-suggestion:hover,
.global-search-suggestion:focus-visible {
    background: rgba(10, 124, 95, 0.12);
    outline: none;
}
.global-search-suggestion .icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(10, 124, 95, 0.12);
    display: grid;
    place-items: center;
    font-size: 16px;
    color: var(--color-primary);
}
.global-search-suggestion .meta { display: grid; gap: 2px; }
.global-search-suggestion .title { font-weight: 700; }
.global-search-suggestion .subtitle { color: var(--color-muted); font-size: 14px; }
.global-search-suggestion.empty { cursor: default; }

/* Language adjustments */
body.has-global-topbar .header { top: var(--topbar-height); }
body.has-global-topbar.has-global-search .header { top: calc(var(--topbar-height) + var(--global-search-height)); }

@media (max-width: 640px) {
    .global-topbar-inner { width: min(100%, 100% - 12px); gap: 8px; }
    .home-hindi-btn { padding: 8px 10px; }
    .global-search-inner { width: min(100%, 100% - 12px); padding: 3px 0; }
    .global-search-form {
        grid-template-columns: 30px 1fr;
        grid-template-rows: auto auto;
        row-gap: 4px;
    }
    .global-search-button { grid-column: 1 / -1; width: 100%; }
}

/* Table and form defaults */
table {
    border-collapse: collapse;
    width: 100%;
    font-size: 15px;
}
th, td {
    padding: 10px;
    border-bottom: 1px solid var(--color-divider);
}
th { text-align: left; font-weight: 600; color: var(--color-text); }

.theme-dark table th,
.theme-dark table td { border-color: var(--color-border); }

/* Utility classes for muted text and dividers */
.muted { color: var(--color-muted); }
.divider { border-top: 1px solid var(--color-divider); margin: 12px 0; }

/* Dark mode specifics */
.theme-dark .global-topbar { background: var(--color-primary); color: #fff; }
.theme-dark .dots-menu,
.theme-dark .notif-menu,
.theme-dark .card,
.theme-dark .global-search,
.theme-dark .global-search-suggestions {
    background: var(--color-surface);
    color: var(--color-text);
}
.theme-dark .global-search-form {
    background: var(--color-bg);
    border-color: var(--color-border);
}
.theme-dark input,
.theme-dark select,
.theme-dark textarea {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}
.theme-dark .global-search-suggestion:hover,
.theme-dark .global-search-suggestion:focus-visible {
    background: rgba(10, 124, 95, 0.16);
}
