:root {
--bg: #f4f5f7;
--surface: #ffffff;
--surface-soft: #f8fafc;
--border: #cbd5e1;
--border-light: #e2e8f0;
--text: #0f172a;
--text-soft: #475569;
--text-muted: #94a3b8;
--blue: #0052cc;
--blue-hover: #0065ff;
--blue-soft: #deebff;
--green: #166534;
--green-soft: #dcfce7;
--red: #de350b;
--red-hover: #ff5630;
--radius: 6px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
width: 100%;
height: 100%;
}

body {
font-family:
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
Roboto,
Helvetica,
Arial,
sans-serif;

background-color: var(--bg);
color: var(--text);
line-height: 1.3;


}

button,
input,
select {
font: inherit;
}

button {
cursor: pointer;
}

.hidden {
display: none !important;
}

/* APPLICATION */

.app {
display: flex;
height: 100vh;
overflow: hidden;
position: relative;
}

/* LEFT SIDEBAR */

.sidebar {
width: 270px;
background-color: var(--surface);
border-right: 1px solid var(--border);
display: flex;
flex-direction: column;
flex-shrink: 0;
z-index: 100;
transition: transform 0.25s ease-in-out;
height: 100%;
}

.sidebar-header {
padding: 10px 16px;
height: 57px;
border-bottom: 1px solid var(--border);
display: flex;
align-items: center;
}

.brand {
display: flex;
align-items: center;
gap: 10px;
}

.brand-mark {
width: 32px;
height: 32px;
background-color: var(--green-soft);
color: var(--green);
display: flex;
align-items: center;
justify-content: center;
border-radius: 6px;
font-size: 18px;
}

.brand-title {
font-weight: 700;
font-size: 15px;
color: var(--text);
line-height: 1.1;
}

.brand-title span {
font-size: 11px;
font-weight: 400;
color: #64748b;
display: block;
}

.sidebar-content {
flex: 1;
overflow-y: auto;
padding: 12px;
}

/* CATEGORY TREE */

.category-block {
margin-bottom: 10px;
border-radius: 6px;
padding: 4px;
transition: background-color 0.2s, border-color 0.2s;
border: 1.5px solid transparent;
}

.category-block.drag-over {
background-color: #e2e8f0;
border-color: var(--blue);
border-style: dashed;
}

.category-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 4px 0;
}

.category-name {
font-weight: 700;
font-size: 12px;
color: #1e293b;
text-transform: uppercase;
letter-spacing: 0.5px;
}

.btn-delete-cat {
background: none;
border: none;
color: #ef4444;
font-size: 11px;
cursor: pointer;
padding: 2px 4px;
border-radius: 4px;
display: none;
}

.category-header:hover .btn-delete-cat {
display: inline-block;
}

.sidebar-tree-list {
position: relative;
margin-left: 6px;
padding-left: 10px;
border-left: 1.5px dashed #94a3b8;
min-height: 24px;
}

.sidebar-tree-item {
position: relative;
display: flex;
align-items: center;
padding: 5px 8px;
margin: 2px 0;
border-radius: 4px;
font-size: 13px;
color: var(--text);
cursor: grab;
background-color: var(--surface);
border: 1px solid transparent;
}

.sidebar-tree-item:active {
cursor: grabbing;
}

.sidebar-tree-item::before {
content: "";
position: absolute;
left: -10px;
top: 50%;
width: 8px;
height: 1px;
border-top: 1.5px dashed #94a3b8;
}

.sidebar-tree-item:hover {
background-color: #f1f5f9;
border-color: var(--border);
}

.sidebar-tree-item.active {
background-color: var(--blue-soft);
color: var(--blue);
font-weight: 600;
border-color: #93c5fd;
}

.sidebar-tree-title {
color: inherit;
text-decoration: none;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
width: 100%;
}

/* MAIN */

.main {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
min-width: 0;
}

/* TOP BAR */

.topbar {
background-color: var(--surface);
border-bottom: 1px solid var(--border);
padding: 10px 16px;
min-height: 57px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}

.topbar-left {
display: flex;
align-items: center;
gap: 12px;
flex: 1;
min-width: 200px;
}

.menu-toggle {
display: none;
background: none;
border: 1px solid var(--border);
font-size: 16px;
padding: 4px 8px;
border-radius: 4px;
cursor: pointer;
color: var(--text);
}

.search-wrapper {
flex: 1;
position: relative;
width: 100%;
}

.search-input {
width: 100%;
padding: 6px 10px;
border: 1px solid var(--border);
border-radius: 4px;
font-size: 13px;
outline: none;
background: #fff;
color: var(--text);
}

.search-input:focus {
border-color: var(--blue);
box-shadow: 0 0 0 1px var(--blue);
}

.topbar-actions {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: nowrap;
}

/* BUTTONS */

