/* ============================================================
   CSS CUSTOM PROPERTIES  — Light mode defaults
   ============================================================ */
:root {
    /* ── Palette ── */
    --sand-50:  #faf7f4;
    --sand-100: #f2ebe3;
    --sand-200: #e6d9cc;
    --sand-300: #c9b49a;
    --sand-400: #a98a6a;
    --sand-500: #8a6a4a;

    --blue-100: #e8f0f7;
    --blue-200: #c3d8ed;
    --blue-300: #7aafd6;
    --blue-400: #4a86b8;
    --blue-500: #2d6494;

    --accent:       var(--blue-400);
    --accent-hover: var(--blue-500);

    /* ── Surfaces ── */
    --bg:           var(--sand-50);
    --bg-header:    #ffffff;
    --bg-card:      #ffffff;
    --bg-hover:     var(--sand-100);
    --bg-alt:       var(--sand-100);
    --bg-player:    #ffffff;

    /* ── Borders ── */
    --border:       var(--sand-200);
    --border-focus: var(--blue-300);

    /* ── Text ── */
    --text-primary:   #2c2218;
    --text-secondary: #6b5745;
    --text-muted:     #9c8470;
    --text-on-accent: #ffffff;

    /* ── Icons ── */
    --icon-folder: #c4883a;
    --icon-audio:  var(--blue-400);
    --icon-pdf:    #c0392b;
    --icon-zip:    #8e44ad;
    --icon-image:  #27ae60;
    --icon-video:  #2980b9;
    --icon-text:   #7f8c8d;
    --icon-unknown:#95a5a6;

    /* ── Shadows ── */
    --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
    --shadow-md: 0 4px 16px rgba(0,0,0,.10);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.14);

    /* ── Radii / Spacing ── */
    --radius:    10px;
    --radius-sm: 6px;
    --radius-lg: 16px;
    --gutter:    clamp(1rem, 4vw, 2rem);

    /* ── Typography ── */
    --font-ar: 'Segoe UI', 'Tahoma', 'Arial', sans-serif;
    --font-mono: 'Consolas', 'Monaco', monospace;
    --size-xs:  .75rem;
    --size-sm:  .875rem;
    --size-base:1rem;
    --size-lg:  1.125rem;
    --size-xl:  1.5rem;
    --size-2xl: 2rem;
    --size-3xl: 2.6rem;

    /* ── Transition ── */
    --tr: 200ms ease;

    /* ── Player height ── */
    --player-h: 120px;
}

/* ── Dark Mode ── */
html.dark {
    --bg:           #1a1410;
    --bg-header:    #221b13;
    --bg-card:      #2a2018;
    --bg-hover:     #332818;
    --bg-alt:       #241c14;
    --bg-player:    #1e1610;

    --border:       #3d2f22;
    --border-focus: var(--blue-300);

    --text-primary:   #f0e8df;
    --text-secondary: #c4a882;
    --text-muted:     #8a7060;

    --sand-200: #3a2c20;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
    --shadow-md: 0 4px 16px rgba(0,0,0,.4);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.5);

    --accent:       var(--blue-300);
    --accent-hover: var(--blue-400);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-family:   var(--font-ar);
    font-size:     var(--size-base);
    color:         var(--text-primary);
    background:    var(--bg);
    scroll-behavior: smooth;
    transition: background var(--tr), color var(--tr);
}

