/* ============================================
   GATE APP LAYOUT - Override & Extensions
   Extends form-app.css for gate-specific styling
   ============================================ */

/* Gate-specific body layout class */
body[data-page="gate"].gate-app-layout {
    padding: 0 !important;
    margin: 0 !important;
    background-color: var(--fa-bg);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body[data-page="gate"].gate-app-layout .navbar {
    display: none !important;
}

/* ===== GATE APP CONTAINER (inherit from form-app-container) ===== */
.gate-app-container {
    display: flex;
    flex: 1;
    height: 100vh;
    min-height: 0;
    overflow: hidden;
}

/* ===== GATE SIDEBAR ===== */
.gate-app-sidebar {
    width: var(--fa-sidebar-width);
    min-width: var(--fa-sidebar-width);
    background-color: var(--fa-sidebar-bg);
    color: white;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 200;
    overflow: hidden;
}

.gate-app-sidebar .sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 24px 16px;
    text-decoration: none;
    flex-shrink: 0;
}

.gate-app-sidebar .sidebar-logo img {
    width: 28px;
    height: 28px;
    border-radius: 6px;
}

.gate-app-sidebar .sidebar-logo span {
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Gate Sidebar Menu */
.sidebar-menu {
    list-style: none;
    margin: 0;
    padding: 12px;
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.sidebar-menu::-webkit-scrollbar {
    width: 4px;
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}

.sidebar-menu-item {
    margin-bottom: 4px;
}

.sidebar-menu-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    text-decoration: none;
    color: rgba(255, 255, 255, 0.65);
    border-radius: var(--fa-radius-sm);
    font-size: 0.9rem;
    font-weight: 400;
    transition: background-color 0.2s, color 0.2s;
    cursor: pointer;
    position: relative;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.sidebar-menu-link:hover {
    background-color: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.9);
}

.sidebar-menu-link.active {
    background-color: rgba(45, 90, 135, 0.2);
    color: white;
    font-weight: 500;
    box-shadow: inset 3px 0 0 var(--fa-primary);
}

.sidebar-menu-link svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    stroke-width: 2;
}

/* ===== GATE MAIN CONTENT ===== */
.gate-app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ===== GATE TOPBAR ===== */
.gate-app-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--fa-topbar-height);
    padding: 0 24px;
    background: var(--fa-card-white);
    border-bottom: 1px solid var(--fa-border);
    flex-shrink: 0;
}

.gate-app-topbar .topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.gate-sidebar-toggle {
    display: none;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    padding: 0;
    border: 1px solid var(--fa-border);
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
}

.gate-sidebar-toggle span {
    width: 18px;
    height: 2px;
    border-radius: 999px;
    background: var(--fa-text-dark);
}

.gate-app-topbar .topbar-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--fa-text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gate-app-topbar .topbar-right {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-shrink: 0;
    align-self: stretch;
}

.gate-app-lang-switcher {
    padding: 8px 30px 8px 12px !important;
    font-size: 0.875rem;
    line-height: 1.4;
    border: 1px solid var(--fa-border);
    border-radius: var(--fa-radius-sm);
    background-color: white;
    color: var(--fa-text-dark);
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 8px center;
    background-repeat: no-repeat;
    background-size: 16px 16px;
    margin: auto 0;
}

.gate-sidebar-backdrop {
    display: none;
}

/* ===== GATE CANVAS ===== */
.gate-app-canvas {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background-color: var(--fa-bg);
}

.gate-app-canvas-inner {
    max-width: 900px;
    margin: 0 auto;
    padding: 32px 24px;
}

/* ===== GATE SECTIONS ===== */
.gate-section {
    display: none;
    margin-bottom: 32px;
}

.gate-section.active {
    display: block;
    animation: fadeIn 0.3s ease-in;
}

