/*
 * Lokadarshan design tokens and shared components.
 * Used by the public site, the reader and the CMS.
 */

:root {
    /* Colour */
    --ld-ink: #1b2333;
    --ld-ink-2: #44506a;
    --ld-ink-3: #5c6880;
    --ld-line: #e1e5ec;
    --ld-line-strong: #c8d0dc;
    --ld-paper: #f5f6f8;
    --ld-surface: #ffffff;
    --ld-blue: #2457d6;
    --ld-blue-ink: #173f9f;
    --ld-blue-soft: #eaf0fd;
    --ld-magenta: #c8126f;
    --ld-yellow: #fef33f;
    --ld-yellow-soft: #fffbd2;
    --ld-navy: #194f86;
    --ld-navy-deep: #123a63;
    --ld-green: #11724f;
    --ld-green-soft: #e2f3eb;
    --ld-amber: #8a5300;
    --ld-amber-soft: #fff1d4;
    --ld-red: #b42323;
    --ld-red-soft: #fdeaea;

    /* Type */
    --ld-font-display: "Anek Kannada", "Noto Sans Kannada", system-ui, -apple-system, "Segoe UI", sans-serif;
    --ld-font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Kannada", "Helvetica Neue", Arial, sans-serif;
    --ld-step--1: 0.875rem;
    --ld-step-0: 1rem;
    --ld-step-1: clamp(1.125rem, 1.07rem + 0.25vw, 1.25rem);
    --ld-step-2: clamp(1.3rem, 1.2rem + 0.5vw, 1.6rem);
    --ld-step-3: clamp(1.6rem, 1.38rem + 1vw, 2.2rem);
    --ld-step-4: clamp(2.1rem, 1.6rem + 2.4vw, 3.6rem);

    /* Shape and depth */
    --ld-radius-s: 6px;
    --ld-radius: 10px;
    --ld-radius-l: 14px;
    --ld-shadow-1: 0 1px 2px rgba(27, 35, 51, 0.06);
    --ld-shadow-2: 0 1px 2px rgba(27, 35, 51, 0.06), 0 6px 18px -10px rgba(27, 35, 51, 0.3);
    --ld-shadow-paper: 0 1px 1px rgba(27, 35, 51, 0.1), 0 12px 28px -14px rgba(27, 35, 51, 0.45);

    /* Layout */
    --ld-gutter: 16px;
    --ld-max: 1240px;
    --ld-header-h: 56px;

    /* Bootstrap integration */
    --bs-body-font-family: var(--ld-font-body);
    --bs-body-color: var(--ld-ink);
    --bs-body-bg: var(--ld-paper);
    --bs-border-color: var(--ld-line);
    --bs-primary: var(--ld-blue);
    --bs-primary-rgb: 36, 87, 214;
    --bs-link-color: var(--ld-blue);
    --bs-link-color-rgb: 36, 87, 214;
    --bs-link-hover-color: var(--ld-blue-ink);
    --bs-link-hover-color-rgb: 23, 63, 159;
    --bs-secondary-color: var(--ld-ink-3);
    --bs-focus-ring-color: rgba(36, 87, 214, 0.35);
}

@media (min-width: 600px) {
    :root {
        --ld-gutter: 24px;
    }
}

@media (min-width: 1024px) {
    :root {
        --ld-gutter: 32px;
        --ld-header-h: 60px;
    }
}

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

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

body {
    margin: 0;
    min-height: 100vh;
    background: var(--ld-paper);
    color: var(--ld-ink);
    font-family: var(--ld-font-body);
    font-size: 1rem;
    line-height: 1.55;
    text-rendering: optimizeLegibility;
}

img,
svg,
video,
canvas {
    max-width: 100%;
}

img {
    height: auto;
}

a {
    color: var(--ld-blue);
    text-underline-offset: 0.18em;
}

a:hover {
    color: var(--ld-blue-ink);
}

h1,
h2,
h3,
h4 {
    color: var(--ld-ink);
    font-family: var(--ld-font-display);
    font-stretch: 87.5%;
    line-height: 1.12;
    text-wrap: balance;
}

p {
    text-wrap: pretty;
}

