/* ======================================================
   Jordan PG Grade Map — Ministry of Transportation
   Modern Government UI Stylesheet
   ====================================================== */

:root {
    /* Brand Colors — Jordanian Flag */
    --color-gov-green: #007A3D;
    --color-gov-green-light: #00994D;
    --color-gov-red: #CE1126;
    --color-gov-black: #0F1419;
    --color-gov-white: #FFFFFF;

    /* Neutral Palette */
    --color-bg-body: #F0F2F5;
    --color-bg-sidebar: #FFFFFF;
    --color-bg-header: #0F1419;
    --color-bg-card: #F7F8FA;
    --color-bg-card-hover: #EEF0F4;

    --color-text-primary: #1A1D21;
    --color-text-secondary: #5F6B7A;
    --color-text-tertiary: #8B95A2;
    --color-text-inverse: #FFFFFF;
    --color-text-accent: #007A3D;

    --color-border: #E2E5EA;
    --color-border-light: #ECEEF2;
    --color-divider: #F0F2F5;

    /* Typography */
    --font-en: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-ar: 'Cairo', 'Segoe UI', sans-serif;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12), 0 4px 8px rgba(0, 0, 0, 0.06);
    --shadow-sidebar: 4px 0 24px rgba(0, 0, 0, 0.06);

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    /* Sizing */
    --header-height: 64px;
    --sidebar-width: 400px;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration-fast: 180ms;
    --duration-normal: 280ms;
    --duration-slow: 400ms;
}

/* ==============================
   Reset & Base
   ============================== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-en);
    color: var(--color-text-primary);
    background-color: var(--color-bg-body);
    overflow: hidden;
    line-height: 1.6;
}

html[dir="rtl"] body {
    font-family: var(--font-ar);
}

/* ==============================
   App Layout
   ============================== */
.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;  /* Use dynamic viewport height for mobile */
    width: 100vw;
    position: relative;
}

/* Flag accent bar at the very top */
.app-layout::before {
    content: '';
    display: block;
    height: 3px;
    width: 100%;
    background: linear-gradient(
        to right,
        var(--color-gov-red) 0%,
        var(--color-gov-red) 25%,
        var(--color-gov-black) 25%,
        var(--color-gov-black) 50%,
        var(--color-gov-white) 50%,
        var(--color-gov-white) 75%,
        var(--color-gov-green) 75%,
        var(--color-gov-green) 100%
    );
    flex-shrink: 0;
    z-index: 100;
}

/* ==============================
   Header
   ============================== */
.app-header {
    flex: 0 0 var(--header-height);
    background: var(--color-bg-header);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.25rem;
    z-index: 50;
    position: relative;
}

/* Subtle bottom highlight line on header */
.app-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(
        to right,
        transparent,
        rgba(255, 255, 255, 0.06) 20%,
        rgba(255, 255, 255, 0.06) 80%,
        transparent
    );
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    min-width: 0;
}

/* Hamburger / Toggle button */
.btn-icon {
    background: transparent;
    border: none;
    color: var(--color-text-inverse);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--duration-fast) ease, transform var(--duration-fast) ease;
    flex-shrink: 0;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-icon:active {
    transform: scale(0.92);
}

/* Flag Badge */
.gov-badge {
    flex-shrink: 0;
}

/* Titles */
.titles {
    min-width: 0;
}

.titles h1 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--color-text-inverse);
    line-height: 1.25;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-subtitle {
    font-size: 0.7rem;
    color: var(--color-text-tertiary);
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    display: block;
    margin-top: 1px;
}

html[dir="rtl"] .header-subtitle {
    text-transform: none;
    letter-spacing: normal;
}

.header-right {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* ==============================
   Language Toggle
   ============================== */
.lang-toggle {
    display: flex;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 2px;
}

.lang-toggle button {
    background: transparent;
    border: none;
    padding: 0.3rem 0.75rem;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.5);
    transition: all var(--duration-fast) ease;
    font-family: inherit;
    line-height: 1;
}