.gate-section-highlight {
    animation: gateSectionPulse 1.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes gateSectionPulse {
    0% {
        transform: translateY(8px);
        opacity: 0.82;
    }

    35% {
        transform: translateY(0);
        opacity: 1;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.gate-section-header {
    margin-bottom: 24px;
    scroll-margin-top: 24px;
}

.gate-section-header h2 {
    margin: 0 0 8px 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--fa-text-dark);
}

.gate-section-subtitle {
    margin: 0;
    font-size: 0.95rem;
    color: var(--fa-text-muted);
    line-height: 1.5;
}

.gate-section-empty {
    padding: 32px 24px;
    text-align: center;
    background: var(--fa-card-white);
    border-radius: var(--fa-radius-lg);
    border: 1px dashed var(--fa-border);
}

.gate-section-empty p {
    margin: 0;
    color: var(--fa-text-muted);
    font-size: 0.95rem;
}

.recent-date-header {
    margin: 1rem 0 0.5rem;
    color: var(--fa-text-muted);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ===== GATE QUICK START BUTTONS ===== */
.gate-quick-start {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

.gate-btn-primary,
.gate-btn-secondary {
    padding: 16px 24px;
    border: none;
    border-radius: var(--fa-radius-lg);
    font-family: var(--fa-font);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.gate-btn-primary {
    background: linear-gradient(135deg, var(--fa-primary) 0%, #1e4c7a 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(45, 90, 135, 0.2);
}

.gate-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(45, 90, 135, 0.3);
}

.gate-btn-primary:active {
    transform: translateY(0);
}

.gate-btn-secondary {
    background: var(--fa-card-white);
    color: var(--fa-text-dark);
    border: 2px solid var(--fa-border);
    text-align: center;
}

.gate-btn-secondary:hover {
    border-color: var(--fa-primary);
    background: linear-gradient(135deg, rgba(45, 90, 135, 0.05) 0%, rgba(45, 90, 135, 0.02) 100%);
}

.gate-btn-secondary .gate-btn-content {
    align-items: center;
}

.gate-btn-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.gate-btn-title {
    display: block;
    font-size: 1.05rem;
    font-weight: 700;
}

.gate-btn-subtitle {
    display: block;
    font-size: 0.85rem;
    opacity: 0.85;
    font-weight: 400;
}

.gate-try-note {
    margin: 12px 0 0 0;
    font-size: 0.9rem;
    color: var(--fa-text-muted);
    text-align: center;
}

/* ===== ALERT BOXES ===== */
.gate-alert {
    padding: 16px 20px;
    border-radius: var(--fa-radius-lg);
    margin-bottom: 16px;
    line-height: 1.6;
}

.gate-alert-info {
    background-color: #e6f7ff;
    border: 1px solid #91d5ff;
    color: #0050b3;
}

.gate-alert-warning {
    background-color: #fff4e5;
    border: 1px solid #ffd8a8;
    color: #8c6d1f;
}

.gate-alert p {
    margin: 0 0 12px 0;
}

.gate-alert p:last-child {
    margin-bottom: 0;
}

/* ===== OPTIONS MENU ===== */
.gate-options-menu {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.gate-option-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: var(--fa-card-white);
    border: 1px solid var(--fa-border);
    border-radius: var(--fa-radius-lg);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--fa-font);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--fa-text-dark);
    text-align: left;
}

.gate-option-item:hover {
    background: linear-gradient(135deg, rgba(45, 90, 135, 0.05) 0%, rgba(45, 90, 135, 0.02) 100%);
    border-color: var(--fa-primary);
}

.gate-option-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.gate-option-text {
    flex: 1;
}

.gate-inline-modal {
    position: fixed;
    inset: 0;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(15, 23, 42, 0.52);
    backdrop-filter: blur(4px);
}

.gate-inline-modal__dialog {
    width: min(680px, 100%);
    max-height: min(82vh, 760px);
    overflow-y: auto;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
}

.gate-inline-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--fa-border);
    background: linear-gradient(180deg, #f8fbff 0%, #f3f7fb 100%);
}

.gate-inline-modal__header h2 {
    margin: 0;
    color: var(--fa-text-dark);
    font-size: 1.125rem;
    font-weight: 700;
}

.gate-inline-modal__close {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--fa-text-muted);
    cursor: pointer;
    font-size: 1.75rem;
    line-height: 1;
}

.gate-inline-modal__close:hover {
    background: rgba(45, 90, 135, 0.08);
    color: var(--fa-primary);
}

.gate-inline-modal__body {
    padding: 24px;
}

.gate-info-modal h3,
.gate-info-modal h4,
.gate-confirm-modal h3 {
    margin-top: 0;
    color: var(--fa-text-dark);
}

.gate-info-modal p,
.gate-info-modal li,
.gate-confirm-modal p {
    line-height: 1.7;
    color: var(--fa-text-dark);
}

.gate-info-modal ul {
    margin: 0 0 18px;
    padding-left: 20px;
}

.gate-info-card {
    margin-bottom: 16px;
    padding: 16px 18px;
    background: #f7fafc;
    border: 1px solid #dbe5ef;
    border-radius: 16px;
}

.gate-info-card h4 {
    margin-bottom: 12px;
}

.gate-info-note {
    margin: 12px 0 0;
    font-size: 0.92rem;
    color: var(--fa-text-muted);
}

.gate-info-callout {
    margin: 20px 0 0;
    padding: 14px 16px;
    border-radius: 14px;
    font-size: 0.92rem;
}

.gate-info-callout--info {
    background: #edf6ff;
    border-left: 4px solid var(--fa-primary);
}

.gate-info-callout--warn {
    background: #fff8e8;
    border-left: 4px solid #f0a500;
}

.gate-info-table {
    width: 100%;
    margin-top: 12px;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.gate-info-table th,
.gate-info-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e7edf4;
    vertical-align: top;
}

.gate-info-table thead tr {
    background: #edf6ff;
}

.gate-confirm-modal {
    text-align: center;
}

.gate-confirm-modal__icon {
    margin-bottom: 16px;
    font-size: 2.75rem;
}

.gate-confirm-modal__actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 24px;
}

