/* Refactored and grouped styles */

/* Root variables */
:root {
    --bg: #0f1115;
    --bg-light: #ffffff;
    --bg-gradient: linear-gradient(135deg, #12161c, #0d1014);
    --bg-gradient-light: linear-gradient(135deg, #f9f9f9, #eaeaea);
    --panel: #1c2229;
    --panel-light: #f9f9f9;
    --panel-alt: #242c35;
    --panel-alt-light: #eeeeee;
    --text: #e5e9ef;
    --text-light: #000000;
    --accent: #3d82f6;
    --accent-hover: #2c6bd0;
    --danger: #c0392b;
    --border: #333c46;
    --border-light: #dddddd;
    --radius: 6px;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Arial, sans-serif;
}

/* Updated table styles for light and dark themes */
:root {
    --table-bg: var(--panel-alt);
    --table-bg-light: #f3f3f3; /* Light gray background for light theme */
    --table-border: var(--border);
    --table-border-light: #cccccc;
    --table-hover-bg: #26313a;
    --table-hover-bg-light: #e8e8e8; /* Slightly darker gray for hover in light theme */
    --table-header-bg: #222b33;
    --table-header-bg-light: #e0e0e0; /* Light gray header for light theme */
    --table-text: var(--text);
    --table-text-light: #333333; /* Darker text for light theme */
}

/* General styles */
* {
    box-sizing: border-box;
}

body {
    margin: 1.5rem;
    background: var(--bg-gradient);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

h1, h2 {
    margin: .2rem 0 1rem;
    font-weight: 600;
    letter-spacing: .5px;
}

/* Topbar styles */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.user-box {
    display: flex;
    gap: .75rem;
    align-items: center;
    flex-wrap: wrap;
}

/* Card styles */
.card {
    background: var(--panel);
    padding: 1rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px -4px rgba(0, 0, 0, .55);
    backdrop-filter: blur(4px);
}

/* Form styles */
label {
    display: block;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-top: .5rem;
    opacity: .8;
}

input {
    margin: .35rem 0 0.75rem;
    width: 100%;
    padding: .4rem .6rem;
    background: var(--panel-alt);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    font: inherit;
    transition: .15s border, .15s background;
}

input:focus {
    outline: none;
    border-color: var(--accent);
    background: #1f2730;
    box-shadow: 0 0 0 2px rgba(61, 130, 246, .25);
}

/* Checkbox label: left aligned and vertically centered */
.checkbox-label {
    display: flex;
    align-items: center; /* vertical center */
    gap: .5rem;
    margin-top: .25rem;
    justify-content: flex-start; /* align to the left */
}

/* Button styles */
.button {
    display: inline-block;
    padding: .55rem 1rem;
    background: var(--panel-alt);
    color: var(--text);
    text-decoration: none;
    font-size: .9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: .15s background, .15s color, .15s border;
    line-height: 1.1;
}

.button.primary {
    background: var(--accent);
    border-color: var(--accent);
    font-weight: 600;
}

.button.primary:hover {
    background: var(--accent-hover);
}

.button:hover {
    background: #2b353f;
    color: #fff;
}

.button.secondary {
	font-size: 0.6rem;
	padding: 0.4rem;
}

/* Table styles */
table {
    width: 100%;
    border-collapse: collapse;
    margin: .25rem 0;
    font-size: .85rem;
    background: var(--table-bg);
    border: 1px solid var(--table-border);
    border-radius: var(--radius);
    overflow: hidden;
}

body.light table {
    background: var(--table-bg-light);
    border-color: var(--table-border-light);
}

th, td {
    padding: .55rem .7rem;
    text-align: center; /* center-align all table cells */
    vertical-align: middle; /* vertically center cell content */
    border-bottom: 1px solid var(--table-border);
    max-width: 400px;
    color: var(--table-text);
}

body.light th, body.light td {
    border-bottom: 1px solid var(--table-border-light);
    color: var(--table-text-light);
}

th {
    background: var(--table-header-bg);
    font-weight: 600;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    position: sticky;
    top: 0;
    z-index: 1;
}

body.light th {
    background: var(--table-header-bg-light);
    color: var(--text-light);
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover td {
    background: var(--table-hover-bg);
}

body.light tbody tr:hover td {
    background: var(--table-hover-bg-light);
}

a {
    color: var(--accent);
    text-decoration: none;
    word-break: break-all;
}

a:hover {
    text-decoration: underline;
}

.truncate {
    max-width: 420px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: var(--mono);
    font-size: .75rem;
    text-align: center;
}

/* Optimize table rendering */
#imagesTable {
    contain: layout;
}

/* Make table horizontally scrollable on small devices */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* smooth scrolling on iOS */
}

/* On small screens, allow the table to be wider than the viewport so horizontal scrolling is possible */
@media (max-width: 780px) {
    #imagesTable {
        min-width: 720px; /* ensures table can scroll horizontally when viewport is narrow */
    }
}

/* Search controls styles */
.search-controls {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: end;
}

.search-box, .sort-controls {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.search-box label, .sort-controls label {
    font-weight: bold;
    font-size: 14px;
}

#searchInput {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    min-width: 200px;
}

#sortSelect {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    min-width: 180px;
}

