:root {
    --bg-dark: #0d111a;
    --bg-card: #161b29;
    --bg-popup: #1b2030;
    --text-primary: #e6eef8;
    --text-muted: #8a93a9;
    --accent: #7dd3fc;
    --danger: #ff6b6b;
    --border: rgba(125,211,252,0.2);
}

/* Global */
* { box-sizing: border-box; outline: none; }
html,body { height:100%; margin:0; font-family: Inter, Arial, sans-serif; background:var(--bg-dark); color:var(--text-primary); padding:20px; }
.container { max-width:1000px; margin:auto; }

/* Title */
h1 {
    text-align:center;
    font-size:36px;
    margin-bottom:25px;
    color:var(--text-primary);
    user-select: none;
    cursor: default;
}

/* Search Row */
.search-row { display:flex; justify-content:center; align-items:center; gap:12px; margin-bottom:20px; }
#search, #calc-search, #calc-amount {
    flex:1; padding:14px 22px; border-radius:12px; border:1px solid var(--border);
    background:var(--bg-card); color:var(--text-primary); font-size:18px;
}
#search:focus, #calc-search:focus, #calc-amount:focus { border-color:var(--accent); box-shadow:0 0 8px rgba(125,211,252,0.3); }

.category-dropdown { padding:14px 18px; border-radius:12px; border:1px solid var(--border); background:var(--bg-card); color:var(--text-primary); font-size:18px; outline:none; transition:0.2s; }

.calc-button {
    background:var(--bg-card); border:1px solid var(--border); border-radius:50%; width:50px; height:50px;
    color:var(--text-primary); font-size:20px; cursor:pointer; transition:0.2s;
}
.calc-button:hover { border-color:var(--accent); background: rgba(125,211,252,0.1); }

/* Item card */
.item-card {
    background: var(--bg-card); padding:20px; margin:12px auto; width:90%; border-radius:15px;
    font-size:22px; cursor:pointer; border:1px solid var(--border); transition: transform 0.25s ease, box-shadow 0.25s ease;
    position: relative; overflow: hidden;
}
.item-card::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg, rgba(125,211,252,0.05), transparent);
    opacity: 0;
    transition: opacity 0.25s ease;
}
.item-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.45);
}
.item-card:hover::after { opacity: 1; }

/* Popup base for item and calc */
#item-page, #calc-page {
    position:fixed; inset:0; display:flex; justify-content:center; align-items:center;
    background: rgba(13,17,26,0.95); opacity:0; pointer-events:none; transition:opacity 0.25s; z-index:999;
}
#item-page.show, #calc-page.show { opacity:1; pointer-events:auto; animation: fadeIn 0.25s ease forwards; }
#page-content, #calc-content {
    background:var(--bg-popup); padding:40px; width:90%; max-width:600px; border-radius:20px; text-align:left;
    max-height:85%; overflow-y:auto; overflow-x:hidden; transform:translateY(-20px) scale(0.9); opacity:0;
    transition: transform 0.25s ease, opacity 0.25s ease; width: 90%; max-width: 1000px;
}
#item-page.show #page-content, #calc-page.show #calc-content {
    transform: translateY(0) scale(1);
    opacity:1;
    animation: popupScale 0.25s forwards;
}

/* Close */
#close-page, #close-calc { background:none; border:none; color:var(--text-primary); font-size:28px; float:right; cursor:pointer; transition: color 0.2s ease; }
#close-page:hover, #close-calc:hover { color: var(--accent); }

/* Popup contents */
.popup-body { display:flex; gap:30px; flex-wrap:wrap; }
.stats { flex:1; min-width:180px; background:rgba(255,255,255,0.02); padding:20px; border-radius:15px; }
.materials-section { flex:1; min-width:220px; margin-top:20px; }
.materials-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 3 columns side by side */
    gap: 12px;
}
.materials-grid p {
    background:#1f2536; padding:10px 14px; border-radius:12px; text-align:center; font-weight:500; border:1px solid var(--border); color:var(--text-primary);
    transition: background 0.2s ease, transform 0.2s ease;
}
.materials-grid p:hover { background: #2c3352; transform: translateY(-2px); }

/* Calculator list */
#calc-results { margin-top:10px; max-height:180px; overflow-y:auto; display:flex; flex-direction:column; gap:5px; }
.calc-result-item { background:#1b2030; padding:10px; border-radius:12px; cursor:pointer; text-align:center; border:1px solid var(--border); transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease; }
.calc-result-item:hover { transform: translateX(3px); background:#2a3150; border-color:var(--accent); }

/* Highlight */
mark { background-color:var(--accent); color:black; border-radius:3px; padding:0 2px; }

/* ========== ADMIN STYLES (fixed layout) ========== */
header{ display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:12px; }
.controls{ display:flex; align-items:center; gap:8px; }
.controls input{ padding:10px 14px; border-radius:10px; border:1px solid var(--border); background:var(--bg-card); color:var(--text-primary); min-width:240px; font-size:16px; }
.btn{ background:var(--accent); border:none; padding:10px 14px; border-radius:10px; cursor:pointer; color:#041017; font-weight:600; transition: all 0.18s ease; }
.btn.small{ padding:6px 8px; font-size:13px; }
.btn.danger{ background:var(--danger); color:white; }

/* ADMIN OVERLAY - FULLSCREEN */
#admin-page {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: flex-start;
    align-items: stretch;
    background: rgba(13,17,26,0.96);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
    z-index: 9999;
    padding: 0;
}
#admin-page.show { opacity:1; pointer-events:auto; animation: slideDown 0.3s ease forwards; }

/* admin content now single column - grid area only */
#admin-content {
    background: var(--bg-popup);
    padding: 20px;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    border-radius: 0;
    display: block; /* single column */
}

/* grid area (now full width) */
#gridArea {
    padding: 8px;
    overflow-y: auto;
    height: calc(100vh - 56px);
}

/* responsive item grid */
.item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
    padding: 14px;
    overflow-y: auto;
}