.gate-confirm-modal__actions .button-secondary,
.gate-confirm-modal__actions .button-primary {
    flex: 1;
    max-width: 180px;
}

.gate-danger-button {
    background: #d4380d;
}

.gate-danger-button:hover {
    background: #b8330d;
}

/* ===== RECENT SESSIONS LIST ===== */
.recent-sessions-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.recent-session-item {
    padding: 16px 20px;
    background: var(--fa-card-white);
    border: 1px solid var(--fa-border);
    border-radius: var(--fa-radius-lg);
    cursor: pointer;
    transition: all 0.2s ease;
}

.recent-session-item:hover {
    border-color: var(--fa-primary);
    box-shadow: 0 2px 8px rgba(45, 90, 135, 0.1);
}

.recent-session-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--fa-text-dark);
    margin-bottom: 4px;
}

.recent-session-date {
    font-size: 0.85rem;
    color: var(--fa-text-muted);
}

.recent-load-more-btn {
    width: 100%;
    margin-top: 1rem;
}

/* ===== FORM STYLES ===== */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--fa-text-dark);
}

.form-group input,
.form-group select {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border: 1px solid var(--fa-border);
    border-radius: var(--fa-radius-md);
    font-size: 0.95rem;
    font-family: var(--fa-font);
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--fa-primary);
    box-shadow: 0 0 0 3px rgba(45, 90, 135, 0.1);
}

.form-error {
    margin-top: 6px;
    color: #dc3545;
    font-size: 0.85rem;
}

.form-hint {
    display: block;
    margin-top: 6px;
    color: var(--fa-text-muted);
    font-size: 0.85rem;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.form-actions .button-primary,
.form-actions .button-secondary {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: var(--fa-radius-md);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--fa-font);
}

.form-actions .button-primary {
    background: var(--fa-primary);
    color: white;
}

.form-actions .button-primary:hover {
    background: var(--fa-primary-hover);
}

.form-actions .button-secondary {
    background: var(--fa-card-white);
    color: var(--fa-text-dark);
    border: 1px solid var(--fa-border);
}

.form-actions .button-secondary:hover {
    border-color: var(--fa-primary);
}

/* ===== DATE SELECT GROUP ===== */
.date-select-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 1rem;
}

.date-select-group select {
    width: 100%;
}

/* ===== PIN INPUT WRAPPER ===== */
.gate-pin-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.gate-pin-input {
    flex: 1;
}

.gate-refresh-pin-btn {
    padding: 10px 12px;
    background: var(--fa-card-white);
    border: 1px solid var(--fa-border);
    border-radius: var(--fa-radius-md);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gate-refresh-pin-btn:hover {
    border-color: var(--fa-primary);
}

.gate-refresh-pin-btn .refresh-icon {
    display: inline-block;
    transition: transform 0.3s ease;
}

/* ===== LOADING OVERLAY ===== */
.gate-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.gate-loading-content {
    text-align: center;
}

.gate-loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #e0e0e0;
    border-top-color: var(--fa-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

.gate-loading-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--fa-text-dark);
    margin: 0 0 8px 0;
}

