/* =========================================
   1. IMPORT & VARIABLES
   ========================================= */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;600&display=swap');

:root {
    /* --- Colors (IBM Carbon Inspired) --- */
    --bg: #F4F4F4;
    --card: #FFFFFF;
    --text: #161616;
    --subtext: #525252;
    
    /* --- Brand & States --- */
    --primary: #0F62FE;
    --primary-hover: #0353E9;
    --danger: #DA1E28;
    
    /* Status Vibrantes */
    --status-pending: #8D8D8D;
    --status-bought: #0F62FE;
    --status-done: #198038;
    
    --warning: #F1C21B;
    
    /* --- UI Elements --- */
    --border: #E0E0E0;
    --input-bg: #F4F4F4;
    --overlay: rgba(22, 22, 22, 0.6);
    
    /* --- Dimensions --- */
    --header-height: 48px;
    --radius-sm: 4px;
}

[data-theme="dark"] {
    --bg: #161616;
    --card: #262626;
    --text: #F4F4F4;
    --subtext: #A8A8A8;
    --primary: #4589FF;
    --primary-hover: #78A9FF;
    --danger: #FA4D56;
    
    --status-pending: #6F6F6F;
    --status-bought: #4589FF;
    --status-done: #42BE65;
    
    --border: #393939;
    --input-bg: #393939;
    --overlay: rgba(0, 0, 0, 0.75);
}

/* =========================================
   2. RESET & BASE
   ========================================= */
* { 
    box-sizing: border-box; 
    outline: none; 
    -webkit-tap-highlight-color: transparent; 
}

body { 
    font-family: 'IBM Plex Sans', sans-serif; 
    background: var(--bg); 
    color: var(--text); 
    margin: 0; 
    display: flex; 
    flex-direction: column; 
    height: 100vh; 
    overflow: hidden; 
}

/* =========================================
   3. HEADER & NAVIGATION
   ========================================= */
header { 
    padding: 16px 16px 0; 
    background: var(--bg); 
    z-index: 10; 
    flex-shrink: 0; 
}

.top-bar { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 24px; 
    height: var(--header-height); 
}

h1 { 
    margin: 0; 
    font-size: 20px; 
    font-weight: 600; 
    letter-spacing: 0.5px;
}

.top-actions { display: flex; gap: 4px; }

.btn-icon { 
    background: transparent; 
    border: 1px solid transparent; 
    width: 48px; height: 48px; 
    font-size: 20px; 
    color: var(--text); 
    cursor: pointer; 
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}
.btn-icon:hover { background: var(--border); }

/* --- Search Box --- */
.search-box { position: relative; margin-bottom: 16px; }

.search-box i { 
    position: absolute; 
    left: 16px; 
    top: 50%; 
    transform: translateY(-50%); 
    color: var(--subtext); 
    font-size: 16px; 
}

.search-box input { 
    width: 100%; height: 48px; 
    padding: 0 16px 0 48px; 
    background: var(--card); 
    border: none; 
    border-bottom: 1px solid var(--subtext); 
    font-family: 'IBM Plex Sans', sans-serif; 
    font-size: 16px; 
    color: var(--text); 
    transition: border 0.2s;
}
.search-box input:focus { border-bottom: 2px solid var(--primary); }

/* --- Tabs --- */
.categories { 
    display: flex; 
    overflow-x: auto; 
    scrollbar-width: none; 
    border-bottom: 1px solid var(--border); 
}
.categories::-webkit-scrollbar { display: none; }

.tab { 
    padding: 12px 16px; 
    background: transparent; 
    border: none; 
    font-family: 'IBM Plex Sans', sans-serif; 
    font-size: 14px; 
    color: var(--subtext); 
    cursor: pointer; 
    white-space: nowrap; 
    border-bottom: 3px solid transparent; 
    transition: color 0.2s;
}

.tab.active { 
    color: var(--primary); 
    font-weight: 600; 
    border-bottom: 3px solid var(--primary); 
}

/* =========================================
   4. MAIN LIST & ITEMS
   ========================================= */
main { 
    flex: 1; 
    overflow-y: auto; 
    padding: 16px; 
    background: var(--bg); 
}

.list-group { list-style: none; padding: 0; margin: 0; }

.empty-state { 
    text-align: center; 
    color: var(--subtext); 
    margin-top: 60px; 
    font-size: 14px; 
    padding: 20px; 
    line-height: 1.5;
}

/* --- Item Card Design --- */
.item-card { 
    background: var(--card); 
    padding: 12px 16px; 
    margin-bottom: 4px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    transition: all 0.2s ease; 
    position: relative;
    border: 1px solid transparent;
}

