/* ============================================================
   Asset Manager - Core Styles (LTR + RTL)
   ============================================================ */
:root {
    --primary:    #4f46e5;
    --primary-dk: #3730a3;
    --primary-lt: #e0e7ff;
    --success:    #16a34a;
    --danger:     #dc2626;
    --warning:    #d97706;
    --gray-50:    #f9fafb;
    --gray-100:   #f3f4f6;
    --gray-200:   #e5e7eb;
    --gray-300:   #d1d5db;
    --gray-500:   #6b7280;
    --gray-700:   #374151;
    --gray-900:   #111827;
    --sidebar-w:  250px;
    --header-h:   56px;
    --radius:     8px;
    --shadow:     0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg:  0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--gray-900);
    background: var(--gray-50);
    line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Login page ---------- */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dk) 100%);
    padding: 1rem;
}
.login-card {
    background: #fff;
    width: 100%;
    max-width: 420px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem 2rem;
}
.login-card h1 {
    font-size: 1.5rem;
    margin-bottom: .25rem;
    color: var(--gray-900);
}
.login-card .subtitle {
    color: var(--gray-500);
    font-size: .9rem;
    margin-bottom: 1.75rem;
}
.login-card .logo {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-bottom: 1.5rem;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--primary);
}
.login-card .logo svg { flex-shrink: 0; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    margin-bottom: .3rem;
    font-weight: 500;
    font-size: .875rem;
    color: var(--gray-700);
}
.required::after {
    content: ' *';
    color: var(--danger);
    font-weight: 600;
}
.form-control {
    width: 100%;
    padding: .55rem .75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: .9rem;
    font-family: inherit;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
select.form-control { appearance: auto; }
.form-text { font-size: .8rem; color: var(--gray-500); margin-top: .2rem; }
.form-check { display: flex; align-items: center; gap: .4rem; }
.form-check input { margin: 0; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .55rem 1.15rem;
    border: none;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s, box-shadow .15s;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dk); }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover  { background: #b91c1c; }
.btn-outline   { background: #fff; color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-outline:hover { background: var(--gray-100); }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Alerts ---------- */
.alert {
    padding: .65rem 1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    margin-bottom: 1rem;
}
.alert-success { background: #dcfce7; color: #166534; }
.alert-danger  { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-info    { background: var(--primary-lt); color: var(--primary-dk); }

/* ---------- Layout: sidebar + main (LTR default) ---------- */
.app-layout {
    display: flex;
    min-height: 100vh;
}
.sidebar {
    width: var(--sidebar-w);
    background: var(--gray-900);
    color: #fff;
    position: fixed;
    top: 0; bottom: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

/* LTR positioning */
html[dir="ltr"] .sidebar { left: 0; right: auto; }
html[dir="ltr"] .main-content { margin-left: var(--sidebar-w); margin-right: 0; }
html[dir="ltr"] .sidebar-nav a { border-left: 3px solid transparent; border-right: none; }
html[dir="ltr"] .sidebar-nav a.active { border-left-color: var(--primary); }

/* RTL positioning */
html[dir="rtl"] .sidebar { right: 0; left: auto; }
html[dir="rtl"] .main-content { margin-right: var(--sidebar-w); margin-left: 0; }
html[dir="rtl"] .sidebar-nav a { border-right: 3px solid transparent; border-left: none; }
html[dir="rtl"] .sidebar-nav a.active { border-right-color: var(--primary); }

.sidebar-brand {
    padding: 1rem 1.25rem;
    font-weight: 700;
    font-size: 1.05rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: .5rem;
}
.sidebar-nav { flex: 1; padding: .75rem 0; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem 1.25rem;
    color: var(--gray-300);
    font-size: .875rem;
    transition: background .12s;
}
.sidebar-nav a:hover {
    background: rgba(255,255,255,.06);
    color: #fff;
    text-decoration: none;
}
.sidebar-nav a.active {
    background: rgba(255,255,255,.08);
    color: #fff;
}
.sidebar-section {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--gray-500);
    padding: 1rem 1.25rem .4rem;
}
.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,.08);
    padding: .75rem 1.25rem;
    font-size: .8rem;
    color: var(--gray-500);
}

/* ---------- Main content ---------- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.topbar {
    height: var(--header-h);
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-user {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .875rem;
}
.topbar-user .avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary-lt);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: .8rem;
}
.page-content { padding: 1.5rem; flex: 1; }
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}
.page-header h1 { font-size: 1.35rem; }

/* ---------- Cards ---------- */
.card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-body { padding: 1.25rem; }
.card-header {
    padding: .85rem 1.25rem;
    font-weight: 600;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ---------- Tables ---------- */
.table-wrapper { overflow-x: auto; }
table.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}
table.table th {
    text-align: start;
    padding: .65rem 1rem;
    font-weight: 600;
    color: var(--gray-500);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 2px solid var(--gray-200);
    background: var(--gray-50);
}
table.table td {
    padding: .65rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}
table.table tr:hover { background: var(--gray-50); }

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: .15rem .55rem;
    font-size: .75rem;
    font-weight: 500;
    border-radius: 999px;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: var(--primary-lt); color: var(--primary-dk); }

/* ---------- Permission checkboxes grid ---------- */
.perm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: .5rem;
}
.perm-group { margin-bottom: 1.25rem; }
.perm-group h4 {
    font-size: .85rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: .5rem;
    padding-bottom: .3rem;
    border-bottom: 1px solid var(--gray-200);
}
.perm-group label {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .25rem 0;
    font-size: .85rem;
    cursor: pointer;
}

