:root {
    --primary: #4677f2;
    --primary-hover: #355ecb;
    --bg-main: #f8fafc;
    --bg-sidebar: #0f172a;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow: hidden;
    /* App container will handle scroll */
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    color: white;
    display: flex;
    flex-direction: column;
    padding: 2rem 1rem;
    flex-shrink: 0;
    transition: width 0.3s ease, padding 0.3s ease;
    position: relative;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 85px;
    padding: 2rem 1rem;
}

.brand {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    margin-bottom: 3rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.25rem;
    position: relative;
}

.brand-main {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.brand-text {
    display: flex;
    flex-direction: column;
    transition: opacity 0.2s ease;
    white-space: nowrap;
}

.sidebar.collapsed .brand-text {
    opacity: 0;
    pointer-events: none;
}

.sidebar-toggle-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    width: 30px;
    /* Sedikit lebih kecil */
    height: 30px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    margin-right: 5px;
    /* Ruang napas dari tepi */
}

.sidebar-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
    border-color: rgba(255, 255, 255, 0.2);
}

.sidebar.collapsed .sidebar-toggle-btn {
    margin: 0 auto;
}

.sidebar.collapsed .brand {
    justify-content: center;
    padding: 0;
}

.sidebar.collapsed .brand-main {
    display: none;
}

.toggle-icon {
    display: inline-block;
}

.brand-icon {
    background: var(--primary);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 0.9rem;
}

.side-nav {
    flex-grow: 1;
}

.nav-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    color: #94a3b8;
    text-align: left;
    cursor: pointer;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    transition: all 0.2s;
    font-size: 0.95rem;
    white-space: nowrap;
}

.nav-text {
    transition: opacity 0.2s ease;
}

.sidebar.collapsed .nav-text {
    opacity: 0;
    pointer-events: none;
    width: 0;
    overflow: hidden;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 0.75rem 0;
    gap: 0;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.nav-item.active {
    background: var(--primary);
}

.sidebar-footer {
    font-size: 0.8rem;
    color: #475569;
    transition: opacity 0.2s ease;
    white-space: nowrap;
}

.sidebar.collapsed .sidebar-footer {
    opacity: 0;
    pointer-events: none;
}

/* Main Content */
.main-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 2rem;
    height: 100vh;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.top-bar h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.75rem;
    font-weight: 700;
}

