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

* {
    box-sizing: border-box;
}

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #ec4899;
    --bg-color: #f3f4f6;
    --text-color: #1f2937;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.5);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

body {
    font-family: 'Sarabun', sans-serif;
    background: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
    min-height: 100vh;
    min-height: 100dvh;
    /* Use dynamic viewport height for mobile */
    margin: 0;
    color: var(--text-color);
    display: flex;
    flex-direction: column;
}

.main-content {
    flex: 1;
    width: 98%;
    max-width: 100%;
    margin: 1rem auto;
    padding: 0 0.5rem;
}

.glass-container {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

.navbar {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.nav-brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    text-decoration: none;
}

.nav-links a {
    text-decoration: none;
    color: #4b5563;
    margin-left: 1.5rem;
    font-weight: 500;
    transition: color 0.3s;
}

.nav-links a:hover {
    color: var(--primary-color);
}

.user-profile-nav {
    display: inline-block;
}

@media screen and (max-width: 768px) {
    .user-profile-nav {
        display: block;
        margin-bottom: 0.5rem;
        text-align: right;
    }
}

.btn {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-family: 'Sarabun', sans-serif;
    font-weight: 600;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-logout {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.2);
    transition: all 0.3s ease;
}

.btn-logout:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    box-shadow: 0 4px 6px rgba(239, 68, 68, 0.3);
    transform: translateY(-1px);
}

.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
    flex: 1;
}


.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-control {
    width: 100%;
    box-sizing: border-box;
    padding: 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-family: 'Sarabun', sans-serif;
    font-size: 1rem;
    transition: border-color 0.3s;
    background: rgba(255, 255, 255, 0.8);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.alert {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.alert-danger {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

/* Dashboard Header & Buttons */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.dashboard-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--primary-color);
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
}

.btn-hero {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.3), 0 2px 4px -1px rgba(79, 70, 229, 0.15);
    padding: 0.6rem 1.2rem;
    font-size: 1rem;
    border: 2px solid transparent;
}

/* Dashboard Table */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0;
    /* Remove top margin as requested */
}

th,
td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

th {
    font-weight: 600;
    color: #4b5563;
}

