* { box-sizing: border-box; }

:root {
    --bg: #f6f8fc;
    --card: #ffffff;
    --text: #13233a;
    --muted: #5e6b7e;
    --primary: #2e6bff;
    --primary-strong: #2254cc;
    --secondary: #6b7383;
    --border: #e5eaf3;
    --shadow: 0 10px 28px rgba(17, 34, 68, 0.08);
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Segoe UI", Arial, sans-serif;
    background: radial-gradient(circle at top, #eef3ff 0%, var(--bg) 45%);
    color: var(--text);
}

.container {
    max-width: 1420px;
    margin: 0 auto;
    padding: 28px 24px 40px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px;
    box-shadow: var(--shadow);
}

.hidden { display: none !important; }

.eyebrow {
    margin: 0 0 6px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--primary);
}

.muted {
    color: var(--muted);
    margin: 6px 0 0;
}

.login-shell {
    max-width: 560px;
    margin: 9vh auto 0;
    padding: 28px;
}

.login-shell h1 {
    margin: 0;
    font-size: clamp(1.35rem, 4.2vw, 1.85rem);
    line-height: 1.3;
    font-weight: 700;
}

.db-connection-status {
    margin-top: 16px;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.45;
    border: 1px solid var(--border, #2a3544);
}

.db-connection-status.loading {
    background: var(--surface-2, #1a2332);
    color: var(--muted, #94a3b8);
}

.db-connection-status.ok {
    background: rgba(34, 197, 94, 0.12);
    border-color: rgba(34, 197, 94, 0.35);
    color: #86efac;
}

.db-connection-status.info {
    background: rgba(59, 130, 246, 0.12);
    border-color: rgba(59, 130, 246, 0.35);
    color: #93c5fd;
}

.db-connection-status.error {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.35);
    color: #fca5a5;
}

.db-connection-actions {
    margin: 8px 0 0;
}

.db-connection-actions .small-btn {
    font-size: 12px;
    padding: 6px 12px;
}

.login-form {
    margin-top: 20px;
}

.app {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.topbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.panel-role-badge {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    padding: 6px 10px;
    border-radius: 999px;
    background: #f0f4fb;
    border: 1px solid var(--border);
    white-space: nowrap;
}

.panel-role-badge.is-admin {
    color: #1a4a8c;
    background: #e8f0ff;
    border-color: #c5d9ff;
}

.topbar h1 {
    margin: 0;
    font-size: 26px;
}

.grid {
    display: grid;
    gap: 14px;
    grid-template-columns: 1.1fr 1.5fr 1.1fr;
    align-items: start;
}

.panel h2 {
    margin: 0 0 12px;
    font-size: 20px;
}

.panel h3 {
    margin: 0 0 10px;
    font-size: 16px;
}

button {
    border: none;
    border-radius: 11px;
    padding: 11px 14px;
    cursor: pointer;
    background: linear-gradient(180deg, var(--primary), var(--primary-strong));
    color: #fff;
    font-weight: 600;
    transition: transform .12s ease, opacity .12s ease;
}

button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }

button.secondary {
    background: #eef2f9;
    color: #30415d;
    border: 1px solid #d4dceb;
}

button.danger {
    background: #ffecee;
    color: #b4232d;
    border: 1px solid #f4c2c8;
}

label {
    display: block;
    margin-bottom: 10px;
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="file"],
select {
    width: 100%;
    margin-top: 6px;
    padding: 10px 12px;
    border: 1px solid #d8dfeb;
    border-radius: 10px;
    font-size: 14px;
    background: #fff;
}

input:focus {
    outline: none;
    border-color: #98b5ff;
    box-shadow: 0 0 0 3px rgba(46, 107, 255, 0.13);
}

.actions {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}

.upload-form {
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

.help-text {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.upload-queue {
    margin-top: 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f9fbff;
    padding: 10px;
}

.upload-queue h4 {
    margin: 0 0 8px;
    font-size: 13px;
}

.upload-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px dashed #dbe4f3;
}

.upload-item:last-child {
    border-bottom: 0;
}

.upload-item-name {
    font-size: 12px;
    color: #253857;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-item-status {
    font-size: 12px;
    font-weight: 700;
}

.upload-item-error {
    grid-column: 1 / -1;
    font-size: 11px;
    color: #b4232d;
    background: #fff3f5;
    border: 1px solid #f4c9cf;
    border-radius: 8px;
    padding: 5px 8px;
}

.upload-item-status.pending { color: #7a8497; }
.upload-item-status.uploading { color: #2b5aca; }
.upload-item-status.done { color: #197235; }
.upload-item-status.skipped { color: #8a6a1d; }
.upload-item-status.error { color: #b4232d; }

.panel-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    background: #edf3ff;
    color: #2b5aca;
    border: 1px solid #d8e5ff;
    font-size: 12px;
    font-weight: 700;
    padding: 6px 10px;
}

.left-panel,
.center-panel {
    min-height: 66vh;
}

.folder-list,
.file-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 62vh;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    background: #fbfcff;
}

.folder-item,
.file-item {
    background: #fff;
    border: 1px solid #e3eaf7;
    border-radius: 10px;
    padding: 8px;
}

.folder-item.active {
    border-color: #8fb0ff;
    background: #eef4ff;
}

.folder-title-btn {
    width: 100%;
    text-align: left;
    background: transparent;
    color: #1a2f50;
    border: none;
    padding: 0 0 6px;
    font-weight: 700;
}

.folder-item-actions,
.file-item-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.folder-item-actions button,
.file-item-actions button {
    padding: 5px 8px;
    font-size: 12px;
}

.file-item-name {
    font-size: 13px;
    font-weight: 700;
    color: #1a2f50;
    padding-bottom: 6px;
    border-bottom: 1px solid #edf2fb;
    margin-bottom: 6px;
    word-break: break-word;
}

/* z-index alto: em alguns temas da hospedagem o conteúdo do painel cobria as modais */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(9, 16, 31, 0.45);
    z-index: 99998;
}

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 99999;
    padding: 16px;
    overflow-y: auto;
}

.modal.modal-layer-up {
    z-index: 100000;
}

.modal-card {
    width: min(650px, 100%);
    max-height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: 0 20px 40px rgba(17, 34, 68, 0.2);
    padding: 14px;
    overflow: hidden;
}

.modal-card-wide {
    width: min(720px, 100%);
}

.api-link-body {
    max-height: min(70vh, 520px);
    overflow-y: auto;
    padding-right: 4px;
}

.api-url-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
    margin-top: 6px;
}

.api-url-input {
    flex: 1;
    min-width: 0;
    font-family: Consolas, "Courier New", monospace;
    font-size: 12px;
}

.api-endpoint-list {
    margin: 0 0 12px;
    padding-left: 18px;
    font-size: 12px;
    word-break: break-all;
}

.api-endpoint-list code {
    font-size: 11px;
}

.api-snippet {
    width: 100%;
    margin-top: 6px;
    font-family: Consolas, "Courier New", monospace;
    font-size: 11px;
    line-height: 1.4;
    resize: vertical;
    min-height: 200px;
}

.api-link-actions {
    margin-top: 8px;
}

.modal-header {
    flex: 0 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.modal-header h3 {
    margin: 0;
}

.modal-header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
}

.modal-intro {
    margin: 0 0 12px;
}

.modal-card-downloads {
    width: min(560px, 100%);
}

.downloads-modal-body {
    flex: 1 1 auto;
    min-height: 120px;
    max-height: min(58vh, 440px);
    overflow-y: auto;
    padding-right: 4px;
}

.downloads-public-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.downloads-item-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: linear-gradient(180deg, #fbfcff 0%, #f4f7fc 100%);
}

.downloads-item-text {
    min-width: 0;
    flex: 1;
}

.downloads-item-title {
    display: block;
    font-weight: 700;
    font-size: 15px;
    color: #1a2f50;
    line-height: 1.35;
    word-break: break-word;
}

.downloads-item-sub {
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.4;
    color: var(--muted);
}

.downloads-item-file {
    font-size: 11px;
    word-break: break-all;
}

.downloads-item-meta {
    font-weight: 600;
    color: #4a5b78;
}

.downloads-item-dl {
    flex-shrink: 0;
}

.downloads-manage-scroll {
    flex: 1 1 auto;
    min-height: 0;
    max-height: min(72vh, 560px);
    overflow-y: auto;
    padding-right: 4px;
}

.downloads-manage-section {
    margin-bottom: 20px;
}

.downloads-manage-section:last-child {
    margin-bottom: 0;
}

.downloads-section-title {
    margin: 0 0 8px;
    font-size: 15px;
    font-weight: 700;
    color: #1a2f50;
}

#createFolderModal .upload-form,
#uploadModal .upload-form,
#uploadFolderModal .upload-form,
#moveFileModal .upload-form,
#apiLinkModal .upload-form {
    flex: 1 1 auto;
    overflow-y: auto;
    padding-right: 4px;
}

#uploadModal .upload-queue,
#uploadFolderModal .upload-queue {
    max-height: 240px;
    overflow-y: auto;
}

.preview-path {
    margin: 0 0 10px;
    font-size: 13px;
    color: var(--muted);
    background: #f4f7fc;
    border: 1px solid var(--border);
    padding: 10px;
    border-radius: 10px;
    word-break: break-word;
}

.image-preview {
    width: 100%;
    max-height: 420px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fafcff;
}

audio, video {
    width: 100%;
    margin-top: 10px;
    border-radius: 12px;
}

.status-message {
    margin: 0;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #c6dfcc;
    background: #eef9f0;
    color: #1d6c2b;
    font-size: 13px;
    font-weight: 600;
}

.status-message.error {
    border-color: #f3c6cb;
    background: #fff1f3;
    color: #a22631;
}

.login-form-feedback {
    margin-top: 14px;
}

.downloads-table code {
    word-break: break-word;
    font-size: 12px;
}

.downloads-display-title {
    display: block;
    margin-bottom: 6px;
    font-size: 15px;
}

.downloads-file-ref {
    margin-top: 4px;
}

.downloads-file-ref code {
    color: var(--muted, #64748b);
}

.downloads-admin-cell {
    min-width: 220px;
    vertical-align: top;
}

.downloads-label-field {
    display: block;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 8px;
}

.downloads-label-field input {
    width: 100%;
    margin-top: 4px;
    font-weight: 400;
}

.downloads-admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
}

.help-text.tiny {
    font-size: 11px;
    margin: 0;
}

.login-form-feedback:not(.hidden) {
    display: block;
}

#loginSubmitBtn:disabled {
    opacity: 0.75;
    cursor: wait;
}

.wma-folder-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.wma-folder-item {
    background: #fff8e8;
    border: 1px solid #f0d59b;
    color: #6b4b08;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 700;
}

#videoFoldersInfo .wma-folder-item {
    background: #e8f4ff;
    border-color: #a8c8e8;
    color: #1a4a6e;
}

.users-admin-view {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.panel-users-table-wrap {
    overflow-x: auto;
}

.panel-users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.panel-users-table th,
.panel-users-table td {
    border: 1px solid var(--border, #d8dee8);
    padding: 8px 10px;
    text-align: left;
    vertical-align: top;
}

.panel-users-table th {
    background: #f4f7fc;
    font-weight: 700;
}

.panel-user-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

button.sm {
    font-size: 12px;
    padding: 5px 10px;
}

.help-text.error-text {
    color: #a22631;
    font-weight: 600;
}

@media (max-width: 1180px) {
    .grid { grid-template-columns: 1fr; }
    .folder-list,
    .file-list { max-height: 40vh; }
}
