:root {
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --card-alt: #f9fafb;
    --input-bg: #ffffff;
    --hover-bg: #f3f4f6;
    --heading: #111827;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #10b981;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --warning: #f59e0b;
    --warning-hover: #d97706;
    --info: #0ea5e9;
    --info-hover: #0284c7;
    --folder: #fbbf24;
    --radius: 8px;
    --shadow: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
    --modal-overlay: rgba(17,24,39,.7);
}
:root[data-theme="dark"] {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --card-alt: #172033;
    --input-bg: #0f172a;
    --hover-bg: #273449;
    --heading: #f8fafc;
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --shadow: 0 4px 6px -1px rgba(0,0,0,.4), 0 2px 4px -1px rgba(0,0,0,.3);
    --modal-overlay: rgba(0,0,0,.75);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-color); color: var(--text-main); line-height: 1.5;
}
.container { max-width: 1000px; margin: 0 auto; padding: 2rem 1rem; }
header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; flex-wrap: wrap; gap: .75rem; }
h1, h2, h3 { color: var(--heading); }
header h1 { font-size: 1.75rem; font-weight: 700; }

/* Cards */
.card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; margin-bottom: 1.5rem; border: 1px solid var(--border-color); }
.card-flush { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 1.25rem 1.5rem .75rem; }
.card-head h3 { font-size: 1.125rem; font-weight: 600; }

/* Forms */
.form-group { margin-bottom: 1rem; }
label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .25rem; color: var(--text-muted); }
input[type="text"], input[type="password"], input[type="search"], select {
    width: 100%; padding: .625rem; border: 1px solid var(--border-color); border-radius: 6px;
    font-size: .875rem; background: var(--input-bg); color: var(--text-main); transition: border-color .2s;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.search-input { max-width: 240px; padding: .4rem .6rem; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .25rem;
    padding: .5rem 1rem; font-size: .875rem; font-weight: 500; line-height: 1.25;
    border: none; border-radius: 6px; cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background-color .2s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-sm { padding: .3rem .65rem; font-size: .78rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: var(--warning-hover); }
.btn-info { background: var(--info); color: #fff; }
.btn-info:hover { background: var(--info-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border-color); color: var(--text-main); }
.btn-outline:hover { background: var(--hover-bg); }

/* Tables */
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: .7rem 1rem; text-align: left; border-bottom: 1px solid var(--border-color); }
th { font-size: .72rem; text-transform: uppercase; font-weight: 600; color: var(--text-muted); background: var(--card-alt); position: sticky; top: 0; z-index: 5; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text-main); }
th.sorted::after { content: " ▲"; font-size: .6rem; }
th.sorted.desc::after { content: " ▼"; }
td { font-size: .875rem; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--hover-bg); }
td.empty { text-align: center; color: var(--text-muted); padding: 2rem; white-space: normal; }
.muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: .75rem; color: var(--text-muted); margin-top: .5rem; }

