/* ============================================================
   Spreadsheet Manager – Frontend Styles
   All rules are scoped to .sm-wrapper to avoid theme conflicts.
   ============================================================ */

/* ── Design tokens ─────────────────────────────────────────────────────── */
/* Defined on :root so modals/toasts appended to <body> inherit them too  */
:root {
    --sm-primary:      #3b5bdb;
    --sm-primary-h:    #2f4ac4;
    --sm-primary-bg:   rgba(59,91,219,.08);
    --sm-danger:       #e03131;
    --sm-danger-bg:    rgba(224,49,49,.08);
    --sm-success:      #2f9e44;
    --sm-surface:      #ffffff;
    --sm-bg:           #f4f5f7;
    --sm-border:       #dde1e7;
    --sm-text:         #1a1d23;
    --sm-muted:        #6b7280;
    --sm-radius-sm:    6px;
    --sm-radius:       12px;
    --sm-radius-lg:    16px;
    --sm-shadow:       0 1px 4px rgba(0,0,0,.07), 0 4px 16px rgba(0,0,0,.05);
    --sm-shadow-lg:    0 8px 32px rgba(0,0,0,.18);
    --sm-ease:         0.18s cubic-bezier(.4,0,.2,1);
    --sm-font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ── Base reset inside wrapper ─────────────────────────────────────────── */
.sm-wrapper *, .sm-wrapper *::before, .sm-wrapper *::after {
    box-sizing: border-box;
    margin: 0; padding: 0;
}

.sm-wrapper {
    font-family:   var(--sm-font);
    font-size:     14px;
    line-height:   1.5;
    color:         var(--sm-text);
    background:    var(--sm-bg);
    border-radius: var(--sm-radius);
    padding:       28px;
}

/* ── Inline error (shown before JS loads) ─────────────────────────────── */
.sm-inline-error {
    font-family:   var(--sm-font, sans-serif);
    background:    #fff5f5;
    border:        1px solid #ffc9c9;
    border-left:   4px solid #e03131;
    color:         #c92a2a;
    border-radius: 6px;
    padding:       12px 16px;
    font-size:     14px;
}
.sm-inline-error a { color: inherit; }

/* ── Header bar ────────────────────────────────────────────────────────── */
.sm-header {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    gap:             16px;
    margin-bottom:   24px;
    flex-wrap:       wrap;
}

.sm-header-title {
    font-size:      20px;
    font-weight:    700;
    letter-spacing: -.4px;
    color:          var(--sm-text);
}

.sm-header-actions {
    display:     flex;
    align-items: center;
    gap:         10px;
    flex-wrap:   wrap;
}

/* ── Search box ────────────────────────────────────────────────────────── */
.sm-search {
    position: relative;
}

.sm-search-icon {
    position:        absolute;
    left:            10px;
    top:             50%;
    transform:       translateY(-50%);
    color:           var(--sm-muted);
    pointer-events:  none;
    display:         flex;
}

.sm-search input {
    width:         200px;
    padding:       8px 12px 8px 34px;
    border:        1.5px solid var(--sm-border);
    border-radius: var(--sm-radius-sm);
    font-size:     14px;
    font-family:   var(--sm-font);
    background:    var(--sm-surface);
    color:         var(--sm-text);
    outline:       none;
    transition:    border-color var(--sm-ease), box-shadow var(--sm-ease);
}

.sm-search input:focus {
    border-color: var(--sm-primary);
    box-shadow:   0 0 0 3px var(--sm-primary-bg);
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.sm-btn {
    display:      inline-flex;
    align-items:  center;
    gap:          6px;
    padding:      8px 16px;
    border-radius: var(--sm-radius-sm);
    font-size:    14px;
    font-weight:  600;
    font-family:  var(--sm-font);
    cursor:       pointer;
    border:       1.5px solid transparent;
    line-height:  1;
    transition:   all var(--sm-ease);
    text-decoration: none;
}
.sm-btn svg { flex-shrink: 0; }

.sm-btn-primary {
    background:  var(--sm-primary);
    color:       #fff;
    border-color: var(--sm-primary);
}
.sm-btn-primary:hover {
    background:  var(--sm-primary-h);
    border-color: var(--sm-primary-h);
    transform:   translateY(-1px);
    box-shadow:  0 4px 14px rgba(59,91,219,.35);
}
.sm-btn-primary:active { transform: translateY(0); box-shadow: none; }

.sm-btn-ghost {
    background:  transparent;
    color:       var(--sm-muted);
    border-color: var(--sm-border);
}
.sm-btn-ghost:hover {
    border-color: var(--sm-primary);
    color:        var(--sm-primary);
}

.sm-btn-danger-outline {
    background:  transparent;
    color:       var(--sm-danger);
    border-color: var(--sm-danger);
}
.sm-btn-danger-outline:hover {
    background: var(--sm-danger);
    color:      #fff;
}

/* Icon-only card action buttons */
.sm-icon-btn {
    display:      inline-flex;
    align-items:  center;
    justify-content: center;
    width:        30px;
    height:       30px;
    border:       none;
    border-radius: var(--sm-radius-sm);
    cursor:       pointer;
    background:   transparent;
    color:        var(--sm-muted);
    transition:   all var(--sm-ease);
}
.sm-icon-btn:hover            { background: var(--sm-bg); color: var(--sm-primary); }
.sm-icon-btn.sm-btn-del:hover { color: var(--sm-danger); background: var(--sm-danger-bg); }

/* ── Stats row ──────────────────────────────────────────────────────────── */
.sm-stats {
    font-size:     13px;
    color:         var(--sm-muted);
    margin-bottom: 16px;
}

/* ── Card grid ──────────────────────────────────────────────────────────── */
.sm-grid {
    display:               grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap:                   16px;
}

/* ── Individual card ────────────────────────────────────────────────────── */
.sm-card {
    background:    var(--sm-surface);
    border:        1.5px solid var(--sm-border);
    border-radius: var(--sm-radius);
    padding:       18px;
    position:      relative;
    transition:    box-shadow var(--sm-ease), transform var(--sm-ease), border-color var(--sm-ease);
    animation:     sm-card-in 0.28s ease both;
}
.sm-card:hover {
    box-shadow:   var(--sm-shadow);
    border-color: #c5cae0;
    transform:    translateY(-2px);
}

@keyframes sm-card-in {
    from { opacity: 0; transform: translateY(10px) scale(.98); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* Card action buttons (top-right corner) */
.sm-card-actions {
    position:   absolute;
    top:        12px;
    right:      12px;
    display:    flex;
    gap:        2px;
    opacity:    0;
    transition: opacity var(--sm-ease);
}
.sm-card:hover .sm-card-actions { opacity: 1; }

/* Badge showing row number */
.sm-card-badge {
    display:        inline-block;
    padding:        2px 8px;
    background:     var(--sm-primary-bg);
    color:          var(--sm-primary);
    font-size:      11px;
    font-weight:    700;
    letter-spacing: .5px;
    text-transform: uppercase;
    border-radius:  4px;
    margin-bottom:  14px;
}

.sm-card-fields { display: flex; flex-direction: column; gap: 10px; }

.sm-field {}
.sm-field-label {
    font-size:      10.5px;
    font-weight:    700;
    text-transform: uppercase;
    letter-spacing: .6px;
    color:          var(--sm-muted);
    margin-bottom:  2px;
}
.sm-field-value {
    font-size:  14px;
    color:      var(--sm-text);
    word-break: break-word;
}
.sm-field-empty { color: var(--sm-muted); font-style: italic; }

/* ── Empty state ────────────────────────────────────────────────────────── */
.sm-empty {
    grid-column:     1 / -1;
    text-align:      center;
    padding:         64px 24px;
    color:           var(--sm-muted);
}
.sm-empty-icon {
    width: 56px; height: 56px;
    background: var(--sm-border);
    border-radius: 50%;
    display:        flex;
    align-items:    center;
    justify-content: center;
    margin:         0 auto 16px;
    color:          var(--sm-muted);
}
.sm-empty h3 {
    font-size:   18px;
    font-weight: 700;
    color:       var(--sm-text);
    margin-bottom: 6px;
}

/* ── Loading spinner ────────────────────────────────────────────────────── */
.sm-loading {
    display:         flex;
    flex-direction:  column;
    align-items:     center;
    justify-content: center;
    padding:         72px 24px;
    color:           var(--sm-muted);
    gap:             12px;
}
.sm-spinner {
    width:           38px;
    height:          38px;
    border:          3px solid var(--sm-border);
    border-top-color: var(--sm-primary);
    border-radius:   50%;
    animation:       sm-spin .75s linear infinite;
}
@keyframes sm-spin { to { transform: rotate(360deg); } }

/* ── Modal overlay ──────────────────────────────────────────────────────── */
.sm-overlay {
    position:        fixed;
    inset:           0;
    background:      rgba(10,15,30,.52);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index:         999990;
    display:         flex;
    align-items:     center;
    justify-content: center;
    padding:         20px;
    animation:       sm-overlay-in .18s ease;
}
@keyframes sm-overlay-in { from { opacity: 0; } to { opacity: 1; } }

/* ── Modal card ─────────────────────────────────────────────────────────── */
.sm-modal {
    background:  var(--sm-surface);
    border-radius: var(--sm-radius-lg);
    width:       100%;
    max-width:   500px;
    max-height:  90vh;
    overflow-y:  auto;
    box-shadow:  var(--sm-shadow-lg);
    animation:   sm-modal-in .24s cubic-bezier(.34,1.56,.64,1);
}
@keyframes sm-modal-in {
    from { opacity: 0; transform: scale(.92) translateY(20px); }
    to   { opacity: 1; transform: scale(1)   translateY(0); }
}

.sm-modal-header {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    padding:         22px 22px 0;
}
.sm-modal-header h3 { font-size: 17px; font-weight: 700; }

.sm-modal-close {
    background:    none;
    border:        none;
    cursor:        pointer;
    color:         var(--sm-muted);
    padding:       4px;
    border-radius: var(--sm-radius-sm);
    display:       flex;
    align-items:   center;
    transition:    color var(--sm-ease), background var(--sm-ease);
}
.sm-modal-close:hover { color: var(--sm-text); background: var(--sm-bg); }

.sm-modal-body {
    padding: 18px 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.sm-form-group { display: flex; flex-direction: column; gap: 5px; }
.sm-form-group label {
    font-size:   13px;
    font-weight: 600;
    color:       var(--sm-text);
}
.sm-form-group input,
.sm-form-group textarea {
    padding:       9px 11px;
    border:        1.5px solid var(--sm-border);
    border-radius: var(--sm-radius-sm);
    font-size:     14px;
    font-family:   var(--sm-font);
    outline:       none;
    resize:        vertical;
    transition:    border-color var(--sm-ease), box-shadow var(--sm-ease);
    color:         var(--sm-text);
    background:    var(--sm-surface);
}
.sm-form-group input:focus,
.sm-form-group textarea:focus {
    border-color: var(--sm-primary);
    box-shadow:   0 0 0 3px var(--sm-primary-bg);
}

.sm-modal-footer {
    padding:         0 22px 22px;
    display:         flex;
    justify-content: flex-end;
    gap:             10px;
}

/* ── Confirm dialog ─────────────────────────────────────────────────────── */
.sm-confirm {
    background:    var(--sm-surface);
    border-radius: var(--sm-radius-lg);
    padding:       32px 28px;
    width:         100%;
    max-width:     360px;
    box-shadow:    var(--sm-shadow-lg);
    text-align:    center;
    animation:     sm-modal-in .24s cubic-bezier(.34,1.56,.64,1);
}
.sm-confirm-icon {
    width:           52px;
    height:          52px;
    background:      var(--sm-danger-bg);
    border-radius:   50%;
    display:         flex;
    align-items:     center;
    justify-content: center;
    margin:          0 auto 16px;
    color:           var(--sm-danger);
}
.sm-confirm h3  { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.sm-confirm p   { color: var(--sm-muted); font-size: 14px; margin-bottom: 22px; }
.sm-confirm-btns { display: flex; gap: 10px; justify-content: center; }

/* ── Toast notifications ────────────────────────────────────────────────── */
.sm-toasts {
    position:       fixed;
    bottom:         24px;
    right:          24px;
    z-index:        999999;
    display:        flex;
    flex-direction: column;
    gap:            8px;
    pointer-events: none;
}
.sm-toast {
    display:       flex;
    align-items:   center;
    gap:           8px;
    padding:       11px 16px;
    border-radius: 10px;
    font-size:     14px;
    font-weight:   600;
    font-family:   var(--sm-font, sans-serif);
    box-shadow:    var(--sm-shadow-lg);
    animation:     sm-toast-in .28s ease;
    transition:    opacity .25s, transform .25s;
    min-width:     210px;
}
@keyframes sm-toast-in {
    from { opacity: 0; transform: translateX(24px); }
    to   { opacity: 1; transform: translateX(0); }
}
.sm-toast.sm-toast-success { background: #1a7340; color: #fff; }
.sm-toast.sm-toast-error   { background: #9a1c1c; color: #fff; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .sm-wrapper        { padding: 16px; }
    .sm-header         { flex-direction: column; align-items: flex-start; }
    .sm-search input   { width: 100%; }
    .sm-grid           { grid-template-columns: 1fr; }
    .sm-modal          { max-width: 100%; max-height: 95vh; }
}
