/* --- CSS Custom Properties (Theme Variables) --- */
:root {
    --font-primary: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

    /* Dark Theme */
    --bg-color: #121218;
    --bg-gradient-start: #1a1a2e;
    --bg-gradient-end: #10101a;
    --text-primary: #e0e0e7;
    --text-secondary: #a0a0b0;
    --text-accent: #61dafb; /* Bright, modern accent */
    --text-error: #ff7b7b; /* Softer red for errors */

    --surface-bg: rgba(30, 30, 45, 0.65); /* Semi-transparent surface */
    --surface-bg-hover: rgba(40, 40, 60, 0.75);
    --surface-border: rgba(255, 255, 255, 0.08);
    --surface-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    --surface-shadow-hover: 0 12px 32px rgba(0, 0, 0, 0.45);

    --button-bg-gradient-start: var(--text-accent);
    --button-bg-gradient-end: #42a8c9; /* Darker shade of accent */
    --button-text-color: #0e0e12;
    --button-hover-opacity: 0.9;
    --button-active-scale: 0.97;

    --input-bg: rgba(255, 255, 255, 0.03);
    --input-border: rgba(255, 255, 255, 0.15);
    --input-focus-border: var(--text-accent);
    --input-text-color: var(--text-primary);

    --border-radius-sm: 6px;
    --border-radius-md: 12px;
    --border-radius-lg: 18px;

    --transition-fast: 0.2s ease-out;
    --transition-medium: 0.3s ease-out;

    /* RGB version of accent color for box-shadows etc. */
    --text-accent-rgb: 97, 218, 251;
}

/* --- General Styles & Resets --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-primary);
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    background-attachment: fixed;
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes subtlePulse {
  0% { box-shadow: 0 0 0 0 rgba(var(--text-accent-rgb), 0.3); }
  70% { box-shadow: 0 0 0 8px rgba(var(--text-accent-rgb), 0); }
  100% { box-shadow: 0 0 0 0 rgba(var(--text-accent-rgb), 0); }
}

/* --- Header --- */
header {
    background: rgba(18, 18, 24, 0.7); /* Darker, semi-transparent */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text-primary);
    padding: 1.2em 1em;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.25);
    animation: fadeIn 0.5s var(--transition-medium) backwards;
}

h1 {
    margin: 0;
    font-size: 2.2rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

h2 {
    color: var(--text-accent);
    margin-bottom: 1em;
    font-size: 1.8rem;
    font-weight: 500;
}

/* --- Navigation --- */
nav ul {
    list-style: none;
    padding: 0;
    display: flex;
    justify-content: center;
    gap: 2em;
    margin-top: 0.5em;
}

nav a {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    padding: 0.5em 0;
    position: relative;
    transition: color var(--transition-fast);
}

nav a::after {
    content: '';
    position: absolute;
    width: 0;
    height: 2px;
    bottom: -2px; /* Slightly offset */
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--text-accent);
    transition: width var(--transition-medium);
}

nav a:hover {
    color: var(--text-accent);
}

nav a:hover::after {
    width: 70%;
}

/* --- Main Content Container --- */
.container {
    max-width: 1100px;
    margin: 2.5em auto;
    padding: 2.5em;
    background: var(--surface-bg);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--surface-shadow);
    border: 1px solid var(--surface-border);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: fadeIn 0.6s var(--transition-medium) 0.1s backwards;
}

/* --- Forms --- */
form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2em; /* Increased gap */
}

label {
    margin-bottom: 0.3em;
    font-weight: 500;
    color: var(--text-secondary);
    align-self: flex-start; /* For forms centered in container */
    padding-left: 5px; /* Small indent */
}
/* Center label if form is not full width itself */
form > label {
    width: 100%;
    max-width: 340px; /* Match input width */
}


input[type="text"],
input[type="password"] {
    padding: 0.8em 1em;
    width: 100%;
    max-width: 340px;
    border: 1px solid var(--input-border);
    border-radius: var(--border-radius-sm);
    font-size: 1rem;
    background-color: var(--input-bg);
    color: var(--input-text-color);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input[type="text"]:focus,
input[type="password"]:focus {
    outline: none;
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 3px rgba(var(--text-accent-rgb), 0.25);
}

/* --- Buttons --- */
button,
.button-style { /* Generic class for button-like elements */
    background: linear-gradient(90deg, var(--button-bg-gradient-start), var(--button-bg-gradient-end));
    color: var(--button-text-color);
    border: none;
    padding: 0.8em 1.6em;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    transition: opacity var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
    box-shadow: 0 4px 10px rgba(0,0,0,0.25);
}

button:hover,
.button-style:hover {
    opacity: var(--button-hover-opacity);
    box-shadow: 0 6px 15px rgba(var(--text-accent-rgb),0.2);
}

button:active,
.button-style:active {
    transform: scale(var(--button-active-scale));
    box-shadow: 0 2px 5px rgba(var(--text-accent-rgb),0.15);
}

/* Signup Link */
.signup-link {
    margin-top: 1.5em;
    text-align: center;
    font-size: 0.9rem;
}

.signup-link a {
    color: var(--text-accent);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition-fast), text-decoration var(--transition-fast);
}