/* Responsive styles */
@media (max-width: 600px) {
    #searchInput, #sortSelect {
        min-width: 100%;
    }

    .button {
        font-size: 0.8rem;
        padding: 0.5rem;
    }

    .card {
        padding: 0.75rem;
    }
}

@media (max-width: 780px) {
    body {
        margin: 1rem;
    }

    .truncate {
        max-width: 160px;
    }

    table {
        font-size: .75rem;
    }

    th, td {
        padding: .45rem .5rem;
    }

    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: .5rem;
    }
}

/* Moved from index.php */
.sort-arrow {
    cursor: pointer;
    margin-left: 5px;
    font-size: 1.4em;
    color: var(--accent);
}

.sort-arrow:hover {
    text-decoration: underline;
}

/* Light and dark theme styles */

body.light {
    background: var(--bg-gradient-light);
    color: var(--text-light);
}

body.light .card {
    background: var(--panel-light);
    border-color: var(--border-light);
}

body.light .button {
    background: var(--panel-alt-light);
    border-color: var(--border-light);
    color: var(--text-light);
}

body.light .button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--text);
}

body.light .button.primary:hover {
    background: var(--accent-hover);
}

body.light input {
	background: var(--panel-alt-light);
	border-color: var(--border-light);
	color: var(--text-light);
}

/* Updated theme toggle button styles */
.theme-toggle {
    position: fixed;
    bottom: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    background: var(--accent);
    color: #ffffff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.theme-toggle:hover {
    background: var(--accent-hover);
}



/* Toast notifications */
.toast {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 18px;
    background: rgba(0,0,0,0.85);
    color: #fff;
    padding: 10px 14px;
    border-radius: 8px;
    z-index: 3000;
    opacity: 0;
    transition: opacity .25s ease, transform .25s ease;
}
.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(-6px);
}

/* Image modal styles */
.img-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
}
.img-modal.open {
    display: flex;
    align-items: center;
    justify-content: center;
}
.img-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(2px);
}
.img-modal-content {
    position: relative;
    z-index: 2001;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
}
.img-modal-content img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 6px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}
.img-modal-close {
    position: absolute;
    top: -12px;
    right: -12px;
    z-index: 2100;
    background: var(--panel-alt);
    color: var(--text);
    border: 1px solid var(--border);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.img-modal-close:hover {
    background: var(--panel);
}

@media (max-width: 600px) {
    .img-modal-content {
        max-width: 98%;
        max-height: 86%;
    }
    .img-modal-close {
        width: 32px;
        height: 32px;
        top: -8px;
        right: -8px;
    }
}