/* ---------- Language Switcher ---------- */
.lang-switcher {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    font-size: .8rem;
}
.lang-switcher a {
    padding: .2rem .5rem;
    border-radius: 4px;
    color: var(--gray-500);
    font-weight: 500;
}
.lang-switcher a:hover { background: var(--gray-100); text-decoration: none; }
.lang-switcher a.active-lang { background: var(--primary-lt); color: var(--primary); }

/* ---------- Stats grid (dashboard) ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-label {
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--gray-500);
}
.stat-value {
    font-size: 2rem;
    font-weight: 700;
}
.stat-value.color-primary { color: var(--primary); }
.stat-value.color-warning { color: var(--warning); }
.stat-value.color-success { color: var(--success); }

/* ---------- Section heading (in-form) ---------- */
.section-heading {
    font-size: 1rem;
    margin: 1.25rem 0 .75rem;
}

/* ---------- Error page ---------- */
.error-page { background: var(--gray-100); }
.error-page .login-card { text-align: center; }
.error-code {
    font-size: 4rem;
    font-weight: 700;
    color: var(--danger);
}
.error-title { margin-bottom: .5rem; }

/* ---------- Utilities ---------- */
.text-muted { color: var(--gray-500); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-center { text-align: center; }
.text-end { text-align: end; }
.text-sm { font-size: .85rem; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.d-flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: .5rem; }
.align-center { align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.table-empty { text-align: center; padding: 2rem; }

/* ---------- Tree view ---------- */
.tree-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 900px) { .tree-layout { grid-template-columns: 1fr; } }
.tree-list { list-style: none; padding: 0; margin: 0; }
.tree-list .tree-list { padding-inline-start: 1.5rem; }
.tree-node { margin: .2rem 0; }
.tree-node-row {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .4rem .6rem;
    border-radius: var(--radius);
    font-size: .875rem;
    transition: background .1s;
    cursor: default;
}
.tree-node-row:hover { background: var(--gray-100); }
.tree-node-row.active { background: var(--primary-lt); }
.tree-toggle {
    width: 20px; height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    background: none;
    color: var(--gray-500);
    font-size: .7rem;
    flex-shrink: 0;
    transition: transform .15s;
}
.tree-toggle.expanded { transform: rotate(90deg); }
html[dir="rtl"] .tree-toggle { transform: rotate(180deg); }
html[dir="rtl"] .tree-toggle.expanded { transform: rotate(90deg); }
.tree-toggle-placeholder { width: 20px; flex-shrink: 0; }
.tree-label { flex: 1; font-weight: 500; }
.tree-code { color: var(--gray-500); font-size: .75rem; font-weight: 400; }
.tree-meta { color: var(--gray-500); font-size: .75rem; }
.tree-actions { display: flex; gap: .25rem; opacity: 0; transition: opacity .15s; }
.tree-node-row:hover .tree-actions { opacity: 1; }
.tree-children { overflow: hidden; }
.tree-children.collapsed { display: none; }

/* ---------- Picklist tabs ---------- */
.picklist-tabs {
    display: flex;
    gap: .25rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--gray-200);
    padding-bottom: 0;
}
.picklist-tab {
    padding: .5rem 1.25rem;
    font-size: .875rem;
    font-weight: 500;
    color: var(--gray-600);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color .15s, border-color .15s;
    border-radius: var(--radius) var(--radius) 0 0;
}
.picklist-tab:hover { color: var(--primary); background: var(--gray-50); }
.picklist-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: var(--primary-lt);
}