.gate-loading-subtext {
    font-size: 0.9rem;
    color: var(--fa-text-muted);
    margin: 0;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .gate-app-container {
        height: 100vh;
    }

    .gate-app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(82vw, 320px);
        min-width: min(82vw, 320px);
        transform: translateX(-100%);
        transition: transform 0.24s ease;
        border-right: 1px solid rgba(255, 255, 255, 0.08);
        box-shadow: 12px 0 32px rgba(15, 23, 42, 0.24);
    }

    .gate-app-sidebar.is-open {
        transform: translateX(0);
    }

    .sidebar-menu {
        display: block;
        padding: 12px;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .sidebar-menu-link {
        white-space: normal;
        padding: 12px 16px;
    }

    .gate-app-topbar {
        height: var(--fa-topbar-height);
        min-height: var(--fa-topbar-height);
        padding: 0 16px;
        align-items: center;
        gap: 12px;
        flex-wrap: nowrap;
    }

    .gate-sidebar-toggle {
        display: inline-flex;
    }

    .gate-app-topbar .topbar-right {
        width: auto;
        flex-shrink: 0;
    }

    .gate-app-lang-switcher {
        width: auto;
        max-width: 140px;
    }

    .gate-sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        border: none;
        padding: 0;
        background: rgba(15, 23, 42, 0.34);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.24s ease;
        z-index: 150;
    }

    .gate-sidebar-backdrop.is-visible {
        opacity: 1;
        pointer-events: auto;
    }

    body.gate-sidebar-open {
        overflow: hidden;
    }

    .gate-app-canvas-inner {
        padding: 20px 16px 28px;
    }

    .date-select-group {
        grid-template-columns: 1fr;
    }

    .gate-quick-start {
        gap: 12px;
    }

    .gate-btn-primary,
    .gate-btn-secondary {
        padding: 14px 20px;
    }

    .form-actions,
    .gate-confirm-modal__actions {
        flex-direction: column;
    }

    .gate-confirm-modal__actions .button-secondary,
    .gate-confirm-modal__actions .button-primary {
        max-width: none;
    }

    .gate-inline-modal {
        padding: 16px;
    }

    .gate-inline-modal__header,
    .gate-inline-modal__body {
        padding: 18px;
    }

    .gate-info-table,
    .gate-info-table thead,
    .gate-info-table tbody,
    .gate-info-table tr,
    .gate-info-table th,
    .gate-info-table td {
        display: block;
        width: 100%;
    }

    .gate-info-table thead {
        display: none;
    }

    .gate-info-table tr {
        margin-bottom: 12px;
        border: 1px solid #e7edf4;
        border-radius: 12px;
        overflow: hidden;
    }

    .gate-info-table td {
        border-bottom: 1px solid #e7edf4;
    }

    .gate-info-table tr td:last-child {
        border-bottom: none;
    }
}

/* ===== BUTTON STYLES ===== */
.button-primary {
    background: var(--fa-primary);
    color: white;
    padding: 12px 20px;
    border: none;
    border-radius: var(--fa-radius-md);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--fa-font);
}

.button-primary:hover {
    background: var(--fa-primary-hover);
    box-shadow: 0 4px 12px rgba(45, 90, 135, 0.2);
}

.button-primary:active {
    transform: translateY(1px);
}

.button-secondary {
    background: var(--fa-card-white);
    color: var(--fa-text-dark);
    padding: 12px 20px;
    border: 1px solid var(--fa-border);
    border-radius: var(--fa-radius-md);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--fa-font);
}

.button-secondary:hover {
    border-color: var(--fa-primary);
    background: linear-gradient(135deg, rgba(45, 90, 135, 0.05) 0%, rgba(45, 90, 135, 0.02) 100%);
}

.button-secondary:active {
    transform: translateY(1px);
}

/* ===== SCROLLBAR STYLE ===== */
.gate-app-canvas::-webkit-scrollbar {
    width: 8px;
}

.gate-app-canvas::-webkit-scrollbar-track {
    background: transparent;
}

.gate-app-canvas::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

.gate-app-canvas::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}