:focus-visible {
    outline: 3px solid var(--ld-blue);
    outline-offset: 2px;
}

.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
    outline: none;
}

.ld-container {
    width: 100%;
    max-width: var(--ld-max);
    margin-inline: auto;
    padding-inline: var(--ld-gutter);
}

.ld-skip-link {
    position: absolute;
    left: 12px;
    top: -60px;
    z-index: 2000;
    padding: 10px 16px;
    border-radius: var(--ld-radius-s);
    background: var(--ld-ink);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
}

.ld-skip-link:focus {
    top: 12px;
    color: #fff;
}

/* Buttons: brand colours on Bootstrap's component variables */
.btn {
    --bs-btn-font-weight: 600;
    --bs-btn-border-radius: var(--ld-radius-s);
    --bs-btn-padding-x: 1rem;
    --bs-btn-focus-box-shadow: 0 0 0 3px rgba(36, 87, 214, 0.35);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 40px;
}

.btn-sm {
    --bs-btn-padding-x: 0.7rem;
    min-height: 32px;
}

.btn-lg {
    min-height: 48px;
}

.btn-primary {
    --bs-btn-bg: var(--ld-blue);
    --bs-btn-border-color: var(--ld-blue);
    --bs-btn-hover-bg: var(--ld-blue-ink);
    --bs-btn-hover-border-color: var(--ld-blue-ink);
    --bs-btn-active-bg: #12347f;
    --bs-btn-active-border-color: #12347f;
    --bs-btn-disabled-bg: var(--ld-blue);
    --bs-btn-disabled-border-color: var(--ld-blue);
}

.btn-outline-primary {
    --bs-btn-color: var(--ld-blue);
    --bs-btn-border-color: var(--ld-blue);
    --bs-btn-hover-bg: var(--ld-blue);
    --bs-btn-hover-border-color: var(--ld-blue);
    --bs-btn-active-bg: var(--ld-blue-ink);
    --bs-btn-active-border-color: var(--ld-blue-ink);
}

.btn-quiet {
    --bs-btn-color: var(--ld-ink);
    --bs-btn-bg: var(--ld-surface);
    --bs-btn-border-color: var(--ld-line-strong);
    --bs-btn-hover-color: var(--ld-ink);
    --bs-btn-hover-bg: var(--ld-paper);
    --bs-btn-hover-border-color: var(--ld-ink-3);
    --bs-btn-active-color: var(--ld-ink);
    --bs-btn-active-bg: #e9ecf1;
    --bs-btn-active-border-color: var(--ld-ink-3);
}

.btn-danger {
    --bs-btn-bg: var(--ld-red);
    --bs-btn-border-color: var(--ld-red);
    --bs-btn-hover-bg: #941b1b;
    --bs-btn-hover-border-color: #941b1b;
}

.btn .bi {
    font-size: 1.05em;
    line-height: 1;
}

.btn[aria-busy="true"] {
    pointer-events: none;
    opacity: 0.75;
}

.btn[aria-busy="true"]::before {
    content: "";
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: ld-spin 0.75s linear infinite;
}

@keyframes ld-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .btn[aria-busy="true"]::before {
        animation-duration: 2.5s;
    }
}

/* Forms */
.form-control,
.form-select {
    min-height: 42px;
    border-color: var(--ld-line-strong);
    border-radius: var(--ld-radius-s);
    color: var(--ld-ink);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--ld-blue);
    box-shadow: 0 0 0 3px rgba(36, 87, 214, 0.2);
}

.form-label {
    margin-bottom: 0.35rem;
    color: var(--ld-ink);
    font-weight: 600;
}

.form-text {
    color: var(--ld-ink-3);
}

.is-invalid,
.form-error .form-control,
.form-error .form-select {
    border-color: var(--ld-red) !important;
}

.error-message,
.invalid-feedback {
    display: block;
    margin-top: 0.3rem;
    color: var(--ld-red);
    font-size: var(--ld-step--1);
    font-weight: 500;
}

input[type="date"].form-control {
    min-width: 0;
}

/* Status badges */
.ld-status {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.6;
    white-space: nowrap;
}

.ld-status::before {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: currentColor;
}