.name-cell { display: flex; align-items: center; font-weight: 500; max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.name-cell svg { flex-shrink: 0; width: 20px; height: 20px; margin-right: 8px; }
.icon-folder { fill: var(--folder); }
.icon-file { fill: #9ca3af; }
.icon-zip { fill: var(--warning); }
.icon-image { fill: var(--success); }
tr.is-dir .fm-name { font-weight: 600; color: var(--heading); cursor: pointer; }
.fm-name[data-act="preview"] { cursor: zoom-in; }
.action-group { display: inline-flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.action-group .btn { padding: .25rem .55rem; font-size: .75rem; }

/* Progress */
#fm-progress-container { display: none; margin-bottom: .75rem; }
#site-progress-container { display: none; padding: 0 1.5rem .75rem; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.progress-track { width: 100%; background: var(--border-color); border-radius: 999px; height: 8px; overflow: hidden; margin-bottom: .35rem; }
.progress-fill { background: var(--primary); height: 100%; width: 0; transition: width .2s ease; }
.progress-text { font-size: .75rem; font-weight: 600; color: var(--text-muted); text-align: right; display: block; }

/* Modals */
.modal-overlay {
    position: fixed; inset: 0; background: var(--modal-overlay); backdrop-filter: blur(2px);
    display: flex; align-items: center; justify-content: center; padding: 1rem;
    z-index: 1000; opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s;
}
.modal-overlay.active { opacity: 1; visibility: visible; }
/* Dialogs and preview must sit above the file manager */
#previewModal { z-index: 1100; }
#customModal { z-index: 1200; }
.modal-container {
    background: var(--card-bg); border-radius: var(--radius); width: 100%; max-width: 420px;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,.2); display: flex; flex-direction: column;
    transform: scale(.95) translateY(-10px); transition: transform .2s cubic-bezier(.16,1,.3,1);
}
.modal-overlay.active .modal-container { transform: none; }
.modal-wide { max-width: 920px; height: 85vh; max-height: 760px; }
.modal-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border-color); }
.modal-header h3 { font-size: 1.125rem; font-weight: 600; }
.fm-header { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.25rem; }
.modal-body { padding: 1.5rem; font-size: .875rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: .75rem; background: var(--card-alt); border-radius: 0 0 var(--radius) var(--radius); }
.modal-body code { display: block; margin-top: .5rem; padding: .5rem; background: var(--card-alt); border: 1px solid var(--border-color); border-radius: 4px; word-break: break-all; font-size: .75rem; user-select: all; }

/* File manager */
.fm-body { padding: 1rem; overflow: hidden; display: flex; flex-direction: column; flex: 1; }
.fm-nav { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .6rem; flex-wrap: wrap; }
.breadcrumbs { display: flex; align-items: center; flex-wrap: wrap; font-size: .875rem; }
.crumb { color: var(--primary); text-decoration: none; cursor: pointer; }
.crumb:hover { text-decoration: underline; }
.crumb.current { color: var(--heading); font-weight: 600; cursor: default; }
.crumb-sep { color: var(--text-muted); margin: 0 .35rem; }
.fm-toolbar { display: flex; gap: .4rem; margin-bottom: .75rem; flex-wrap: wrap; align-items: center; }
.toolbar-gap { flex: 1; }
.fm-table-wrap { flex: 1; overflow-y: auto; border: 1px solid var(--border-color); border-radius: var(--radius); position: relative; }
.fm-footer { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; font-size: .72rem; color: var(--text-muted); margin-top: .6rem; }
.drop-overlay {
    display: none; position: absolute; inset: 0; align-items: center; justify-content: center;
    background: rgba(59,130,246,.12); border: 2px dashed var(--primary); border-radius: var(--radius);
    color: var(--primary); font-weight: 600; font-size: 1.1rem; pointer-events: none;
}
.fm-table-wrap.dragging .drop-overlay { display: flex; }

/* Preview */
.preview-box { height: auto; max-height: 90vh; }
.preview-body { padding: 1rem; overflow: auto; display: flex; justify-content: center; background: var(--card-alt); border-radius: 0 0 var(--radius) var(--radius); }
.preview-body img { max-width: 100%; max-height: 75vh; object-fit: contain; }

/* Toasts */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; max-width: calc(100vw - 40px); }
.toast {
    min-width: 250px; max-width: 420px; padding: .9rem 1rem; border-radius: var(--radius); box-shadow: var(--shadow);
    color: #fff; font-size: .875rem; font-weight: 500; display: flex; justify-content: space-between; align-items: center; gap: 1rem;
    animation: slideIn .3s cubic-bezier(.16,1,.3,1); white-space: pre-wrap;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast .close { cursor: pointer; font-weight: 700; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(10px); } }

.login-wrapper { max-width: 400px; margin: 10vh auto; }

@media (max-width: 640px) {
    .container { padding: 1rem .75rem; }
    .modal-wide { height: 95vh; }
    .search-input { max-width: 100%; }
}
