/* =========================
   🌿 Root Variables
========================= */
:root {
    --green: #16a34a;
    --green-dark: #15803d;
    --green-light: #10b981;
    --green-hover: #059669;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --blue: #2563eb;
    --blue-light: #dbeafe;
    --danger: #dc2626;
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --transition: 0.2s ease;
}

/* =========================
   🔹 Base Layout
========================= */
html,
body {
    height: 100%;
    margin: 0;
    background: var(--gray-200);
    display: flex;
    flex-direction: column;
    overflow: auto;
}

.main-container {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    overflow: auto;
}

.content-area {
    flex: 1;
    height: 100%;
    position: relative;
    overflow: auto;
}

.safe-top {
    padding-top: env(safe-area-inset-top);
    padding-top: constant(safe-area-inset-top);
}

/* =========================
   🔹 Tabs
========================= */
.tab-active {
    background: var(--green);
    color: white;
    border-bottom: 3px solid var(--green-dark);
}

.tab-inactive {
    background: #f1f5f9;
    color: var(--gray-600);
}

/* =========================
   🔹 Toast
========================= */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--green);
    color: white;
    padding: 10px 16px;
    border-radius: var(--radius-lg);
    display: none;
    z-index: 50;
}

/* =========================
   🔹 Header & Search Box
========================= */
.header-box {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 10px;
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    flex-wrap: nowrap;
    overflow: visible !important;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    width: calc(100% - 20px);
    margin: 10px;
    flex-wrap: nowrap;
}

/* Hide scrollbars for header/search */
.header-box::-webkit-scrollbar,
.search-box::-webkit-scrollbar {
    display: none;
}

.header-box,
.search-box {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* =========================
   🔹 Buttons
========================= */
.header-btn {
    background: #f1f5f9;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    padding: 4px;
    font-size: 0.95rem;
    flex-shrink: 0;
    white-space: nowrap;
    transition: var(--transition);
}

.header-btn:hover {
    background: #e2e8f0;
}

.clear-btn {
    flex: 1;
    max-width: 40px;
    text-align: center;
    padding: 8px 0;
    border: none;
    border-radius: var(--radius-md);
    background: var(--gray-100);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
}

.clear-btn:hover {
    background: #e2e8f0;
}

.btn-done {
    display: block;
    margin: 20px auto;
    padding: 10px 20px;
    background: var(--green-light);
    color: white;
    font-size: 1rem;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition);
}

.btn-done:hover {
    background: var(--green-hover);
}

/* =========================
   🔹 Inputs
========================= */
.index-input,
.search-input {
    padding: 8px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 1rem;
    flex-shrink: 1;
    transition: all 0.25s ease;
}

.index-input {
    flex: 2;
    max-width: 60px;
    text-align: center;
}

.search-input {
    flex: 8;
    min-width: 150px;
}

.push {
    margin-left: auto;
}

/* =========================
   🔹 Dropdown Menu
========================= */
.menu-wrapper {
    position: relative;
}

.menu-dropdown {
    display: none;
    position: absolute;
    left: 0;
    top: 100%;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    z-index: 9999;
    min-width: 180px;
    animation: fadeIn 0.15s ease-out;
}

.menu-item {
    display: block;
    width: 100%;
    padding: 8px 14px;
    font-size: 0.95rem;
    color: var(--gray-700);
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background var(--transition);
}

.menu-item:hover {
    background: var(--gray-100);
}

/* =========================
   🔹 History Popup
========================= */
#historyPopup,
#updatePopup,
#optionPopup {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.history-container,
.update-container,
.option-container {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 10px;
    width: 90%;
    height: 90%;
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
}

/* Header */
.history-header {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 8px;
}

.history-header h3 {
    margin: 0;
    font-weight: 600;
}

/* Scrollable Content */
.history-content {
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
}

.history-content::-webkit-scrollbar {
    width: 6px;
}

.history-content::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 4px;
}

/* Footer */
.history-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    border-top: 1px solid var(--gray-200);
    padding-top: 8px;
}

/* History Buttons */
.history-btn {
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.85rem;
    color: #fff;
    padding: 5px 10px;
    transition: opacity var(--transition);
}

.history-btn:hover {
    opacity: 0.85;
}

.history-btn.gray {
    background: var(--gray-400);
}

.history-btn.danger {
    background: var(--danger);
}

.history-btn.small {
    flex: 0 0 auto;
    min-width: 70px;
}

/* Back button */
.back-btn {
    font-size: 0.9rem;
    color: var(--blue);
    cursor: pointer;
    transition: opacity var(--transition);
}

.back-btn:hover {
    opacity: 0.7;
}

/* Checkbox */
.item-check {
    transform: scale(1.2);
    cursor: pointer;
    accent-color: var(--blue);
}

/* =========================
   🔹 Update / Option Popup
========================= */
.update-search {
    flex: auto;
    padding: 3px;
    font-size: 16px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
}

.update-list {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 2px;
}

.update-item-wrapper {
    background: var(--gray-50);
    border-radius: var(--radius-lg);
    padding: 5px;
    margin-bottom: 10px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.update-item {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto;
    align-items: center;
    gap: 5px;
    border-bottom: 1px solid var(--gray-100);
}

.update-item input {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.update-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 10px;
}

.btnAddItem {
    padding: 3px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    min-width: 70px;
    white-space: nowrap;
    font-size: 0.8rem;
}

.update-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--gray-200);
}

.update-btn {
    flex: 1;
    max-width: 80px;
    padding: 6px 10px;
    border: none;
    border-radius: var(--radius-md);
    color: #fff;
    cursor: pointer;
}

.update-btn.save {
    background: #4cae70;
}

.update-btn.cancel {
    background: #9b9b9d;
}

/* =========================
   🔹 Option Inline
========================= */
.option-inline {
    margin: 6px 0 10px 20px;
    border-left: 3px solid var(--blue-light);
    padding-left: 8px;
}

.option-inline .option-item {
    display: grid;
    grid-template-columns: minmax(40px, 100px) minmax(20px, 60px) 28px;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.option-inline .option-item input {
    padding: 4px 6px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.option-inline .option-item button {
    width: 24px;
    height: 24px;
    font-size: 0.7rem;
    border-radius: var(--radius-sm);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
}

.option-inline .add-option {
    background: #a5bcee;
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.8rem;
}

.option-btn.delete {
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    cursor: pointer;
}

/* =========================
   🔹 Animations
========================= */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.update-item-wrapper[style*="background: #fee2e2"] {
    transition: background 2s ease;
}

/* =========================
   🔹 Note Popup
========================= */
#notePopup {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    justify-content: center;
    align-items: center;
    z-index: 9999;
    animation: fadeIn 0.2s ease;
}

.note-container {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 10px;
    width: calc(100% - 40px);
    max-width: 480px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 10%;
    gap: 10px;
}

.note-container h3 {
    margin: 0;
    font-weight: 600;
}

#noteInput {
    width: calc(100% - 18px);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    padding: 8px;
    font-size: 1rem;
    resize: vertical;
    min-height: 120px;
    font-family: inherit;
}

.note-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.note-btn {
    padding: 6px 12px;
    border: none;
    border-radius: var(--radius-md);
    color: #fff;
    cursor: pointer;
    transition: opacity var(--transition);
}

.note-btn.save {
    background: var(--blue);
}

.note-btn.cancel {
    background: var(--gray-400);
}

.note-btn:hover {
    opacity: 0.85;
}