.signup-link a:hover {
    color: var(--text-primary);
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* --- Footer --- */
footer {
    text-align: center;
    padding: 2em 1em;
    color: var(--text-secondary);
    font-size: 0.85em;
    margin-top: 2.5em;
    border-top: 1px solid var(--surface-border);
}

/* --- File List General --- */
.file-list-header {
    display: flex;
    justify-content: space-between; /* Distributes space between title and controls block */
    align-items: center;
    margin-bottom: 1.5em;
    padding-bottom: 1em;
    border-bottom: 1px solid var(--surface-border);
}

.file-list-header h2 {
    margin-bottom: 0;
    /* No margin-right: auto needed here with space-between on parent */
}

/* This is the new wrapper for all controls on the right */
.file-header-controls {
    display: flex;
    gap: 1em; /* Space BETWEEN view-toggle group and folder-toggle-container group */
    align-items: center;
    /* If you want this whole block to be centered if title is very short,
       you might need to make h2 flex-grow:1 and this block flex-grow:0 or vice-versa,
       but space-between on parent usually suffices. */
}

.view-toggle, .folder-toggle-container {
    display: flex; /* If they contain multiple buttons themselves, e.g. future icons */
    gap: 0.8em; /* Space WITHIN a toggle group, if any */
}

.view-toggle button, /* For existing view toggle */
.folder-toggle button /* For buttons from shared.html/index.html */ {
    padding: 0.6em 1.2em;
    font-size: 0.9rem;
    text-transform: none;
    background: var(--input-bg);
    color: var(--text-secondary);
    border: 1px solid var(--input-border);
    transition: all var(--transition-fast);
    box-shadow: none; /* Override general button shadow */
}

.view-toggle button:hover,
.folder-toggle button:hover {
    background: var(--surface-bg); /* Slight change */
    color: var(--text-primary);
    border-color: var(--input-focus-border);
    opacity: 1; /* Override general button hover opacity */
}
.view-toggle button.active, /* Class for active state */
.folder-toggle button.active {
    background: var(--text-accent);
    color: var(--button-text-color);
    border-color: var(--text-accent);
    font-weight: 600;
}

/* --- File List – Card View --- */
.file-list.card-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: 1.8em; /* Increased gap */
}

.file-item {
    background: var(--surface-bg);
    border-radius: var(--border-radius-md);
    padding: 1.5em; /* Increased padding */
    box-shadow: var(--surface-shadow);
    border: 1px solid var(--surface-border);
    display: flex;
    flex-direction: column;
    gap: 0.6em;
    transition: transform var(--transition-medium), box-shadow var(--transition-medium), background var(--transition-medium);
    overflow: hidden; /* Important for nested overflow effects */
}

.file-item:hover {
    transform: translateY(-8px) scale(1.03);
    box-shadow: var(--surface-shadow-hover);
    background: var(--surface-bg-hover);
}

/* Styling for the <a> tag wrapping file name and extension (both card and list) */
.file-item a {
    text-decoration: none;
    display: flex; /* Use flex to manage children (name and extension) */
    align-items: baseline; /* Aligns text of name and ext nicely */
    overflow: hidden; /* CRUCIAL for children's ellipsis to work */
    margin-bottom: 0.6em; /* Space below the name/ext line before metadata <p> tags */
}

.file-item:hover .file-name { /* Hover effect for file name */
    color: var(--text-accent);
}

/* Styling for the .file-name span (both card and list) */
.file-item .file-name {
    color: var(--text-primary);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: color var(--transition-fast);
    /* Flex item properties */
    flex-grow: 1; /* Allow it to take up available space */
    flex-shrink: 1; /* Allow it to shrink if needed */
    min-width: 0; /* VERY IMPORTANT for flex items to shrink below content size and allow ellipsis */
}

/* Card-specific font size for file name */
.file-list.card-view .file-item .file-name {
    font-size: 1.15rem;
}

/* Styling for the .file-ext span (both card and list) */
.file-item .file-ext {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.8em;
    background-color: rgba(var(--text-accent-rgb), 0.1);
    padding: 0.2em 0.6em;
    border-radius: var(--border-radius-sm);
    display: inline-block; /* Or just rely on flex item behavior */
    margin-left: 0.5em; /* Space between name and extension */
    flex-shrink: 0; /* Prevent extension from shrinking */
}