/* item cell */
.item{
    background:var(--bg-card); border:1px solid var(--border); border-radius:14px; height:110px;
    display:flex; align-items:center; justify-content:center; text-align:center; padding:12px; font-weight:600; color:var(--text-primary);
    cursor:pointer; transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.item:hover { transform: translateY(-3px); box-shadow: 0 4px 14px rgba(0,0,0,0.35); border-color: var(--accent); }
.item .meta{ font-size:13px; color:var(--text-muted); margin-top:6px; display:block; }

/* NOTE: Editor moved to modal; keep .editor styles for material rows */
.editor {
    background: rgba(255,255,255,0.03);
    padding: 18px;
    overflow-y: auto;
    border-left: 1px solid var(--border);
    border-radius: 0;
}

/* form fields */
.lab{ display:block; color:var(--text-muted); margin-top:12px; margin-bottom:6px; font-size:13px; }
.short{ width:100%; padding:10px 14px; border-radius:10px; border:1px solid var(--border); background:var(--bg-card); color:var(--text-primary); font-size:15px; }
.checkbox-row{ display:flex; gap:12px; margin-top:8px; }
.matItem{
    display:flex; gap:10px; align-items:center; padding:10px; border-radius:10px; background:rgba(255,255,255,0.03); border:1px solid var(--border);
    transition: background 0.18s ease, transform 0.18s ease;
}
.matItem:hover { background: rgba(125,211,252,0.05); transform: translateX(2px); }
.matItem .name{ flex:1; color:var(--text-muted); }
.matItem input{ width:84px; padding:8px; border-radius:8px; background:var(--bg-card); border:1px solid var(--border); color:var(--text-primary); }

.actions{ display:flex; gap:10px; justify-content:flex-end; margin-top:16px; }

/* ========== EDITOR MODAL STYLES ========== */
#editor-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 20000;
}
#editor-modal.show {
    display: flex;
}
#editor-box {
    background: var(--bg-popup);
    width: 92%;
    max-width: 520px;
    padding: 26px;
    border-radius: 14px;
    max-height: 86%;
    overflow-y: auto;
    position: relative;
    transform: translateY(-20px) scale(0.9);
    opacity: 0;
    transition: transform 0.18s ease, opacity 0.18s ease;
}
#editor-modal.show #editor-box { transform: translateY(0) scale(1); opacity: 1; animation: modalFade 0.25s ease forwards; }

#editor-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 28px;
    cursor: pointer;
    transition: color 0.2s ease, transform 0.2s ease;
}

/* responsive tweaks */
@media (max-width:1200px){ .item-grid { grid-template-columns: repeat(4,1fr); } }
@media (max-width:850px){ 
    .item-grid { grid-template-columns: repeat(2,1fr); }
    #page-content, #calc-content { width:95%; padding:28px; }
    .materials-grid { grid-template-columns: repeat(auto-fill,minmax(100px,1fr)); }
}

/* small helpers */
.hidden{ display:none !important; }

/* ===== ANIMATIONS ===== */
@keyframes fadeIn { 0%{opacity:0;} 100%{opacity:1;} }
@keyframes popupScale { 0%{transform:translateY(-20px) scale(0.9); opacity:0;} 100%{transform:translateY(0) scale(1); opacity:1;} }
@keyframes slideDown { 0%{transform:translateY(-100%); opacity:0;} 100%{transform:translateY(0); opacity:1;} }
@keyframes modalFade { 0%{opacity:0; transform:translateY(-20px) scale(0.9);} 100%{opacity:1; transform:translateY(0) scale(1);} }

.category-dropdown {
    cursor: pointer; /* makes it look like a hand */
}

/* Password Modal */
#password-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 420px; /* wider modal */
    background: var(--bg-popup);
    color: var(--text-primary);
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
    display: none;
    z-index: 1000;
}
#password-modal.show { display: block; }

#password-modal input[type="password"] {
    width: 100%;
    padding: 10px;
    margin-bottom: 20px;
    border-radius: 6px;
    border: 1px solid var(--text-muted);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 16px;
}

#password-modal .modal-buttons {
    display: flex;
    justify-content: flex-end; /* push buttons to right */
    gap: 10px; /* space between buttons */
}
#password-modal .modal-buttons button {
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    border: none;
    background: var(--accent); /* blue background */
    color: var(--bg-dark); /* text color */
}

#password-error {
    color: #f87171; /* red for error */
    margin-bottom: 10px;
    min-height: 18px;
    font-size: 14px;
}