/* ---------- Setup page two-panel ---------- */
.setup-form-panel .card { position: sticky; top: calc(var(--header-h) + 1.5rem); }

/* ---------- Flat list inline form ---------- */
.inline-form { display: flex; gap: .5rem; align-items: end; flex-wrap: wrap; }
.inline-form .form-group { margin-bottom: 0; flex: 1; min-width: 150px; }
.inline-form .btn { align-self: end; }

/* ---------- Modal ---------- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: modalIn .2s ease;
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(-16px); }
    to   { opacity: 1; transform: translateY(0); }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
    font-size: 1.05rem;
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--gray-500);
    line-height: 1;
    padding: .2rem;
}
.modal-close:hover { color: var(--gray-900); }
.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    display: flex;
    gap: .5rem;
    justify-content: flex-end;
    padding: .85rem 1.25rem;
    border-top: 1px solid var(--gray-200);
}
.modal.modal-wide { max-width: 700px; }

/* ---------- Search bar ---------- */
.search-bar {
    padding: .85rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
}
.search-bar input {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: .875rem;
    font-family: inherit;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.search-bar input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
.tree-node-row.search-hit { background: #fef9c3; }
.tree-node-row.search-hit:hover { background: #fef08a; }
.search-no-results { text-align: center; padding: 1.5rem; color: var(--gray-500); display: none; }

/* ---------- Searchable Select ---------- */
.ss-wrapper { position: relative; }
.ss-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    cursor: pointer;
    text-align: start;
    min-height: 2.4rem;
    background: #fff;
}
.ss-trigger:hover { border-color: var(--gray-500); }
.ss-trigger.ss-active {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
.ss-placeholder { color: var(--gray-500); }
.ss-value { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.ss-chevron { flex-shrink: 0; color: var(--gray-500); transition: transform .15s; }
.ss-trigger.ss-active .ss-chevron { transform: rotate(180deg); }
.ss-tags { display: flex; flex-wrap: wrap; gap: .25rem; flex: 1; overflow: hidden; }
.ss-tag {
    display: inline-block;
    background: var(--primary-lt);
    color: var(--primary-dk);
    font-size: .75rem;
    font-weight: 500;
    padding: .1rem .45rem;
    border-radius: 4px;
    white-space: nowrap;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ss-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 500;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    margin-top: 4px;
    animation: ssIn .15s ease;
}
.ss-dropdown.ss-open { display: block; }
.ss-dropdown.ss-above { top: auto; bottom: 100%; margin-top: 0; margin-bottom: 4px; }
@keyframes ssIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.ss-search {
    display: block;
    width: calc(100% - 1rem);
    margin: .5rem;
    padding: .4rem .65rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: .85rem;
    font-family: inherit;
    outline: none;
}
.ss-search:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(79,70,229,.1); }
.ss-list { max-height: 220px; overflow-y: auto; padding: .25rem 0; }
.ss-item {
    padding: .4rem .75rem;
    font-size: .875rem;
    cursor: pointer;
    transition: background .1s;
}
.ss-item:hover { background: var(--gray-100); }
.ss-item.ss-selected { background: var(--primary-lt); color: var(--primary-dk); font-weight: 500; }
.ss-check-label { display: flex; align-items: center; gap: .4rem; cursor: pointer; font-weight: inherit; font-size: inherit; margin: 0; }
.ss-check-label input[type="checkbox"] { margin: 0; accent-color: var(--primary); }
.ss-check-label span { flex: 1; }
.ss-no-results { padding: .75rem; text-align: center; color: var(--gray-500); font-size: .85rem; }

/* ---------- Photo gallery ---------- */
.photo-gallery { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: .5rem; }
.photo-item {
    position: relative;
    width: 120px; height: 120px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--gray-200);
}
.photo-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-item .photo-delete {
    position: absolute;
    top: 4px; right: 4px;
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 22px; height: 22px;
    font-size: .7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity .15s;
}
.photo-item:hover .photo-delete { opacity: 1; }
html[dir="rtl"] .photo-item .photo-delete { right: auto; left: 4px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
@media (max-width: 900px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .grid-3 { grid-template-columns: 1fr; } }

/* ---------- Audit log ---------- */
.audit-detail { font-size: .8rem; max-height: 200px; overflow: auto; background: var(--gray-50); padding: .5rem; border-radius: var(--radius); white-space: pre-wrap; word-break: break-all; }
.audit-action { font-weight: 600; text-transform: uppercase; font-size: .75rem; }
.audit-action.insert { color: var(--success); }
.audit-action.update { color: var(--warning); }
.audit-action.delete { color: var(--danger); }