.file-item p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.3em;
    line-height: 1.4;
}
.file-item p:last-of-type { /* Last descriptive paragraph before buttons */
    margin-bottom: 1em; /* Space before buttons */
}

.file-item .share-button,
.file-item .delete-button {
    width: 100%;
    margin-top: auto; /* Pushes button to bottom in card view */
    padding: 0.7em 1em;
    font-size: 0.9rem;
    letter-spacing: 0.5px; /* Less spacing for card buttons */
}
.file-item .delete-button {
    background: var(--text-error);
    color: white;
}
.file-item .delete-button:hover {
    background: #e55050; /* Darker red */
    opacity: 1;
}


/* --- File List – List View --- */
.file-list.list-view {
    display: flex;
    flex-direction: column;
    gap: 0.8em;
}

.file-list.list-view .file-item { /* Item itself in list view */
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 1em 1.2em; /* Balanced padding */
    border-radius: var(--border-radius-sm);
}

.file-list.list-view .file-item:hover {
    transform: translateY(-3px) scale(1.008); /* Subtler hover for list items */
}

.file-list.list-view .file-item > * {
    margin-right: 1em;
}
.file-list.list-view .file-item > *:last-child {
    margin-right: 0;
}

/* The <a> tag in list view, now styled by general .file-item a, but we can call it .file-info-list if needed */
.file-info-list { /* This is the <a> tag in list view */
    flex-grow: 1; /* Take up space, allows .file-name inside to use its own flex properties */
    /* Other properties like display:flex, overflow:hidden are now on general .file-item a */
}

/* List-view specific font size for file name */
.file-list.list-view .file-name { /* Targets .file-name specifically within list view items */
    font-size: 1.05rem;
    /* Inherits truncation properties from general .file-item .file-name */
}

.file-list.list-view .file-item p { /* Metadata like size, uploader in list view */
    margin-bottom: 0;
    min-width: 70px;
    text-align: left;
    font-size: 0.9rem;
    flex-shrink: 0; /* Prevent shrinking */
}

.file-list.list-view .share-button,
.file-list.list-view .delete-button {
    width: auto; /* Auto width for list view buttons */
    margin-top: 0; /* No auto margin */
    padding: 0.6em 1em;
    font-size: 0.85rem;
    flex-shrink: 0;
}


/* --- Error Messages --- */
.error-message,
.flashes li /* Assuming flashed messages are LIs in a UL.flashes */
{
    color: var(--text-error);
    background-color: rgba(255, 123, 123, 0.1);
    border: 1px solid rgba(255, 123, 123, 0.2);
    padding: 0.8em 1.2em;
    text-align: center;
    font-weight: 500;
    margin-bottom: 1em;
    border-radius: var(--border-radius-sm);
    animation: fadeIn 0.3s ease-out;
}
ul.flashes {
    list-style-type: none;
    padding: 0;
    margin-bottom: 1em;
}

/* --- File Input Styling (Upload Page) --- */
.file-input-wrapper {
    position: relative;
    display: block; /* Take full width of its form context */
    margin-bottom: 1em;
    width: 100%;
    max-width: 340px; /* Match other inputs */
}

.file-input-wrapper input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    left:0; top:0;
    z-index: 1; /* Ensure it's clickable */
}

.file-input-label {
    display: block;
    text-align: center;
    border: 2px dashed var(--input-border);
    color: var(--text-secondary);
    background-color: var(--input-bg);
    padding: 1.5em 1.2em; /* More padding for a dropzone feel */
    border-radius: var(--border-radius-md); /* Softer radius */
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-medium);
}

.file-input-label:hover,
.file-input-wrapper input[type="file"]:hover + .file-input-label /* Hover effect on label too */ {
    border-color: var(--text-accent);
    color: var(--text-accent);
    background-color: rgba(var(--text-accent-rgb), 0.05);
}

.file-input-wrapper input[type="file"]:focus + .file-input-label {
    border-color: var(--text-accent);
    box-shadow: 0 0 0 3px rgba(var(--text-accent-rgb), 0.25);
}

.upload-page-file-name { /* For the span showing selected file name */
    display: block;
    margin-top: 0.8em;
    font-style: italic;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-align: center;
    word-break: break-all; /* Prevent long names from breaking layout */
}

/* Custom Radio Buttons for Folder Select (Upload Page) */
.folder-select {
    display: flex;
    gap: 10px;
    margin-bottom: 1.5em;
    justify-content: center;
}

.folder-select input[type="radio"] {
    display: none; /* Hide default radio */
}