.item-card:hover { 
    background: var(--input-bg);
    transform: translateX(2px);
}

/* STATUS INDICATORS */
.item-card[data-status="pendente"] { border-left: 6px solid var(--status-pending); }
.item-card[data-status="comprado"] { border-left: 6px solid var(--status-bought); }
.item-card[data-status="entregue"] { border-left: 6px solid var(--status-done); opacity: 0.7; }

/* Content Layout */
.item-content { display: flex; align-items: center; gap: 16px; flex: 1; }

.item-thumb { 
    width: 48px; height: 48px; 
    border-radius: var(--radius-sm); 
    background: var(--input-bg); 
    object-fit: cover; 
    border: 1px solid var(--border);
}

.item-info { flex: 1; }
.item-info strong { display: block; font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.item-info span { font-size: 13px; color: var(--subtext); display: flex; align-items: center; gap: 6px; }

.low-stock-warning { 
    color: var(--danger); 
    font-weight: 700; 
    font-size: 11px; 
    text-transform: uppercase; 
    background: rgba(218, 30, 40, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
}

.item-actions { display: flex; gap: 0; }
.btn-edit-item, .handle-item { 
    color: var(--text); 
    background: transparent; 
    border: none; 
    width: 48px; height: 48px; 
    display: flex; align-items: center; justify-content: center; 
    cursor: pointer; font-size: 20px; 
}
.handle-item { cursor: grab; color: var(--subtext); }

/* =========================================
   5. MODALS & FORMS (Fix: Background & Scroll)
   ========================================= */
.modal { 
    display: none; 
    position: fixed; 
    inset: 0; 
    background: var(--overlay); 
    z-index: 100; 
    align-items: center; 
    justify-content: center; 
    backdrop-filter: blur(2px);
    padding: 16px; /* Evita que o modal cole nas bordas */
}

.modal-content { 
    background-color: var(--card); /* Garantindo que não fique transparente */
    width: 100%; 
    max-width: 400px; 
    padding: 0; 
    box-shadow: 0 12px 32px rgba(0,0,0,0.15); 
    display: flex; 
    flex-direction: column; 
    border: 1px solid var(--border);
    
    /* Scroll no Mobile */
    max-height: 90vh; /* Máximo 90% da tela */
    overflow-y: auto; /* Scroll vertical se precisar */
    -webkit-overflow-scrolling: touch; /* Scroll suave iOS */
    border-radius: 4px; /* Opcional, mas ajuda no visual */
}

.modal-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 16px 24px; 
    background: var(--bg); 
    border-bottom: 1px solid var(--border);
    flex-shrink: 0; /* Header não encolhe no scroll */
}

.modal-header h2 { margin: 0; font-size: 16px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }

.btn-close-x { 
    background: transparent; border: none; 
    font-size: 24px; color: var(--text); 
    padding: 4px; cursor: pointer; 
}

/* --- Form Elements --- */
.modal-content label { 
    display: block; 
    font-size: 12px; 
    font-weight: 600;
    color: var(--subtext); 
    margin: 20px 24px 8px; 
    text-transform: uppercase;
}

/* Inputs Padrão */
.modal-content input, .modal-content select { 
    width: calc(100% - 48px); 
    margin: 0 24px; 
    height: 48px; 
    padding: 0 16px; 
    background: var(--bg); 
    border: none; 
    border-bottom: 1px solid var(--subtext); 
    color: var(--text); 
    font-family: 'IBM Plex Sans', sans-serif; 
    font-size: 16px; 
    border-radius: 0; 
    transition: border-bottom 0.2s;
}

.modal-content input:focus, .modal-content select:focus { 
    border-bottom: 2px solid var(--primary); 
}

/* --- Inputs Lado a Lado --- */
.row-inputs { 
    display: flex; 
    gap: 16px; 
    padding: 0 24px; 
    margin-top: 0; 
}

.row-inputs > div { 
    flex: 1; 
    display: flex;
    flex-direction: column;
}

.row-inputs label { margin: 20px 0 8px; }
.row-inputs input { width: 100%; margin: 0; }

/* --- Photo Area (Ajustado Altura) --- */
.photo-upload-area { 
    height: 140px; 
    background: var(--input-bg); 
    display: flex; align-items: center; justify-content: center; 
    margin: 0; 
    cursor: pointer; 
    border-bottom: 1px solid var(--border);
    position: relative; 
    overflow: hidden; 
    flex-shrink: 0;
}
.photo-upload-area img { width: 100%; height: 100%; object-fit: cover; }
#placeholderFoto { display: flex; flex-direction: column; align-items: center; color: var(--subtext); gap: 8px; font-size: 13px; font-weight: 500; }
#placeholderFoto i { font-size: 32px; color: var(--primary); }

/* --- Status Selector --- */
.status-selector { display: flex; margin: 0 24px; gap: 0; border: 1px solid var(--border); }

.status-btn { 
    flex: 1; 
    padding: 12px; 
    border: none; 
    background: var(--card); 
    color: var(--subtext); 
    cursor: pointer; 
    font-size: 12px; 
    font-weight: 600; 
    text-transform: uppercase;
    border-right: 1px solid var(--border);
    transition: 0.2s;
}
.status-btn:last-child { border-right: none; }

.status-btn.active { 
    background: var(--color); 
    color: #fff; 
}

/* --- Modal Actions --- */
.modal-buttons { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 1px; 
    margin-top: 32px; 
    background: var(--border); 
    border-top: 1px solid var(--border); 
}

.btn-confirm, .btn-cancel { 
    border: none; 
    padding: 24px 0; 
    font-family: 'IBM Plex Sans', sans-serif; 
    font-size: 14px; 
    font-weight: 600;
    text-transform: uppercase;
    cursor: pointer; 
    width: 100%; 
}
.btn-confirm { background: var(--primary); color: #fff; }
.btn-cancel { background: var(--card); color: var(--text); }

#btnExcluirItem { 
    width: 100%; 
    padding: 24px 0; 
    background: var(--danger); 
    color: white; 
    border: none; 
    font-family: 'IBM Plex Sans', sans-serif; 
    font-size: 14px; 
    font-weight: 600;
    text-transform: uppercase;
    cursor: pointer; 
    display: block; 
}

/* =========================================
   6. FOOTER & FAB
   ========================================= */
.actions-footer { 
    position: fixed; bottom: 0; left: 0; right: 0; 
    background: var(--card); 
    padding: 0; 
    display: flex; 
    z-index: 50; 
    border-top: 1px solid var(--border); 
}

.btn-action { 
    flex: 1; border: none; 
    padding: 24px 16px; 
    font-family: 'IBM Plex Sans', sans-serif; 
    font-weight: 600; 
    font-size: 13px; 
    cursor: pointer; 
    display: flex; align-items: center; justify-content: center; gap: 8px; 
    text-transform: uppercase; 
    letter-spacing: 0.5px;
}
.btn-save { background: var(--text); color: var(--bg); }
.btn-load { background: var(--card); color: var(--text); border-right: 1px solid var(--border); }

.fab { 
    position: fixed; bottom: 90px; right: 24px; 
    width: 64px; height: 64px; 
    background: var(--primary); 
    color: #fff; 
    border: none; 
    font-size: 32px; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.3); 
    cursor: pointer; 
    z-index: 5; 
    display: flex; align-items: center; justify-content: center; 
    transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.fab:active { transform: scale(0.9); }

/* =========================================
   7. CATEGORY MANAGEMENT
   ========================================= */
.hint { padding: 0 24px; margin-bottom: 16px; color: var(--subtext); font-size: 13px; }

.add-cat-row { 
    display: flex; gap: 0; 
    margin-bottom: 24px; 
    border: 1px solid var(--subtext); 
    margin: 16px 24px;
}
.add-cat-row input { 
    flex: 1; border: none; padding: 0 16px; height: 48px; 
    background: var(--bg); color: var(--text); 
    margin: 0; width: auto; 
}
.btn-small-add { 
    width: 48px; height: 48px; 
    background: var(--primary); color: #fff; 
    border: none; cursor: pointer; font-size: 24px; 
    display: flex; align-items: center; justify-content: center; 
}

.list-group-edit { list-style: none; padding: 0; max-height: 50vh; overflow-y: auto; }

.cat-edit-row { 
    display: flex; align-items: center; 
    background: var(--card); 
    border-bottom: 1px solid var(--border); 
    padding: 0; 
}
.cat-edit-row input { 
    flex: 1; border: none; background: transparent; 
    color: var(--text); height: 48px; padding-left: 12px; 
    margin: 0; width: auto;
    font-weight: 500;
}
.cat-actions { display: flex; }

.btn-del-cat { 
    width: 48px; height: 48px; 
    display: flex; align-items: center; justify-content: center; 
    background: transparent; border: none; 
    color: var(--danger); font-size: 20px; 
    cursor: pointer; transition: background 0.2s;
}
.btn-del-cat:hover { background: rgba(218, 30, 40, 0.1); }

.handle-cat { 
    width: 48px; height: 48px; 
    display: flex; align-items: center; justify-content: center;
    color: var(--subtext); cursor: grab; font-size: 18px;
}