.ld-status--published {
    background: var(--ld-green-soft);
    color: var(--ld-green);
}

.ld-status--draft {
    background: var(--ld-amber-soft);
    color: var(--ld-amber);
}

.ld-status--archived {
    background: #eceef2;
    color: var(--ld-ink-2);
}

/* Empty states */
.ld-empty {
    display: grid;
    justify-items: center;
    gap: 0.5rem;
    padding: clamp(28px, 6vw, 56px) 20px;
    border: 1px dashed var(--ld-line-strong);
    border-radius: var(--ld-radius);
    background: var(--ld-surface);
    text-align: center;
}

.ld-empty .bi {
    color: var(--ld-ink-3);
    font-size: 2rem;
}

.ld-empty h2,
.ld-empty h3 {
    margin: 0;
    font-size: var(--ld-step-1);
}

.ld-empty p {
    max-width: 52ch;
    margin: 0;
    color: var(--ld-ink-2);
}

.ld-empty .ld-empty__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

/* Flash messages rendered inline (public pages) */
.ld-flash {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    margin: 12px 0 0;
    padding: 0.75rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--ld-radius-s);
    font-weight: 500;
}

.ld-flash .bi {
    flex: none;
    margin-top: 0.1rem;
}

.ld-flash--success {
    border-color: #b7e0cc;
    background: var(--ld-green-soft);
    color: #0b5539;
}

.ld-flash--error {
    border-color: #f2c1c1;
    background: var(--ld-red-soft);
    color: #8c1b1b;
}

.ld-flash--warning {
    border-color: #f1d79b;
    background: var(--ld-amber-soft);
    color: #6d4200;
}

.ld-flash--info {
    border-color: #c8d7f8;
    background: var(--ld-blue-soft);
    color: var(--ld-blue-ink);
}

/* Toasts */
.ld-toasts {
    position: fixed;
    inset-inline-end: 16px;
    inset-block-end: 16px;
    z-index: 1090;
    display: grid;
    gap: 8px;
    width: min(380px, calc(100vw - 32px));
    pointer-events: none;
}

.ld-toast {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.8rem 0.9rem;
    border-radius: var(--ld-radius);
    background: var(--ld-ink);
    color: #fff;
    box-shadow: 0 10px 30px -8px rgba(0, 0, 0, 0.45);
    pointer-events: auto;
    animation: ld-toast-in 0.18s ease-out;
}

.ld-toast .bi {
    flex: none;
    margin-top: 0.1rem;
}

.ld-toast--success .bi {
    color: #6ee7b7;
}

.ld-toast--error .bi {
    color: #fca5a5;
}

.ld-toast--warning .bi {
    color: #fcd34d;
}

.ld-toast__body {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

.ld-toast__close {
    flex: none;
    width: 28px;
    height: 28px;
    margin: -4px -4px 0 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #fff;
    opacity: 0.8;
}

.ld-toast__close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.12);
}

@keyframes ld-toast-in {
    from {
        transform: translateY(8px);
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ld-toast {
        animation: none;
    }
}

/* Confirm dialog (native <dialog>) */
.ld-dialog {
    width: min(460px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    padding: 0;
    border: 0;
    border-radius: var(--ld-radius-l);
    color: var(--ld-ink);
    box-shadow: 0 24px 60px -12px rgba(15, 23, 42, 0.45);
}

.ld-dialog::backdrop {
    background: rgba(15, 23, 42, 0.5);
}

.ld-dialog__body {
    padding: 22px 22px 8px;
}

.ld-dialog__title {
    margin: 0 0 0.4rem;
    font-size: var(--ld-step-1);
}

.ld-dialog__message {
    margin: 0;
    color: var(--ld-ink-2);
}

.ld-dialog__input {
    margin-top: 0.9rem;
}

.ld-dialog__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 22px 20px;
}

/* Small utilities */
.ld-muted {
    color: var(--ld-ink-3);
}

.ld-nowrap {
    white-space: nowrap;
}

.ld-tabular {
    font-variant-numeric: tabular-nums;
}

@media print {
    .ld-toasts,
    .ld-skip-link {
        display: none !important;
    }
}