.folder-select label { /* Label styled as button */
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-secondary);
    padding: 0.7em 1.3em;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--border-radius-sm);
    transition: all var(--transition-medium);
    align-self: auto; /* Override general form label */
    margin-bottom: 0; /* Override general form label */
}

.folder-select input[type="radio"]:checked + label {
    background: var(--text-accent);
    color: var(--button-text-color);
    border-color: var(--text-accent);
    box-shadow: 0 2px 5px rgba(var(--text-accent-rgb), 0.2);
    font-weight: 600;
}

.folder-select label:hover {
    border-color: var(--text-accent);
    color: var(--text-accent);
}

.folder-select input[type="radio"]:checked + label:hover {
    opacity: 0.9;
}

/* Empty Message for file lists */
.empty-message {
    text-align: center;
    font-style: italic;
    color: var(--text-secondary);
    margin-top: 2em;
    padding: 1.5em;
    font-size: 1.1rem;
    background: rgba(var(--surface-bg), 0.5); /* Muted background, was missing 'var' */
    border-radius: var(--border-radius-md);
}

/* Notification Style (for JS) */
.custom-notification {
    position: fixed;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%) translateY(100px); /* Start off-screen */
    background-color: var(--surface-bg);
    color: var(--text-primary);
    padding: 14px 28px;
    border-radius: var(--border-radius-sm);
    z-index: 1001; /* High z-index */
    opacity: 0;
    transition: opacity 0.4s ease-in-out, transform 0.4s ease-in-out;
    box-shadow: 0 5px 20px rgba(0,0,0,0.35);
    border: 1px solid var(--surface-border);
    font-size: 0.95rem;
    font-weight: 500;
}

.custom-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
    body {
        font-size: 15px; /* Adjust base font for mobile */
    }
    .container {
        padding: 1.5em;
        margin: 1.5em 1em; /* Add side margin */
    }

    input[type="text"],
    input[type="password"],
    .file-input-wrapper {
        max-width: 100%;
    }
    form > label { /* ensure labels are also full width on mobile */
        max-width: 100%;
    }

    nav ul {
        flex-direction: column;
        gap: 0.8em;
        align-items: center;
    }
    nav a::after {
        left: 0;
        transform: translateX(0);
        width: 0; /* Reset for vertical */
    }
    nav a:hover::after {
        width: 50%; /* Adjust for vertical */
    }


    h1 { font-size: 1.9rem; }
    h2 { font-size: 1.6rem; }

    .file-list.card-view {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 1.2em;
    }
    .file-item { padding: 1.2em; }

    .file-list-header {
        flex-direction: column; /* Stack title and controls on mobile */
        gap: 1em;
        align-items: stretch; /* Make children take full width */
    }

    .file-list-header h2 {
        text-align: center; /* Center title on mobile */
    }

    .file-header-controls {
        justify-content: center; /* Center the control buttons on mobile */
        width: 100%;
    }

    /* Ensure buttons in controls take up good space if needed */
    .file-header-controls .view-toggle,
    .file-header-controls .folder-toggle-container {
        flex-grow: 1;
        justify-content: center; /* Center buttons within their toggle groups */
    }
/*    .file-header-controls .view-toggle button, */
/*    .file-header-controls .folder-toggle button {*/
         /* width: 100%; /* If you want each button to be full width of its group */
         /* flex-grow: 1; /* If multiple buttons in a group, make them share space */
  /*  } */
    .folder-select {
        flex-direction: column;
        align-items: stretch;
    }
    .folder-select label {
        width: 100%;
    }
}

@media (max-width: 480px) {
    body { font-size: 14px; }
    h1 { font-size: 1.7rem; }
    h2 { font-size: 1.4rem; }

    button, .button-style {
        padding: 0.7em 1.2em;
        font-size: 0.95rem;
    }
    .file-list.card-view {
        grid-template-columns: 1fr; /* Single column */
    }

    .file-list.list-view .file-item {
        flex-wrap: wrap; /* Allow wrapping for very small screens */
        gap: 0.5em;
        padding: 0.8em;
    }
    /* In list view, the <a> tag needs to be full width if things wrap */
    .file-list.list-view .file-item a {
      width: 100%;
      margin-bottom: 0.5em; /* Adjust margin when wrapped */
    }

    .file-list.list-view .file-item p { min-width: 50px; font-size: 0.8rem; }

    .file-list.list-view .share-button,
    .file-list.list-view .delete-button {
        flex-basis: calc(50% - 5px); /* Two buttons side-by-side */
        text-align: center;
        font-size: 0.8rem;
        padding: 0.5em 0.8em;
    }
    .custom-notification {
        width: calc(100% - 30px); /* Full width on mobile */
        bottom: 15px;
        padding: 12px 20px;
    }
}