.lang-toggle button:hover {
    color: rgba(255, 255, 255, 0.75);
}

.lang-toggle button.active {
    background: var(--color-gov-green);
    color: var(--color-text-inverse);
    box-shadow: 0 1px 4px rgba(0, 122, 61, 0.35);
}

/* Language Specific Visibility */
html[lang="en"] .lang-ar-only { display: none !important; }
html[lang="ar"] .lang-en-only { display: none !important; }

/* ==============================
   Body Structure
   ============================== */
.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* ==============================
   Sidebar
   ============================== */
.app-sidebar {
    flex: 0 0 var(--sidebar-width);
    background: var(--color-bg-sidebar);
    border-right: 1px solid var(--color-border-light);
    display: flex;
    flex-direction: column;
    z-index: 10;
    box-shadow: var(--shadow-sidebar);
    transition: margin var(--duration-slow) var(--ease-out);
    will-change: margin;
}

.app-sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}

html[dir="rtl"] .app-sidebar {
    border-right: none;
    border-left: 1px solid var(--color-border-light);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.06);
}

html[dir="rtl"] .app-sidebar.collapsed {
    margin-left: 0;
    margin-right: calc(-1 * var(--sidebar-width));
}

/* Sidebar Header */
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--color-border-light);
    background: var(--color-bg-sidebar);
    flex-shrink: 0;
}

.sidebar-header h2 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--color-text-primary);
    letter-spacing: -0.01em;
}

/* Sidebar close btn override — dark icon on white bg */
.sidebar-header .btn-icon {
    color: var(--color-text-secondary);
    background: var(--color-bg-card);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    padding: 0;
}

.sidebar-header .btn-icon:hover {
    color: var(--color-text-primary);
    background: var(--color-bg-card-hover);
}

/* Sidebar Content */
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}

.sidebar-content::-webkit-scrollbar {
    width: 5px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 10px;
}

/* Info Card */
.info-card {
    animation: fadeInUp var(--duration-slow) var(--ease-out);
}

.info-card h2 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--color-text-primary);
    margin-bottom: 0.375rem;
    letter-spacing: -0.02em;
    line-height: 1.3;
}

.text-muted {
    color: var(--color-text-secondary);
    font-size: 0.88rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

/* Content Section Cards */
.content-section {
    margin-bottom: 1rem;
    background: var(--color-bg-card);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border-light);
    transition: border-color var(--duration-fast) ease,
                box-shadow var(--duration-fast) ease,
                transform var(--duration-fast) ease;
    position: relative;
    overflow: hidden;
}

.content-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: var(--color-gov-green);
    border-radius: 0 3px 3px 0;
    opacity: 0;
    transition: opacity var(--duration-fast) ease;
}

html[dir="rtl"] .content-section::before {
    left: auto;
    right: 0;
    border-radius: 3px 0 0 3px;
}

.content-section:hover {
    border-color: var(--color-border);
    box-shadow: var(--shadow-xs);
}

.content-section:hover::before {
    opacity: 1;
}

.content-section h3 {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--color-gov-green);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    letter-spacing: -0.01em;
}

.content-section h3::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-gov-green);
    flex-shrink: 0;
}

.content-section p {
    font-size: 0.85rem;
    line-height: 1.7;
    color: var(--color-text-secondary);
}

/* ==============================
   PG Grade Floating Overlay
   ============================== */
.pg-overlay {
    position: absolute;
    bottom: 16px;
    right: 16px;
    z-index: 15;
    width: 460px;
    max-width: calc(100vw - 32px);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12),
                0 2px 8px rgba(0, 0, 0, 0.06);
    transition: box-shadow var(--duration-normal) ease;
}

html[dir="rtl"] .pg-overlay {
    right: auto;
    left: 16px;
}

.pg-overlay:hover {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.16),
                0 4px 12px rgba(0, 0, 0, 0.08);
}

/* Toggle Button */
.pg-overlay-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.6rem 0.875rem;
    background: var(--color-bg-header);
    color: var(--color-text-inverse);
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: background var(--duration-fast) ease;
}