.actions {
    display: flex;
    gap: 1rem;
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-outline {
    background: white;
    border-color: var(--border);
    color: var(--text-main);
}

.btn-outline:hover {
    background-color: #f1f5f9;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

/* Editor Grid */
.editor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: start;
}

/* Panels */
.input-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-body {
    padding: 1.5rem;
}

.card-body.no-padding {
    padding: 0;
}

/* Form Elements */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

input,
textarea,
select {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    color: var(--text-main);
    transition: all 0.2s;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

input[type="file"] {
    padding: 0.5rem;
    font-size: 0.8rem;
    background: #f8fafc;
    cursor: pointer;
}

input[type="file"]::-webkit-file-upload-button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    margin-right: 10px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* Items Table Editor */
.items-editor-table {
    width: 100%;
    border-collapse: collapse;
}

.items-editor-table th {
    background: #f8fafc;
    text-align: left;
    padding: 1rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.items-editor-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.item-row input {
    padding: 0.6rem 0.8rem;
    font-size: 0.9em;
}

.btn-delete {
    background: #fee2e2;
    color: #dc2626;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: 0.2s;
}

.btn-delete:hover {
    background: #fecaca;
}

/* Preview Panel */
.preview-panel {
    position: sticky;
    top: 0;
}

.invoice-paper {
    background: white;
    width: 100%;
    height: auto;
    min-height: 200mm;
    padding: 25px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    color: #1e293b;
    font-size: 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 50px;
}

.label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 10px;
}

.company-brand {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.preview-logo {
    max-width: 220px;
    max-height: 100px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
}

.from-section h3,
.to-section h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
    color: #000;
}

.from-section p,
.to-section p {
    font-size: 1.1rem;
    color: #000;
    line-height: 1.5;
}

.invoice-meta {
    text-align: right;
}

.invoice-meta h1 {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 2.5rem;
    color: var(--primary);
    margin-bottom: 15px;
}

.meta-item {
    margin-bottom: 6px;
    color: #000;
}

.meta-item strong {
    color: #000;
    margin-left: 10px;
}

.preview-subheader {
    margin-bottom: 40px;
    border-top: 1.5px solid #000;
    padding-top: 20px;
}

.to-section h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.to-section p {
    color: #000;
    line-height: 1.5;
}

/* Preview Table */
.preview-items {
    margin-bottom: 40px;
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
}

.preview-table th {
    text-align: center;
    padding: 15px;
    background: #3c4858;
    color: white;
    font-weight: 700;
    font-size: 13px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.preview-table th:last-child {
    border-right: none;
}

.preview-table td {
    padding: 15px;
    background: #e9ebf0;
    border-right: 1px solid white;
    color: #444;
}

.preview-table td:last-child {
    border-right: none;
}

.preview-table tr {
    border-bottom: 4px solid white;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.item-desc {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Totals */
.preview-totals {
    display: flex;
    justify-content: flex-end;
}

.totals-wrapper {
    width: 250px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.grand-total {
    border-bottom: none;
    padding-top: 15px;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary);
}

/* Footer preview */
.preview-footer {
    margin-top: 60px;
}

.flex-items-end {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.signature-section {
    min-width: 200px;
    text-align: center;
}

.sig-image-container {
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 10px 0;
}

.notes-box {
    background: #f8fafc;
    padding: 20px;
    border-radius: 8px;
    width: 60%;
}

/* Responsive */
@media (max-width: 1200px) {
    .editor-grid {
        grid-template-columns: 1fr;
    }
}

@media print {

    .sidebar,
    .top-bar,
    .input-panel {
        display: none !important;
    }

    .main-content {
        padding: 0;
        overflow: visible;
    }

    .preview-panel {
        position: static;
    }

    .invoice-paper {
        box-shadow: none;
        padding: 0;
        height: auto !important;
        min-height: 0 !important;
    }
}

/* History View Styles */
.btn-delete {
    background: #fee2e2;
    color: #ef4444;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-delete:hover {
    background: #ef4444;
    color: white;
}

#history-view {
    padding-bottom: 50px;
}

#history-view table {
    width: 100%;
}

#history-view .btn-sm {
    padding: 8px 16px;
    font-size: 0.85rem;
    margin-left: 8px;
    border-radius: 6px;
}

.no-padding {
    padding: 0 !important;
}

#history-list-body tr:hover td {
    background: #f8fafc;
}

/* Rich Text Utility Styles */
.item-desc b,
.pv-notes b {
    font-weight: bold;
}

.item-desc i,
.pv-notes i {
    font-style: italic;
}

.item-desc u,
.pv-notes u {
    text-decoration: underline;
}

.item-desc font[color],
.pv-notes font[color] {
    color: inherit;
}

/* Rich Text Editor Styling */
.rich-text-input {
    min-height: 1.2rem;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    font-size: 0.95rem;
    color: var(--text-main);
    transition: all 0.2s;
    overflow-y: auto;
}

.rich-text-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(70, 119, 242, 0.1);
}

.toolbar {
    margin-bottom: 8px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.toolbar button {
    padding: 4px 10px;
    font-size: 0.85rem;
    cursor: pointer;
    border: 1px solid var(--border);
    background: white;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
}

.toolbar button:hover {
    background: #f1f5f9;
    border-color: var(--primary);
}

.toolbar input[type="color"] {
    border: 1px solid var(--border);
    padding: 0;
    width: 32px;
    height: 32px;
    cursor: pointer;
    border-radius: 6px;
    background: white;
}

/* Ensure preview respects the formatted content */
.item-desc,
#pv-notes {
    white-space: pre-wrap;
    word-break: break-word;
}