body {
    min-height: 100dvh;
    padding-bottom: calc(var(--player-h) + 2rem);
    display: flex;
    flex-direction: column;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select { font-family: inherit; }
svg { display: block; }

/* ============================================================
   SITE HEADER
   ============================================================ */
.site-header {
    background:    var(--bg-header);
    border-bottom: 1px solid var(--border);
    box-shadow:    var(--shadow-sm);
    position:      sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 1100px;
    margin:    0 auto;
    padding:   1.1rem var(--gutter);
    display:   flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.site-title-ar {
    font-size:   var(--size-xl);
    font-weight: 700;
    letter-spacing: .01em;
    color:       var(--text-primary);
    line-height: 1.2;
}

/* ── Dark Toggle ── */
.dark-toggle {
    width:  42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background:    var(--bg-alt);
    color:         var(--text-secondary);
    display:       flex;
    align-items:   center;
    justify-content: center;
    flex-shrink:   0;
    transition:    background var(--tr), border-color var(--tr), color var(--tr);
}
.dark-toggle:hover {
    background:    var(--bg-hover);
    color:         var(--accent);
}
.dark-toggle svg { width: 20px; height: 20px; }
.dark-toggle .icon-sun  { display: block; }
.dark-toggle .icon-moon { display: none;  }
html.dark .dark-toggle .icon-sun  { display: none;  }
html.dark .dark-toggle .icon-moon { display: block; }

/* ============================================================
   BREADCRUMB
   ============================================================ */
.breadcrumb {
    background: var(--bg-alt);
    border-bottom: 1px solid var(--border);
}

.breadcrumb-inner {
    max-width: 1100px;
    margin:    0 auto;
    padding:   .6rem var(--gutter);
    display:   flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .3rem .15rem;
    font-size: var(--size-sm);
    color:     var(--text-muted);
}

.bc-sep { margin: 0 .3rem; color: var(--text-muted); }

.bc-link {
    color: var(--accent);
    border-radius: var(--radius-sm);
    padding: .1rem .3rem;
    transition: background var(--tr), color var(--tr);
}
.bc-link:hover {
    background: var(--blue-100);
    color:      var(--accent-hover);
}
html.dark .bc-link:hover { background: rgba(122,175,214,.12); }

.bc-current {
    color: var(--text-secondary);
    font-weight: 600;
    padding: .1rem .3rem;
}

/* ============================================================
   SEARCH
   ============================================================ */
.search-wrap {
    max-width: 1100px;
    margin: 1.25rem auto .5rem;
    padding: 0 var(--gutter);
}

.search-inner {
    position: relative;
    display:  flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    right:    .9rem;
    color:    var(--text-muted);
    pointer-events: none;
}
.search-icon svg { width: 18px; height: 18px; }

.search-input {
    width:         100%;
    padding:       .65rem .9rem .65rem 2.8rem;
    padding-right: 2.8rem;
    background:    var(--bg-card);
    border:        1px solid var(--border);
    border-radius: var(--radius);
    color:         var(--text-primary);
    font-size:     var(--size-base);
    outline:       none;
    transition:    border-color var(--tr), box-shadow var(--tr);
    /* RTL — icon on right */
    text-align:    right;
}
.search-input:focus {
    border-color: var(--border-focus);
    box-shadow:   0 0 0 3px rgba(74,134,184,.18);
}
.search-input::placeholder { color: var(--text-muted); }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
    max-width:  1100px;
    margin:     .75rem auto 0;
    padding:    0 var(--gutter) 2rem;
    flex: 1;
}

/* ── Empty State ── */
.empty-state {
    display:         flex;
    flex-direction:  column;
    align-items:     center;
    justify-content: center;
    gap:             1rem;
    padding:         5rem 2rem;
    text-align:      center;
}
.empty-icon { font-size: 4rem; }
.empty-text {
    font-size:   var(--size-lg);
    color:       var(--text-muted);
    font-weight: 500;
}

/* ── No-results ── */
.no-results {
    padding:   2rem;
    text-align: center;
    color:     var(--text-muted);
    font-size: var(--size-sm);
}

/* ── Table Wrapper ── */
.table-wrap {
    background:    var(--bg-card);
    border:        1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow:      hidden;
    box-shadow:    var(--shadow-sm);
}

/* ── File Table ── */
.file-table {
    width:           100%;
    border-collapse: collapse;
}

.file-table thead tr {
    background:    var(--bg-alt);
    border-bottom: 2px solid var(--border);
}

.file-table th {
    padding:     .8rem 1rem;
    font-size:   var(--size-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color:       var(--text-muted);
    text-align:  right;
    white-space: nowrap;
}
.file-table th.col-name    { width: 50%; }
.file-table th.col-size    { width: 10%; }
.file-table th.col-date    { width: 18%; }
.file-table th.col-actions { width: 22%; text-align: center; }

/* ── Rows ── */
.file-row {
    border-bottom: 1px solid var(--border);
    transition:    background var(--tr);
}
.file-row:last-child { border-bottom: none; }
.file-row:hover { background: var(--bg-hover); }

.file-table td {
    padding:  1.1rem 1.25rem;
    vertical-align: middle;
    font-size: var(--size-base);
    color:     var(--text-secondary);
}

/* ── Name Cell ── */
.name-cell {
    display:     flex;
    align-items: center;
    gap:         .85rem;
}

.file-icon {
    flex-shrink: 0;
    width:       22px;
    height:      22px;
    display:     flex;
}
.file-icon svg { width: 22px; height: 22px; }

.icon-folder  svg { color: var(--icon-folder); }
.icon-audio   svg { color: var(--icon-audio);  }
.icon-pdf     svg { color: var(--icon-pdf);    }
.icon-zip     svg { color: var(--icon-zip);    }
.icon-image   svg { color: var(--icon-image);  }
.icon-video   svg { color: var(--icon-video);  }
.icon-text    svg { color: var(--icon-text);   }
.icon-unknown svg { color: var(--icon-unknown);}

.item-link {
    color:       var(--text-primary);
    font-weight: 600;
    font-size:   var(--size-base);
    background:  none;
    border:      none;
    padding:     0;
    text-align:  right;
    cursor:      pointer;
    transition:  color var(--tr);
    word-break:  break-word;
}
.item-link:hover { color: var(--accent); text-decoration: underline; }
.audio-link      { color: var(--accent); }
.audio-link:hover{ color: var(--accent-hover); }

/* ── Size & Date ── */
.col-size, .col-date {
    white-space: nowrap;
    font-size:   var(--size-xs);
    color:       var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* ── Action Buttons ── */
.action-btns {
    display:    flex;
    align-items:center;
    justify-content: center;
    gap:        .4rem;
    flex-wrap:  wrap;
}

.action-btn {
    width:         36px;
    height:        36px;
    border-radius: var(--radius-sm);
    display:       flex;
    align-items:   center;
    justify-content: center;
    color:         var(--text-muted);
    background:    var(--bg-alt);
    border:        1px solid var(--border);
    transition:    background var(--tr), color var(--tr), border-color var(--tr);
    flex-shrink:   0;
}
.action-btn svg { width: 18px; height: 18px; }
.action-btn:hover        { background: var(--bg-hover); color: var(--accent); border-color: var(--border-focus); }
.action-btn.play-btn:hover { color: var(--icon-audio); }
.action-btn.dl-btn:hover   { color: var(--blue-500); }
.action-btn.open-btn:hover { color: var(--sand-500); }

/* ============================================================
   STICKY AUDIO PLAYER
   ============================================================ */
.audio-player {
    position:      fixed;
    bottom:        0;
    left:          0;
    right:         0;
    background:    var(--bg-player);
    border-top:    2px solid var(--border);
    box-shadow:    var(--shadow-lg);
    z-index:       200;
    padding:       .75rem var(--gutter);
    transition:    background var(--tr), border-color var(--tr);
}
.audio-player[hidden] { display: none; }
.audio-player:not([hidden]) { display: block; }

.player-inner {
    max-width:   1100px;
    margin:      0 auto;
    display:     flex;
    flex-direction: column;
    gap:         .55rem;
}

/* Track info */
.player-info {
    display:     flex;
    align-items: center;
    gap:         .5rem;
    min-width:   0;
}
.player-icon svg { width: 18px; height: 18px; color: var(--accent); }

.player-track {
    font-size:    var(--size-sm);
    font-weight:  600;
    color:        var(--text-primary);
    white-space:  nowrap;
    overflow:     hidden;
    text-overflow:ellipsis;
    flex: 1;
    min-width: 0;
}

/* Controls */
.player-controls {
    display:     flex;
    align-items: center;
    gap:         .5rem;
    flex-wrap:   wrap;
}

.player-btn {
    width:         34px;
    height:        34px;
    border-radius: var(--radius-sm);
    display:       flex;
    align-items:   center;
    justify-content: center;
    color:         var(--text-secondary);
    background:    var(--bg-alt);
    border:        1px solid var(--border);
    transition:    background var(--tr), color var(--tr);
    flex-shrink:   0;
    text-decoration: none;
}
.player-btn svg { width: 18px; height: 18px; }
.player-btn:hover { background: var(--bg-hover); color: var(--accent); }

.player-play {
    background: var(--accent);
    color:      var(--text-on-accent);
    border-color: var(--accent);
    width:  42px;
    height: 42px;
}
.player-play svg { width: 22px; height: 22px; }
.player-play:hover { background: var(--accent-hover); color: var(--text-on-accent); }

.player-close { color: var(--text-muted); }
.player-close:hover { color: #c0392b; }

.player-time {
    font-size:     var(--size-xs);
    color:         var(--text-muted);
    white-space:   nowrap;
    font-variant-numeric: tabular-nums;
    min-width:     3ch;
}

/* Seek & Volume Range Inputs */
.player-seek, .player-volume {
    -webkit-appearance: none;
    appearance:         none;
    height:             4px;
    border-radius:      2px;
    background:         var(--border);
    outline:            none;
    cursor:             pointer;
    accent-color:       var(--accent);
    transition:         background var(--tr);
}
.player-seek  { flex: 1; min-width: 80px; }
.player-volume { width: 80px; }

.player-seek::-webkit-slider-thumb,
.player-volume::-webkit-slider-thumb {
    -webkit-appearance: none;
    width:  14px;
    height: 14px;
    border-radius: 50%;
    background:    var(--accent);
    cursor:        pointer;
}
.player-seek::-moz-range-thumb,
.player-volume::-moz-range-thumb {
    width:  14px;
    height: 14px;
    border-radius: 50%;
    background:    var(--accent);
    border:        none;
    cursor:        pointer;
}

.player-vol-icon svg { width: 18px; height: 18px; color: var(--text-muted); }

/* Speed select */
.player-speed {
    font-size:    var(--size-xs);
    background:   var(--bg-alt);
    border:       1px solid var(--border);
    border-radius:var(--radius-sm);
    color:        var(--text-secondary);
    padding:      .2rem .35rem;
    height:       34px;
    cursor:       pointer;
    outline:      none;
    transition:   border-color var(--tr);
}
.player-speed:focus { border-color: var(--border-focus); }

/* ============================================================
   FOOTER
   ============================================================ */
.site-footer {
    background:    var(--bg-header);
    border-top:    1px solid var(--border);
    margin-top:    auto;
}
.footer-inner {
    max-width:   1100px;
    margin:      0 auto;
    padding:     1rem var(--gutter);
    display:     flex;
    align-items: center;
    justify-content: center;
    gap:         .5rem;
    font-size:   var(--size-xs);
    color:       var(--text-muted);
}
.footer-sep { color: var(--sand-300); }

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Tablet — hide date column */
@media (max-width: 768px) {
    .col-date { display: none; }

    .file-table th.col-name    { width: 60%; }
    .file-table th.col-size    { width: 15%; }
    .file-table th.col-actions { width: 25%; }

    .player-volume { width: 55px; }
    .player-speed  { display: none; }
}

/* Phone */
@media (max-width: 520px) {
    .col-size  { display: none; }
    .col-date  { display: none; }

    .file-table th.col-name    { width: 70%; }
    .file-table th.col-actions { width: 30%; }

    .site-title-ar { font-size: var(--size-lg); }

    .player-volume { display: none; }
    .player-vol-icon { display: none; }

    .search-input { font-size: var(--size-sm); }
}

/* Very small — stack player controls */
@media (max-width: 420px) {
    .player-controls { gap: .3rem; }
    .player-seek { min-width: 60px; }
}

/* ============================================================
   SCROLLBAR (Webkit)
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--sand-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--sand-400); }

/* ============================================================
   FOCUS VISIBLE
   ============================================================ */
:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
}