.pg-overlay-toggle:hover {
    background: #1a2028;
}

.pg-overlay-icon {
    flex-shrink: 0;
    opacity: 0.7;
}

.pg-overlay-toggle span {
    flex: 1;
    text-align: left;
}

html[dir="rtl"] .pg-overlay-toggle span {
    text-align: right;
}

.pg-overlay-chevron {
    flex-shrink: 0;
    opacity: 0.5;
    transition: transform var(--duration-normal) var(--ease-out);
}

/* Expanded state — chevron flips */
.pg-overlay.expanded .pg-overlay-chevron {
    transform: rotate(180deg);
}

/* Overlay Body */
.pg-overlay-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--duration-slow) var(--ease-out);
}

.pg-overlay.expanded .pg-overlay-body {
    max-height: 400px;
}

/* ==============================
   PG Adjustment Table
   ============================== */
.pg-adjustment-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.78rem;
}

/* Table Header */
.pg-adjustment-table thead tr {
    background: rgba(15, 20, 25, 0.06);
}

.pg-adjustment-table th {
    padding: 0.55rem 0.6rem;
    font-weight: 600;
    font-size: 0.68rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    white-space: nowrap;
    border-bottom: 1px solid var(--color-border);
}

html[dir="rtl"] .pg-adjustment-table th {
    text-transform: none;
    letter-spacing: normal;
}

.th-condition {
    color: var(--color-text-primary);
    text-align: left;
    min-width: 120px;
}

html[dir="rtl"] .th-condition {
    text-align: right;
}

.th-zone {
    color: var(--color-text-primary);
    text-align: center;
    min-width: 85px;
}

.th-zone-70 {
    background: rgba(206, 126, 75, 0.1);
}

.th-zone-64 {
    background: rgba(100, 149, 200, 0.1);
}

/* Table Body */
.pg-adjustment-table tbody tr {
    transition: background var(--duration-fast) ease;
}

.pg-adjustment-table tbody tr:nth-child(odd) {
    background: transparent;
}

.pg-adjustment-table tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.02);
}

.pg-adjustment-table tbody tr:hover {
    background: rgba(0, 122, 61, 0.04);
}

.pg-adjustment-table td {
    padding: 0.5rem 0.6rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    vertical-align: middle;
}

.pg-adjustment-table tbody tr:last-child td {
    border-bottom: none;
}

/* Traffic Condition Cell */
.td-condition {
    text-align: left;
}

html[dir="rtl"] .td-condition {
    text-align: right;
}

.condition-label {
    font-size: 0.75rem;
    color: var(--color-text-primary);
    font-weight: 500;
    line-height: 1.3;
}

.condition-separator {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.1rem 0;
}

html[dir="rtl"] .condition-separator {
    text-transform: none;
    letter-spacing: normal;
}

/* Grade Cell */
.td-grade {
    text-align: center;
    padding: 0.5rem 0.35rem;
}

/* PG Badge */
.pg-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 5px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
    line-height: 1;
    transition: transform var(--duration-fast) var(--ease-spring),
                box-shadow var(--duration-fast) ease;
}

.pg-badge-70 {
    background: linear-gradient(135deg, #D4845A, #C47040);
    color: #FFFFFF;
    box-shadow: 0 1px 3px rgba(196, 112, 64, 0.3);
}

.pg-badge-64 {
    background: linear-gradient(135deg, #6B9FCA, #5489B8);
    color: #FFFFFF;
    box-shadow: 0 1px 3px rgba(84, 137, 184, 0.3);
}

.pg-adjustment-table tbody tr:hover .pg-badge {
    transform: scale(1.05);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--color-border-light);
    background: var(--color-bg-sidebar);
    display: flex;
    align-items: center;
    gap: 0.875rem;
    flex-shrink: 0;
}

.mot-logo {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--color-border-light);
    flex-shrink: 0;
}

.footer-text {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    line-height: 1.5;
    flex: 1;
    min-width: 0;
}