tr:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: #fff;
    margin: 0;
    /* Changed from 10% auto to 0 */
    position: fixed;
    /* Fixed position for centering */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* True vertical centering */
    width: 90%;
    max-width: 450px;
    /* Slightly smaller max-width */
    padding: 2rem 3rem 2rem 2rem;
    /* Increased right padding to balance scrollbar */
    border-radius: 16px;
    max-height: 90vh;
    /* Prevent overflow on small screens */
    overflow-y: auto;
    /* Internal scroll if needed */
    overflow-x: hidden;
    /* No horizontal scroll */
    box-sizing: border-box;
    /* padding doesn't affect width */
    animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
    from {
        opacity: 0;
        transform: translate(-50%, -40%) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes modalSlide {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close-modal {
    position: absolute;
    right: 1.5rem;
    top: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6b7280;
    z-index: 10;
}



/* Enhanced Mobile Adjustments */
@media screen and (max-width: 768px) {
    .navbar {
        flex-wrap: wrap;
        padding: 0.5rem 1rem;
        gap: 0.5rem;
    }

    .nav-brand {
        width: 100%;
        text-align: center;
        margin-bottom: 0.25rem;
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        /* Optional: visual separation */
        padding-bottom: 0.5rem;
    }

    .nav-links {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-left: 0 !important;
        /* Override default margin */
    }

    .nav-links a {
        margin-left: 0.5rem;
        /* Reduce margin on mobile */
    }

    .user-profile-nav {
        display: flex !important;
        /* Force flex to align content */
        text-align: left !important;
        margin-right: auto !important;
        /* Push buttons to right */
        margin-bottom: 0 !important;
    }

    .user-info-container {
        display: flex;
        flex-direction: column;
        line-height: 1.2;
    }

    .user-name {
        font-weight: 600;
        font-size: 0.95rem;
    }

    .user-org {
        font-size: 0.8rem;
        color: #6b7280;
    }

    /* Adjust button sizes for touch targets */
    .btn-icon {
        padding: 0.6rem !important;
        font-size: 1.2rem !important;
    }

    /* Reduce status dropdown size on mobile */
    #edit_status {
        padding: 0.5rem;
        font-size: 0.9rem;
        height: auto;
    }

    /* Admin/Nav Icons Specific */
    .nav-links .nav-text {
        display: none;
    }

    .nav-links a {
        font-size: 1.2rem;
        /* Make icons slightly larger */
        padding: 0.5rem;
        margin-left: 0.25rem;
    }
}

/* Mobile adjustments for Modals - Force Center */
@media screen and (max-width: 500px) {
    .modal-content {
        width: 90%;
        max-width: 90%;
        height: auto;
        max-height: 85vh;

        /* Force Centering */
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        margin: 0;

        border-radius: 16px;
        overflow-y: auto;
    }
}

.qr-display {
    text-align: center;
    margin-top: 1rem;
}

.qr-display img {
    max-width: 250px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Toast Notification */
.toast {
    visibility: hidden;
    min-width: 200px;
    background-color: rgba(0, 0, 0, 0.8);
    color: #fff;
    text-align: center;
    border-radius: 50px;
    padding: 12px 24px;
    position: fixed;
    z-index: 10000;
    left: 50%;
    transform: translateX(-50%);
    bottom: 30px;
    font-size: 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transition: opacity 0.3s, bottom 0.3s;
}

.toast.show {
    visibility: visible;
    opacity: 1;
    bottom: 50px;
}

/* Responsive Table / Card View */
@media screen and (max-width: 768px) {

    /* Force table to not be like tables anymore */
    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    /* Hide table headers (but not display: none;, for accessibility) */
    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    tr {
        border: 1px solid #ccc;
        border-radius: 12px;
        margin-bottom: 0.5rem;
        /* Reduced bottom margin */
        background: rgba(255, 255, 255, 0.6);
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        padding: 0.75rem;
        /* Reduced padding */
    }

    td {
        /* Behave  like a "row" */
        border: none;
        border-bottom: 1px solid #eee;
        position: relative;
        padding-left: 0;
        padding-right: 0;
        padding-top: 0.25rem;
        /* Compact vertical padding */
        padding-bottom: 0.25rem;
        text-align: left !important;
        /* Force left align on mobile */
    }

    td:last-child {
        border-bottom: 0;
        padding-bottom: 0;
    }

    /* Adjust specific columns for Mobile Card View */
    td:nth-of-type(1) {
        /* Title */
        font-weight: bold;
        font-size: 1.1em;
        color: var(--primary-color);
        margin-bottom: 0.25rem;
        /* Compact margin */
        padding-top: 0;
    }

    td:nth-of-type(2) {
        /* Short URL */
        margin-bottom: 0.25rem;
        /* Compact margin */
    }

    td:nth-of-type(3) {
        /* Actions */
        border-bottom: none;
        margin-top: 0.25rem;
        /* Compact margin */
        justify-content: flex-start;
        /* Left align actions on mobile */
    }
}

@media screen and (min-width: 769px) {
    .container {
        max-width: 95%;
        /* Stretch closer to full width */
    }

    .table-container {
        width: 100%;
        overflow-x: hidden;
        /* No scroll on desktop */
    }

    table {
        table-layout: auto;
        /* Let columns size by content */
    }
}

.auth-card {
    /* Centered card style */
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

/* Row for forms */
.row {
    display: flex;
    gap: 1rem;
}

.col-half {
    flex: 1;
}

/* Mobile responsive */
@media screen and (max-width: 768px) {
    .row {
        flex-direction: column;
        gap: 0;
    }

    .auth-card {
        margin: 1rem;
        padding: 2rem !important;
    }
}

/* Success Page Specific Styles */
.success-card {
    padding: 3rem 2.5rem;
}

.success-header {
    margin-bottom: 2rem;
}

.success-qr-box {
    margin: 2rem 0;
}

.success-actions {
    margin-top: 2.5rem;
}

/* Success Page Mobile Optimization */
@media screen and (max-width: 500px) {
    .success-card {
        padding: 1.5rem !important;
        /* Tighter padding on mobile */
    }

    .success-header {
        margin-bottom: 0.5rem;
        /* Reduced space below header */
        font-size: 1.25rem;
        /* Slightly smaller font */
    }

    .success-qr-box {
        margin: 1rem 0;
        /* Reduced margin around QR */
    }

    .success-actions {
        margin-top: 1.5rem;
        /* Reduced margin above buttons */
    }
}