.btn {
padding: 6px 12px;
min-height: 32px;
font-size: 12px;
border-radius: 4px;
border: 1px solid var(--border);
background-color: #fff;
color: var(--text);
cursor: pointer;
font-weight: 600;
transition:
background-color 0.15s,
border-color 0.15s,
color 0.15s;
white-space: nowrap;
}

.btn:hover {
background-color: #f1f5f9;
}

.btn-primary {
background-color: var(--blue);
color: #fff;
border-color: var(--blue);
}

.btn-primary:hover {
background-color: var(--blue-hover);
border-color: var(--blue-hover);
}

.btn-danger {
background-color: var(--red);
color: #fff;
border-color: var(--red);
}

.btn-danger:hover {
background-color: var(--red-hover);
border-color: var(--red-hover);
}

.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}

/* CONTENT */

.content-area {
flex: 1;
display: flex;
overflow: hidden;
}

.workspace-center {
flex: 1;
padding: 16px;
overflow-y: auto;
min-width: 0;
}

.grid-workspace {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 12px;
align-items: start;
}

/* TREEVIEW CARDS */

.accordion-card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
overflow: hidden;
transition:
box-shadow 0.2s,
border-color 0.2s,
background-color 0.15s;
cursor: pointer;
}

.accordion-card:hover {
border-color: var(--blue);
background-color: #f8fafc;
}

.accordion-card.active {
border-color: var(--blue);
box-shadow: 0 0 0 1px var(--blue);
}

.accordion-header {
padding: 10px 12px;
display: flex;
align-items: center;
justify-content: space-between;
user-select: none;
}

.accordion-title {
font-weight: 600;
font-size: 13px;
color: var(--text);
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
width: 100%;
}

/* RIGHT SIDEBAR */

.widgets-sidebar {
width: 250px;
background-color: var(--surface);
border-left: 1px solid var(--border);
padding: 16px;
display: flex;
flex-direction: column;
gap: 16px;
flex-shrink: 0;
overflow-y: auto;
}

.widget {
background: var(--surface-soft);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 10px;
}

.widget-title {
font-size: 11px;
font-weight: 700;
text-transform: uppercase;
color: #334155;
margin-bottom: 6px;
letter-spacing: 0.5px;
}

.recent-list {
display: flex;
flex-direction: column;
gap: 4px;
}

.recent-item {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
padding: 6px 8px;
font-size: 12px;
color: var(--text);
text-decoration: none;
border-radius: 4px;
border: 1px solid var(--border-light);
background: #fff;
cursor: pointer;
text-align: left;
}

.recent-item:hover {
background-color: #f1f5f9;
}

/* MOBILE OVERLAY */

.sidebar-overlay {
display: none;
position: fixed;
inset: 0;
background: rgba(15, 23, 42, 0.4);
z-index: 99;
}

/* MODALS */

.modal-backdrop {
display: none;
position: fixed;
inset: 0;
background: rgba(15, 23, 42, 0.5);
align-items: center;
justify-content: center;
z-index: 1000;
padding: 16px;
}

.modal-backdrop.show {
display: flex;
}

.modal {
background: #fff;
border-radius: 8px;
width: 100%;
max-width: 380px;
padding: 16px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.modal-header {
margin-bottom: 12px;
}

.modal-title {
font-size: 16px;
font-weight: 600;
color: var(--text);
}

.field {
margin-bottom: 10px;
display: flex;
flex-direction: column;
gap: 4px;
}

.field label {
font-size: 12px;
font-weight: 600;
color: #1e293b;
}

.field input,
.field select {
padding: 8px;
border: 1px solid var(--border);
border-radius: 4px;
font-size: 13px;
background: #fff;
color: var(--text);
outline: none;
}

.field input:focus,
.field select:focus {
border-color: var(--blue);
box-shadow: 0 0 0 1px var(--blue);
}

.modal-footer {
display: flex;
justify-content: flex-end;
gap: 8px;
margin-top: 14px;
}

/* TOAST */

.toast {
position: fixed;
bottom: 20px;
right: 20px;
padding: 8px 14px;
background: #0f172a;
color: #fff;
font-size: 13px;
border-radius: 4px;
display: none;
z-index: 1001;
}

.toast.show {
display: block;
}

/* RESPONSIVE */

/* RESPONSIVE & MEDIA QUERIES */

@media (max-width: 1200px) {
  .grid-workspace {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .widgets-sidebar {
    display: none; /* Hide right widget sidebar on medium-small screens */
  }
}

@media (max-width: 768px) {
  /* Mobile-only styles apply ONLY when screen width is 768px or narrower */
  .menu-toggle {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.15);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.show {
    display: block;
  }

  .topbar {
    padding: 8px 10px;
    gap: 8px;
    height: auto;
    min-height: 57px;
    flex-wrap: wrap;
  }

  .topbar-left {
    width: 100%;
    flex: none;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .topbar-actions .btn {
    flex-shrink: 0;
  }

  .btn-delete-cat {
    display: inline-block;
  }
}

@media (max-width: 600px) {
  .grid-workspace {
    grid-template-columns: 1fr;
  }
}