.footer-text strong {
    color: var(--color-text-primary);
    font-weight: 600;
    display: block;
}

/* ==============================
   Main Map Area
   ============================== */
.app-main {
    flex: 1;
    position: relative;
    background: var(--color-bg-body);
    min-width: 0;
}

.map-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.map-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* ==============================
   Backdrop
   ============================== */
.sidebar-backdrop {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 20, 25, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 5;
    opacity: 0;
    transition: opacity var(--duration-normal) ease;
}

/* ==============================
   Animations
   ============================== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==============================
   Mobile (≤ 768px)
   ============================== */
@media (max-width: 768px) {
    :root {
        --header-height: 56px;
        --sidebar-width: 100%;
    }

    .app-header {
        padding: 0 0.875rem;
    }

    .header-left {
        gap: 0.625rem;
    }

    .titles h1 {
        font-size: 0.92rem;
    }

    .header-subtitle {
        font-size: 0.62rem;
    }

    .gov-badge {
        display: none !important;
    }

    /* Off-canvas sidebar */
    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        height: 100dvh;
        width: 100%;
        max-width: 380px;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        z-index: 1000;
        transition: transform var(--duration-slow) var(--ease-out);
        will-change: transform;
        border-right: none;
    }

    html[dir="rtl"] .app-sidebar {
        left: auto;
        right: 0;
        transform: translateX(100%);
        border-left: none;
    }

    .app-sidebar.active {
        transform: translateX(0);
    }

    html[dir="rtl"] .app-sidebar.active {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        position: fixed;
        z-index: 900;
    }

    .sidebar-backdrop.active {
        display: block;
        opacity: 1;
    }

    .sidebar-content {
        padding: 1.25rem;
    }

    .info-card h2 {
        display: none;
    }

    .content-section {
        padding: 1.125rem;
    }

    .content-section p {
        font-size: 0.84rem;
        line-height: 1.65;
    }

    /* Larger tap targets on mobile */
    .btn-icon {
        padding: 0.625rem;
        min-width: 44px;
        min-height: 44px;
    }

    .lang-toggle button {
        padding: 0.375rem 0.625rem;
        min-height: 36px;
    }

    .sidebar-header .btn-icon {
        width: 36px;
        height: 36px;
    }

    /* Floating overlay on mobile — bottom-left, compact */
    .pg-overlay {
        bottom: 10px;
        right: 10px;
        left: auto;
        width: auto;
        max-width: calc(100vw - 20px);
        border-radius: var(--radius-sm);
    }

    html[dir="rtl"] .pg-overlay {
        right: auto;
        left: 10px;
    }

    .pg-overlay-toggle {
        padding: 0.5rem 0.75rem;
        font-size: 0.74rem;
        gap: 0.4rem;
    }

    .pg-overlay .pg-overlay-body {
        max-width: calc(100vw - 22px);
        overflow-x: auto;
    }

    .pg-overlay.expanded .pg-overlay-body {
        max-height: 300px;
    }
}

/* Small phones */
@media (max-width: 380px) {
    .titles h1 {
        font-size: 0.84rem;
    }

    .header-subtitle {
        display: none;
    }

    .lang-toggle button {
        padding: 0.3rem 0.5rem;
        font-size: 0.72rem;
    }
}

/* Landscape phones */
@media (max-height: 500px) and (orientation: landscape) {
    :root {
        --header-height: 48px;
    }

    .sidebar-content {
        padding: 1rem;
    }

    .content-section {
        padding: 1rem;
        margin-bottom: 0.75rem;
    }
}

/* Large desktops */
@media (min-width: 1440px) {
    :root {
        --sidebar-width: 420px;
    }
}

/* ==============================
   Reduced Motion
   ============================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==============================
   Focus Visible (Accessibility)
   ============================== */
:focus-visible {
    outline: 2px solid var(--color-gov-green);
    outline-offset: 2px;
}

.btn-icon:focus-visible {
    outline-offset: 1px;
}
